-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example how to use custom async logger
- Loading branch information
Showing
2 changed files
with
42 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Example that shows how to create and use custom async logger. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"github.com/dl1998/go-logging/pkg/common/level" | ||
"github.com/dl1998/go-logging/pkg/logger" | ||
"github.com/dl1998/go-logging/pkg/logger/formatter" | ||
"github.com/dl1998/go-logging/pkg/logger/handler" | ||
"time" | ||
) | ||
|
||
func main() { | ||
asyncQueueSize := 10 | ||
|
||
applicationLogger := logger.NewAsyncLogger("example", time.DateTime, asyncQueueSize) | ||
|
||
applicationFormatter := formatter.New("%(datetime) [%(level)] %(message)") | ||
consoleHandler := handler.NewConsoleHandler(level.Debug, level.Null, applicationFormatter) | ||
applicationLogger.AddHandler(consoleHandler) | ||
|
||
for index := 0; index < asyncQueueSize; index++ { | ||
applicationLogger.Warning("This message will be displayed.") | ||
} | ||
|
||
fmt.Println("This will be printed before the last warning log message.") | ||
|
||
applicationLogger.WaitToFinishLogging() | ||
} |