Compare commits
3 commits
v0.4.1
...
v0.5.0-bet
Author | SHA1 | Date | |
---|---|---|---|
ba2ba315d0 | |||
a1c991bcbd | |||
eb8b9abe1a |
6 changed files with 28 additions and 4 deletions
|
@ -12,6 +12,8 @@ func main(){
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Check out this [simple example file](cmd/simple/main.go) for the basic usage.
|
||||||
|
|
||||||
## Multiple Log Instance
|
## Multiple Log Instance
|
||||||
|
|
||||||
Create a new log instance (instead of using the `Default`).
|
Create a new log instance (instead of using the `Default`).
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.martin-riedl.de/golang/log"
|
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"git.martin-riedl.de/golang/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
someMethod()
|
someMethod()
|
||||||
|
anotherMethod()
|
||||||
}
|
}
|
||||||
|
|
||||||
func someMethod() {
|
func someMethod() {
|
||||||
log.Default.Info("Hello World")
|
log.Default.Info("Hello World")
|
||||||
log.Default.With("os", runtime.GOOS).Info("environment detected")
|
log.Default.With("os", runtime.GOOS).Warning("environment detected")
|
||||||
|
}
|
||||||
|
|
||||||
|
func anotherMethod() {
|
||||||
|
log.Default.WithMap(map[string]any{
|
||||||
|
"foo": "bar",
|
||||||
|
"bar": "baz",
|
||||||
|
}).Info("Second Hello World")
|
||||||
}
|
}
|
||||||
|
|
7
entry.go
7
entry.go
|
@ -49,6 +49,13 @@ func (entry *Entry) With(key string, value any) *Entry {
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (entry *Entry) WithMap(entries map[string]any) *Entry {
|
||||||
|
for key, value := range entries {
|
||||||
|
entry.With(key, value)
|
||||||
|
}
|
||||||
|
return entry
|
||||||
|
}
|
||||||
|
|
||||||
func (entry *Entry) WithContent(content []Content) *Entry {
|
func (entry *Entry) WithContent(content []Content) *Entry {
|
||||||
entry.Content = append(entry.Content, content...)
|
entry.Content = append(entry.Content, content...)
|
||||||
return entry
|
return entry
|
||||||
|
|
|
@ -65,7 +65,7 @@ func (formatter *FormatterJSON) Process(entry *Entry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *FormatterJSON) End(entry *Entry) []byte {
|
func (formatter *FormatterJSON) End(_ *Entry) []byte {
|
||||||
// build JSON
|
// build JSON
|
||||||
data, err := json.Marshal(formatter.data)
|
data, err := json.Marshal(formatter.data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -82,7 +82,7 @@ func (formatter *FormatterKeyValue) addKV(key string, value any) {
|
||||||
formatter.builder.WriteString(val)
|
formatter.builder.WriteString(val)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (formatter *FormatterKeyValue) End(entry *Entry) []byte {
|
func (formatter *FormatterKeyValue) End(_ *Entry) []byte {
|
||||||
// send data
|
// send data
|
||||||
return []byte(formatter.builder.String())
|
return []byte(formatter.builder.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,6 +113,12 @@ func (logger *Logger) With(key string, value any) *Entry {
|
||||||
return entry
|
return entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (logger *Logger) WithMap(entries map[string]any) *Entry {
|
||||||
|
entry := NewEntry(logger)
|
||||||
|
entry.WithMap(entries)
|
||||||
|
return entry
|
||||||
|
}
|
||||||
|
|
||||||
func (logger *Logger) WithContent(content []Content) *Entry {
|
func (logger *Logger) WithContent(content []Content) *Entry {
|
||||||
entry := NewEntry(logger)
|
entry := NewEntry(logger)
|
||||||
entry.WithContent(content)
|
entry.WithContent(content)
|
||||||
|
|
Loading…
Add table
Reference in a new issue