aboutsummaryrefslogtreecommitdiffstats
path: root/logger/logsystem.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-21 14:26:44 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-21 14:26:44 +0800
commit9edb9a21bce97594928f8660e8e32df2cb25b74d (patch)
treea933fa349621d842f361762045eabc96772d147d /logger/logsystem.go
parent4f5b362bda862b0d77583491d5e04193148a9349 (diff)
downloaddexon-9edb9a21bce97594928f8660e8e32df2cb25b74d.tar.gz
dexon-9edb9a21bce97594928f8660e8e32df2cb25b74d.tar.zst
dexon-9edb9a21bce97594928f8660e8e32df2cb25b74d.zip
Add json LogSystem #538
Diffstat (limited to 'logger/logsystem.go')
-rw-r--r--logger/logsystem.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/logger/logsystem.go b/logger/logsystem.go
index 8458b938f..1318a9f96 100644
--- a/logger/logsystem.go
+++ b/logger/logsystem.go
@@ -61,3 +61,27 @@ func (t *rawLogSystem) SetLogLevel(i LogLevel) {
func (t *rawLogSystem) GetLogLevel() LogLevel {
return LogLevel(atomic.LoadUint32(&t.level))
}
+
+// NewRawLogSystem creates a LogSystem that prints to the given writer without
+// adding extra information. Suitable for preformatted output
+func NewJsonLogSystem(writer io.Writer, flags int, level LogLevel) LogSystem {
+ logger := log.New(writer, "", 0)
+ return &jsonLogSystem{logger, uint32(level)}
+}
+
+type jsonLogSystem struct {
+ logger *log.Logger
+ level uint32
+}
+
+func (t *jsonLogSystem) LogPrint(level LogLevel, msg string) {
+ t.logger.Print(msg)
+}
+
+func (t *jsonLogSystem) SetLogLevel(i LogLevel) {
+ atomic.StoreUint32(&t.level, uint32(i))
+}
+
+func (t *jsonLogSystem) GetLogLevel() LogLevel {
+ return LogLevel(atomic.LoadUint32(&t.level))
+}