2018-03-28 18:49:41 +00:00
|
|
|
package zerolog_test
|
|
|
|
|
|
|
|
import (
|
2018-04-19 20:12:29 +00:00
|
|
|
"bytes"
|
2018-03-28 18:49:41 +00:00
|
|
|
"os"
|
2018-04-19 20:12:29 +00:00
|
|
|
"strings"
|
|
|
|
"testing"
|
2018-03-28 18:49:41 +00:00
|
|
|
|
|
|
|
"github.com/rs/zerolog"
|
|
|
|
)
|
|
|
|
|
|
|
|
func ExampleConsoleWriter_Write() {
|
|
|
|
log := zerolog.New(zerolog.ConsoleWriter{Out: os.Stdout, NoColor: true})
|
|
|
|
|
|
|
|
log.Info().Msg("hello world")
|
|
|
|
// Output: <nil> |INFO| hello world
|
|
|
|
}
|
2018-04-19 20:12:29 +00:00
|
|
|
|
|
|
|
func TestConsoleWriterNumbers(t *testing.T) {
|
|
|
|
buf := &bytes.Buffer{}
|
|
|
|
log := zerolog.New(zerolog.ConsoleWriter{Out: buf, NoColor: true})
|
|
|
|
log.Info().
|
|
|
|
Float64("float", 1.23).
|
|
|
|
Uint64("small", 123).
|
|
|
|
Uint64("big", 1152921504606846976).
|
|
|
|
Msg("msg")
|
|
|
|
if got, want := strings.TrimSpace(buf.String()), "<nil> |INFO| msg big=1152921504606846976 float=1.23 small=123"; got != want {
|
|
|
|
t.Errorf("\ngot:\n%s\nwant:\n%s", got, want)
|
|
|
|
}
|
|
|
|
}
|