1
0
mirror of https://github.com/khorevaa/logos.git synced 2025-03-17 21:17:58 +02:00
logos/example_test.go

105 lines
2.0 KiB
Go
Raw Permalink Normal View History

2021-02-01 17:50:15 +03:00
package logos_test
import (
2021-02-01 18:47:45 +03:00
"errors"
2021-02-01 17:50:15 +03:00
"github.com/khorevaa/logos"
2021-02-01 19:19:18 +03:00
log2 "log"
2021-02-01 17:50:15 +03:00
)
2021-02-01 18:47:45 +03:00
func ExampleNew_simple() {
2021-02-01 19:19:18 +03:00
rawConfig := `
appenders:
console:
- name: CONSOLE
target: stdout
no_color: true
encoder:
console:
disable_timestamp: true
color_scheme:
info_level: blue+b
debug_level: green+b
2021-02-02 00:01:37 +03:00
loggers:
2021-02-01 19:19:18 +03:00
root:
level: debug
appender_refs:
- CONSOLE
`
err := logos.InitWithConfigContent(rawConfig)
if err != nil {
panic(err)
}
//logos.CancelRedirectStdLog()
2021-02-01 17:50:15 +03:00
2021-02-01 19:19:18 +03:00
log2.Println("1")
2021-02-01 18:47:45 +03:00
log := logos.New("<your-package-name>") // like github.com/khorevaa/logos
log.Info("This is me first log. Hello world logging systems")
2021-02-01 19:19:18 +03:00
//cancel()
//log2.Println("2")
2021-02-01 17:50:15 +03:00
2021-02-01 19:19:18 +03:00
// Output:
// INFO stdlog 1
// INFO <your-package-name> This is me first log. Hello world logging systems
2021-02-01 18:47:45 +03:00
}
func ExampleNew_with_config_json() {
rawConfig := `
appenders:
console:
- name: CONSOLE
target: stdout
encoder:
json:
2021-02-02 00:01:37 +03:00
loggers:
2021-02-01 18:47:45 +03:00
root:
level: info
appender_refs:
- CONSOLE
`
logos.InitWithConfigContent(rawConfig)
log := logos.New("<your-package-name>") // like github.com/khorevaa/logos
log.Info("This is me first log. Hello world logging systems")
}
func ExampleNew_with_color_scheme() {
rawConfig := `
appenders:
console:
- name: CONSOLE
target: stdout
2021-02-01 19:19:18 +03:00
no_color: true
2021-02-01 18:47:45 +03:00
encoder:
console:
2021-02-01 19:19:18 +03:00
disable_timestamp: true
2021-02-01 18:47:45 +03:00
color_scheme:
info_level: blue+b
debug_level: green+b
2021-02-02 00:01:37 +03:00
loggers:
2021-02-01 18:47:45 +03:00
root:
level: debug
appender_refs:
- CONSOLE
`
logos.InitWithConfigContent(rawConfig)
log := logos.New("<your-package-name>") // like github.com/khorevaa/logos
log.Info("This is me first log. Hello world logging systems")
err := errors.New("log system error")
log.Debug("This is me first error", logos.Any("err", err))
2021-02-01 17:50:15 +03:00
2021-02-01 19:19:18 +03:00
// Output:
// INFO <your-package-name> This is me first log. Hello world logging systems
// DEBUG <your-package-name> This is me first error err=log system error
2021-02-01 17:50:15 +03:00
}