summaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-01-12 11:29:21 -0500
committerJoram Wilander <jwawilander@gmail.com>2016-01-12 11:29:21 -0500
commit691380a60a0f038e22af4b518df91baefbf25e85 (patch)
tree302bda63c5c37a7cb6401bb57211ba936c3cd4fb /Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go
parentcf0d275ae44ae0e554c039b34a9b68ddac7a081f (diff)
parenta41c807c700979c4dfb0cdda179e889f022dd80b (diff)
downloadchat-691380a60a0f038e22af4b518df91baefbf25e85.tar.gz
chat-691380a60a0f038e22af4b518df91baefbf25e85.tar.bz2
chat-691380a60a0f038e22af4b518df91baefbf25e85.zip
Merge pull request #1852 from mattermost/PLT-1608
PLT-1608 Upgrading logging package
Diffstat (limited to 'Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go')
-rw-r--r--Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go b/Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go
new file mode 100644
index 000000000..8a941e269
--- /dev/null
+++ b/Godeps/_workspace/src/github.com/alecthomas/log4go/termlog.go
@@ -0,0 +1,49 @@
+// Copyright (C) 2010, Kyle Lemons <kyle@kylelemons.net>. All rights reserved.
+
+package log4go
+
+import (
+ "fmt"
+ "io"
+ "os"
+ "time"
+)
+
+var stdout io.Writer = os.Stdout
+
+// This is the standard writer that prints to standard output.
+type ConsoleLogWriter struct {
+ format string
+ w chan *LogRecord
+}
+
+// This creates a new ConsoleLogWriter
+func NewConsoleLogWriter() *ConsoleLogWriter {
+ consoleWriter := &ConsoleLogWriter{
+ format: "[%T %D] [%L] (%S) %M",
+ w: make(chan *LogRecord, LogBufferLength),
+ }
+ go consoleWriter.run(stdout)
+ return consoleWriter
+}
+func (c *ConsoleLogWriter) SetFormat(format string) {
+ c.format = format
+}
+func (c *ConsoleLogWriter) run(out io.Writer) {
+ for rec := range c.w {
+ fmt.Fprint(out, FormatLogRecord(c.format, rec))
+ }
+}
+
+// This is the ConsoleLogWriter's output method. This will block if the output
+// buffer is full.
+func (c *ConsoleLogWriter) LogWrite(rec *LogRecord) {
+ c.w <- rec
+}
+
+// Close stops the logger from sending messages to standard output. Attempts to
+// send log messages to this logger after a Close have undefined behavior.
+func (c *ConsoleLogWriter) Close() {
+ close(c.w)
+ time.Sleep(50 * time.Millisecond) // Try to give console I/O time to complete
+}