diff --git a/examples/customasyncstructuredlogger/main.go b/examples/customasyncstructuredlogger/main.go index 3a3f4b6..7c6e950 100644 --- a/examples/customasyncstructuredlogger/main.go +++ b/examples/customasyncstructuredlogger/main.go @@ -13,7 +13,7 @@ import ( func main() { asyncQueueSize := 10 - applicationLogger := structuredlogger.NewAsyncStructuredLogger("example", time.DateTime, asyncQueueSize) + applicationLogger := structuredlogger.NewAsyncLogger("example", time.DateTime, asyncQueueSize) applicationFormatter := formatter.NewJSON(map[string]string{ "time": "%(datetime)", diff --git a/pkg/structuredlogger/asyncstructuredlogger.go b/pkg/structuredlogger/asyncstructuredlogger.go index 921bd60..097e7d9 100644 --- a/pkg/structuredlogger/asyncstructuredlogger.go +++ b/pkg/structuredlogger/asyncstructuredlogger.go @@ -52,23 +52,22 @@ func (logger *baseAsyncLogger) Log(logLevel level.Level, parameters ...any) { logger.messageQueue <- logRecord } -// AsyncStructuredLoggerInterface defines async structured logger interface. -type AsyncStructuredLoggerInterface interface { +// AsyncLoggerInterface defines async structured logger interface. +type AsyncLoggerInterface interface { Interface WaitToFinishLogging() Open(queueSize int) Close() } -// AsyncStructuredLogger is a structured logger that logs messages -// asynchronously. -type AsyncStructuredLogger struct { +// AsyncLogger is a structured logger that logs messages asynchronously. +type AsyncLogger struct { // Logger is a standard structured logger. *Logger } -// NewAsyncStructuredLogger creates a new async structured logger. -func NewAsyncStructuredLogger(name string, timeFormat string, queueSize int) *AsyncStructuredLogger { +// NewAsyncLogger creates a new async structured logger. +func NewAsyncLogger(name string, timeFormat string, queueSize int) *AsyncLogger { newBaseLogger := &baseAsyncLogger{ baseLogger: &baseLogger{ name: name, @@ -79,7 +78,7 @@ func NewAsyncStructuredLogger(name string, timeFormat string, queueSize int) *As waitGroup: sync.WaitGroup{}, } go newBaseLogger.startListeningMessages() - return &AsyncStructuredLogger{ + return &AsyncLogger{ Logger: &Logger{ baseLogger: newBaseLogger, }, @@ -87,17 +86,17 @@ func NewAsyncStructuredLogger(name string, timeFormat string, queueSize int) *As } // WaitToFinishLogging waits for all messages to be logged. -func (logger *AsyncStructuredLogger) WaitToFinishLogging() { +func (logger *AsyncLogger) WaitToFinishLogging() { logger.baseLogger.(*baseAsyncLogger).WaitToFinishLogging() } // Open opens the messageQueue with the provided queueSize and starts listening // for messages. -func (logger *AsyncStructuredLogger) Open(queueSize int) { +func (logger *AsyncLogger) Open(queueSize int) { logger.baseLogger.(*baseAsyncLogger).Open(queueSize) } // Close closes the messageQueue. -func (logger *AsyncStructuredLogger) Close() { +func (logger *AsyncLogger) Close() { logger.baseLogger.(*baseAsyncLogger).Close() } diff --git a/pkg/structuredlogger/asyncstructuredlogger_test.go b/pkg/structuredlogger/asyncstructuredlogger_test.go index 708c8ad..a9cfcf7 100644 --- a/pkg/structuredlogger/asyncstructuredlogger_test.go +++ b/pkg/structuredlogger/asyncstructuredlogger_test.go @@ -151,29 +151,27 @@ func BenchmarkBaseAsyncLogger_Log(b *testing.B) { } } -// TestNewAsyncStructuredLogger tests that NewAsyncStructuredLogger creates a new -// AsyncStructuredLogger. -func TestNewAsyncStructuredLogger(t *testing.T) { - newAsyncStructuredLogger := NewAsyncStructuredLogger(loggerName, timeFormat, messageQueueSize) +// TestNewAsyncLogger tests that NewAsyncLogger creates a new AsyncLogger. +func TestNewAsyncLogger(t *testing.T) { + newAsyncStructuredLogger := NewAsyncLogger(loggerName, timeFormat, messageQueueSize) testutils.AssertNotNil(t, newAsyncStructuredLogger) testutils.AssertEquals(t, loggerName, newAsyncStructuredLogger.Name()) testutils.AssertEquals(t, messageQueueSize, cap(newAsyncStructuredLogger.baseLogger.(*baseAsyncLogger).messageQueue)) } -// BenchmarkNewAsyncStructuredLogger benchmarks NewAsyncStructuredLogger. -func BenchmarkNewAsyncStructuredLogger(b *testing.B) { +// BenchmarkNewAsyncLogger benchmarks NewAsyncLogger. +func BenchmarkNewAsyncLogger(b *testing.B) { for index := 0; index < b.N; index++ { - NewAsyncStructuredLogger(loggerName, timeFormat, messageQueueSize) + NewAsyncLogger(loggerName, timeFormat, messageQueueSize) } } -// TestAsyncStructuredLogger_WaitToFinishLogging tests that -// AsyncStructuredLogger.WaitToFinishLogging waits until async logger finish -// logging messages. -func TestAsyncStructuredLogger_WaitToFinishLogging(t *testing.T) { +// TestAsyncLogger_WaitToFinishLogging tests that AsyncLogger.WaitToFinishLogging +// waits until async logger finish logging messages. +func TestAsyncLogger_WaitToFinishLogging(t *testing.T) { mockHandler := &MockHandler{} - newAsyncStructuredLogger := &AsyncStructuredLogger{ + newAsyncStructuredLogger := &AsyncLogger{ Logger: &Logger{ baseLogger: &baseAsyncLogger{ baseLogger: &baseLogger{ @@ -199,11 +197,11 @@ func TestAsyncStructuredLogger_WaitToFinishLogging(t *testing.T) { testutils.AssertEquals(t, true, waited) } -// TestAsyncStructuredLogger_Open tests that AsyncStructuredLogger.Open creates a -// new message queue and start listening messages. -func TestAsyncStructuredLogger_Open(t *testing.T) { +// TestAsyncLogger_Open tests that AsyncLogger.Open creates a new message queue +// and start listening messages. +func TestAsyncLogger_Open(t *testing.T) { mockHandler := &MockHandler{} - newAsyncStructuredLogger := &AsyncStructuredLogger{ + newAsyncStructuredLogger := &AsyncLogger{ Logger: &Logger{ baseLogger: &baseAsyncLogger{ baseLogger: &baseLogger{ @@ -221,11 +219,11 @@ func TestAsyncStructuredLogger_Open(t *testing.T) { testutils.AssertNotNil(t, newAsyncStructuredLogger.baseLogger.(*baseAsyncLogger).messageQueue) } -// TestAsyncStructuredLogger_Close tests that AsyncStructuredLogger.Close closes -// message queue channel. -func TestAsyncStructuredLogger_Close(t *testing.T) { +// TestAsyncLogger_Close tests that AsyncLogger.Close closes message queue +// channel. +func TestAsyncLogger_Close(t *testing.T) { mockHandler := &MockHandler{} - newAsyncStructuredLogger := &AsyncStructuredLogger{ + newAsyncStructuredLogger := &AsyncLogger{ Logger: &Logger{ baseLogger: &baseAsyncLogger{ baseLogger: &baseLogger{