aboutsummaryrefslogtreecommitdiffstats
path: root/logger/logsystem.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-01-22 00:04:11 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-01-22 00:04:11 +0800
commit7f9c3354872e6fcc63c37abddb184e3e58790bc3 (patch)
tree98721ba3e202456503d9cffc7d0985c9ef35d215 /logger/logsystem.go
parent87f50659db7a4bf194769b05f541d2ccf02f4fc8 (diff)
downloaddexon-7f9c3354872e6fcc63c37abddb184e3e58790bc3.tar.gz
dexon-7f9c3354872e6fcc63c37abddb184e3e58790bc3.tar.zst
dexon-7f9c3354872e6fcc63c37abddb184e3e58790bc3.zip
Split into multiple files
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))
+}