From 9670c407b6af3af7f853ae5d16e8a483fc364d1c Mon Sep 17 00:00:00 2001 From: Martin Riedl Date: Thu, 4 Jan 2024 00:09:44 +0100 Subject: [PATCH] docs: some new code samples --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/README.md b/README.md index c2a171a..bf152e2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,55 @@ +# goLog + +GoLog is a simple logging framework for golang. + +## Getting Started + +```golang +import log "gitlab.com/martinr92/golog" + +func main(){ + log.Default.Info("My First Info Message") +} +``` + +## Multiple Log Instance + +Create a new log instance (instead of using the `Default`). + +```golang +import log "gitlab.com/martinr92/golog" + +var myLog := log.NewLoggerDefault() +myLog.Info("My First Info Message") +``` + +## Outputs / Formatter / Printer + +- `Formatter` defines the output format (e.g. Key/Value or JSON) +- `Printer` defines the message output location (e.g. stdout or file) +- `Output` is a combination of `Formatter` and `Printer` + +The following sample creates 2 outputs. The first sends a key/value format to stdout. The second writes messages as JSON format to stdout. + +```golang +import log "gitlab.com/martinr92/golog" + +var output1 := NewOutput(log.LevelInfo, NewFormatterKeyValue(), NewPrinterStdout() +var output2 := NewOutput(log.LevelError, NewFormatterJSON(), NewPrinterStdout()) + +var myLog := log.NewLogger( + []*Output{output1, output2} +) +myLog.Info("My First Info Message") + +``` + +## Custom Formatter / Printer + +If you need a special `Formatter` or `Printer`: simply implement the Interface (same name) and assign it to an `Output`. + # License + ``` Copyright 2023 Martin Riedl