From 56e74239d6b34df8f30ef046f0b0ff4ff0866a71 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Sun, 14 Jun 2015 23:53:32 -0800 Subject: first commit --- .../src/code.google.com/p/log4go/termlog.go | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Godeps/_workspace/src/code.google.com/p/log4go/termlog.go (limited to 'Godeps/_workspace/src/code.google.com/p/log4go/termlog.go') diff --git a/Godeps/_workspace/src/code.google.com/p/log4go/termlog.go b/Godeps/_workspace/src/code.google.com/p/log4go/termlog.go new file mode 100644 index 000000000..1ed2e4e0d --- /dev/null +++ b/Godeps/_workspace/src/code.google.com/p/log4go/termlog.go @@ -0,0 +1,45 @@ +// Copyright (C) 2010, Kyle Lemons . All rights reserved. + +package log4go + +import ( + "io" + "os" + "fmt" +) + +var stdout io.Writer = os.Stdout + +// This is the standard writer that prints to standard output. +type ConsoleLogWriter chan *LogRecord + +// This creates a new ConsoleLogWriter +func NewConsoleLogWriter() ConsoleLogWriter { + records := make(ConsoleLogWriter, LogBufferLength) + go records.run(stdout) + return records +} + +func (w ConsoleLogWriter) run(out io.Writer) { + var timestr string + var timestrAt int64 + + for rec := range w { + if at := rec.Created.UnixNano() / 1e9; at != timestrAt { + timestr, timestrAt = rec.Created.Format("01/02/06 15:04:05"), at + } + fmt.Fprint(out, "[", timestr, "] [", levelStrings[rec.Level], "] ", rec.Message, "\n") + } +} + +// This is the ConsoleLogWriter's output method. This will block if the output +// buffer is full. +func (w ConsoleLogWriter) LogWrite(rec *LogRecord) { + 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 (w ConsoleLogWriter) Close() { + close(w) +} -- cgit v1.2.3-1-g7c22