Documentation
¶
Overview ¶
Package consolelog provides a writer for the "github.com/rs/zerolog" package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConsoleWriter ¶
type ConsoleWriter struct {
Out io.Writer
TimeFormat string
PartsOrder []string
// contains filtered or unexported fields
}
ConsoleWriter parses the JSON input and writes an ANSI-colorized output to Out.
It is adapted from the zerolog.ConsoleWriter; see: https://github.com/rs/zerolog/blob/master/console.go.
func NewConsoleWriter ¶
func NewConsoleWriter(options ...func(w *ConsoleWriter)) ConsoleWriter
NewConsoleWriter creates and initializes a new ConsoleWriter.
Example ¶
package main
import (
"github.com/karmi/consolelog"
"github.com/rs/zerolog"
)
func main() {
output := consolelog.NewConsoleWriter()
logger := zerolog.New(output)
logger.Info().Str("foo", "bar").Msg("hello world")
}
Output: INF hello world foo=bar
Example (Custom) ¶
package main
import (
"fmt"
"strings"
"time"
"github.com/karmi/consolelog"
"github.com/rs/zerolog"
)
func main() {
output := consolelog.NewConsoleWriter(
// Customize time formatting
//
func(w *consolelog.ConsoleWriter) {
w.TimeFormat = time.RFC822
},
// Customize "level" formatting
//
func(w *consolelog.ConsoleWriter) {
w.SetFormatter(
zerolog.LevelFieldName,
func(i interface{}) string { return strings.ToUpper(fmt.Sprintf("%-5s", i)) })
},
)
logger := zerolog.New(output).With().Timestamp().Logger()
logger.Info().Str("foo", "bar").Msg("hello world")
// => 19 Jul 18 15:50 CEST INFO hello world foo=bar
}
Output:
func (ConsoleWriter) Formatter ¶
func (w ConsoleWriter) Formatter(id string) Formatter
Formatter returns a formatter by id or the default formatter if none is found.
func (ConsoleWriter) SetFormatter ¶
func (w ConsoleWriter) SetFormatter(id string, f Formatter)
SetFormatter registers a formatter function by id.
Click to show internal directories.
Click to hide internal directories.
