aboutsummaryrefslogtreecommitdiffstats
path: root/logger/logsystem.go
diff options
context:
space:
mode:
Diffstat (limited to 'logger/logsystem.go')
-rw-r--r--logger/logsystem.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/logger/logsystem.go b/logger/logsystem.go
new file mode 100644
index 000000000..f154773ae
--- /dev/null
+++ b/logger/logsystem.go
@@ -0,0 +1,31 @@
+package logger
+
+import (
+ "io"
+ "log"
+ "sync/atomic"
+)
+
+// NewStdLogSystem creates a LogSystem that prints to the given writer.
+// The flag values are defined package log.
+func NewStdLogSystem(writer io.Writer, flags int, level LogLevel) LogSystem {
+ logger := log.New(writer, "", flags)
+ return &stdLogSystem{logger, uint32(level)}
+}
+
+type stdLogSystem struct {
+ logger *log.Logger
+ level uint32
+}
+
+func (t *stdLogSystem) LogPrint(level LogLevel, msg string) {
+ t.logger.Print(msg)
+}
+
+func (t *stdLogSystem) SetLogLevel(i LogLevel) {
+ atomic.StoreUint32(&t.level, uint32(i))
+}
+
+func (t *stdLogSystem) GetLogLevel() LogLevel {
+ return LogLevel(atomic.LoadUint32(&t.level))
+}