diff --git a/CHANGELOG.md b/CHANGELOG.md index 1243b9d..136b9ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.4.1 (Jan 6, 2023) + +- Change name of NewStreamEmitter to NewBufferEmitter. +- Change name of NewDefaultEmitter to NewStreamEmitter. +- Remove default logger of xybor. + # v0.4.0 (Jan 6, 2023) - Allow determine the buffer size in emitter. diff --git a/README.md b/README.md index 88ef6d3..ed9e792 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,7 @@ var handler = xylog.GetHandler("handler") `StreamEmitter` is supported. You can use any `Writer` in this `Emitter` type. ```golang -var emitter = xylog.NewDefaultEmitter(os.Stdout) +var emitter = xylog.NewStreamEmitter(os.Stdout) ``` When a logging method is called, the `Logger` creates a `LogRecord` and sends it @@ -293,7 +293,7 @@ in different application zones. ```golang // common/setup.go func init() { - var emitter = xylog.NewDefaultEmitter(os.Stderr) + var emitter = xylog.NewStreamEmitter(os.Stderr) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) handler.SetEncoding(encoding.NewJSONEncoding()) diff --git a/config.go b/config.go index 34aff08..3940697 100644 --- a/config.go +++ b/config.go @@ -34,17 +34,6 @@ import ( func init() { rootLogger = newLogger("", nil) rootLogger.SetLevel(WARNING) - - var handler = GetHandler("xybor") - handler.AddEmitter(NewDefaultEmitter(os.Stderr)) - handler.SetEncoding(encoding.NewTextEncoding()) - handler.AddMacro("time", "asctime") - handler.AddMacro("level", "levelname") - handler.AddMacro("module", "name") - - var logger = GetLogger("xybor") - logger.SetLevel(WARNING) - logger.AddHandler(handler) } // Default levels, these can be replaced with any positive set of values having @@ -230,7 +219,7 @@ func (cfg SimpleConfig) Apply() (*Logger, error) { } } - var emitter = NewDefaultEmitter(writer) + var emitter = NewStreamEmitter(writer) var enc = cfg.Encoding if enc == nil { diff --git a/emitter.go b/emitter.go index 8df7df2..d475cc1 100644 --- a/emitter.go +++ b/emitter.go @@ -46,9 +46,8 @@ type StreamEmitter struct { lock *xylock.Lock } -// NewStreamEmitter creates a StreamEmitter which writes message to a LogWriter -// (os.Stderr by default). -func NewStreamEmitter(w io.Writer, bufsize int) *StreamEmitter { +// NewBufferEmitter creates a StreamEmitter which uses a Buffered Writer. +func NewBufferEmitter(w io.Writer, bufsize int) *StreamEmitter { xycond.AssertNotNil(w) if bufsize != 0 { @@ -66,9 +65,10 @@ func NewStreamEmitter(w io.Writer, bufsize int) *StreamEmitter { return e } -// NewDefaultEmitter creates a StreamEmitter not using the buffer size. -func NewDefaultEmitter(w io.Writer) *StreamEmitter { - return NewStreamEmitter(w, 0) +// NewStreamEmitter creates a StreamEmitter which writes logging message to a +// stream. +func NewStreamEmitter(w io.Writer) *StreamEmitter { + return NewBufferEmitter(w, 0) } // Emit will be called after a record was decided to log. diff --git a/emitter_test.go b/emitter_test.go index 24ff90d..bc74a3c 100644 --- a/emitter_test.go +++ b/emitter_test.go @@ -31,7 +31,7 @@ import ( func TestNewStreamEmitterWithNil(t *testing.T) { xycond.ExpectPanic(xyerror.AssertionError, func() { - xylog.NewDefaultEmitter(nil) + xylog.NewStreamEmitter(nil) }).Test(t) } diff --git a/example_test.go b/example_test.go index 6a8c52f..4171d3c 100644 --- a/example_test.go +++ b/example_test.go @@ -52,7 +52,7 @@ func ExampleSimpleConfig() { } func ExampleLogger() { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) @@ -93,7 +93,7 @@ func ExampleHandler() { } func ExampleEventLogger() { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) @@ -109,7 +109,7 @@ func ExampleEventLogger() { } func ExampleNewJSONEncoding() { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) handler.SetEncoding(encoding.NewJSONEncoding()) @@ -127,7 +127,7 @@ func ExampleNewJSONEncoding() { } func ExampleNewTextEncoding() { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) handler.SetEncoding(encoding.NewTextEncoding()) @@ -145,7 +145,7 @@ func ExampleNewTextEncoding() { } func ExampleFilter() { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) handler.AddFilter(&test.LoggerNameFilter{Name: "example.filter.chat"}) diff --git a/handler_test.go b/handler_test.go index 141d695..c7d282c 100644 --- a/handler_test.go +++ b/handler_test.go @@ -68,7 +68,7 @@ func TestHandlerFileters(t *testing.T) { } func TestHandlerEmitters(t *testing.T) { - var emitter = xylog.NewDefaultEmitter(os.Stdout) + var emitter = xylog.NewStreamEmitter(os.Stdout) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) xycond.ExpectEqual(len(handler.Emitters()), 1).Test(t) @@ -109,6 +109,6 @@ func TestHandlerFullMacro(t *testing.T) { xycond.ExpectEqual("asctime=ASCTIME created=1 filename=FILENAME "+ "funcname=FUNCNAME levelname=LEVELNAME levelno=2 lineno=3 "+ "module=MODULE msecs=4 pathname=PATHNAME process=5 "+ - "relativeCreated=6", w.Captured).Test(t) + "relativeCreated=6\n", w.Captured).Test(t) }) } diff --git a/logger_test.go b/logger_test.go index c5de380..0705088 100644 --- a/logger_test.go +++ b/logger_test.go @@ -191,7 +191,7 @@ func TestLoggerFindCaller(t *testing.T) { func TestLoggerFlushParent(t *testing.T) { var writer = &test.MockWriter{} - var emitter = xylog.NewDefaultEmitter(writer) + var emitter = xylog.NewStreamEmitter(writer) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) diff --git a/test/context.go b/test/context.go index 66fc8f8..c287b7d 100644 --- a/test/context.go +++ b/test/context.go @@ -31,7 +31,7 @@ import ( // WithLogger allows using a Logger created with a MockWriter quickly. func WithLogger(t *testing.T, f func(logger *xylog.Logger, w *MockWriter)) { var writer = &MockWriter{} - var emitter = xylog.NewStreamEmitter(writer, 1) + var emitter = xylog.NewStreamEmitter(writer) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) @@ -47,7 +47,7 @@ func WithLogger(t *testing.T, f func(logger *xylog.Logger, w *MockWriter)) { // WithHandler allows using a Handler with MockWriter. func WithHandler(t *testing.T, f func(h *xylog.Handler, w *MockWriter)) { var writer = &MockWriter{} - var emitter = xylog.NewStreamEmitter(writer, 1) + var emitter = xylog.NewStreamEmitter(writer) var handler = xylog.GetHandler(t.Name()) handler.AddEmitter(emitter) @@ -58,13 +58,13 @@ func WithHandler(t *testing.T, f func(h *xylog.Handler, w *MockWriter)) { // quickly. func WithStreamEmitter(t *testing.T, f func(e *xylog.StreamEmitter, w *MockWriter)) { var writer = &MockWriter{} - var emitter = xylog.NewStreamEmitter(writer, 1) + var emitter = xylog.NewStreamEmitter(writer) f(emitter, writer) } // WithBenchLogger allows using a Logger whose output is io.Discard. func WithBenchLogger(b *testing.B, f func(logger *xylog.Logger)) { - var emitter = xylog.NewStreamEmitter(io.Discard, 4096) + var emitter = xylog.NewBufferEmitter(io.Discard, 4096) var handler = xylog.GetHandler("") handler.AddEmitter(emitter) handler.SetEncoding(encoding.NewJSONEncoding())