Compare commits
No commits in common. "v0.5.0-beta.1" and "v0.4.1" have entirely different histories.
v0.5.0-bet
...
v0.4.1
6 changed files with 4 additions and 28 deletions
|
@ -12,8 +12,6 @@ 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,24 +1,15 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"git.martin-riedl.de/golang/log"
|
"git.martin-riedl.de/golang/log"
|
||||||
|
"runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
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).Warning("environment detected")
|
log.Default.With("os", runtime.GOOS).Info("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,13 +49,6 @@ 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) []byte {
|
func (formatter *FormatterJSON) End(entry *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) []byte {
|
func (formatter *FormatterKeyValue) End(entry *Entry) []byte {
|
||||||
// send data
|
// send data
|
||||||
return []byte(formatter.builder.String())
|
return []byte(formatter.builder.String())
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,12 +113,6 @@ 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