basic

package
v0.0.0-...-deae2a3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package basic provides a basic text/terminal log entry handler for slog. It allows to define the format of the output string (via Go templates), the format of date and time, the colouring of entries in case of terminal output as well as the writer to redirect the output to. The handler synchronises on write to allow the same handler to be used from concurrent routines.

Index

Constants

View Source
const (
	// StandardTermTemplate represents a standard template for terminal output (default).
	StandardTermTemplate = "" /* 174-byte string literal not displayed */

	// StandardTextTemplate represents a standard template for text file output or any other writers
	// not supporting terminal colouring.
	StandardTextTemplate = "" /* 136-byte string literal not displayed */

	// StandardTimeFormat represents the time format used in the handler by default.
	StandardTimeFormat = "15:04:05.000"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	Time    string
	Level   string
	Context string
	Message string
	Error   error
	Caller  string
	Fields  string
	Color   int
}

Data supplies log data to the template formatter for outputting into the log string. This structure defines all the fields that can be used in the template.

type Handler

type Handler struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Handler represents a log entry handler capable of formatting structured log data into a text format (text files, stderr with or without colouring etc).

func New

func New() *Handler

New constructs a new handler with default template, time formatting, colours and stderr as output.

func (*Handler) Handle

func (h *Handler) Handle(e slog.Entry) (err error)

Handle outputs a textual representation of the log entry into a text writer (stderr, file etc.).

func (*Handler) SetColors

func (h *Handler) SetColors(colors map[slf.Level]int)

SetColors overwrites the level-colour mapping. Every missing mapping will be replaced by gray.

func (*Handler) SetTemplate

func (h *Handler) SetTemplate(s string) error

SetTemplate defines the formatting of the log string using the standard Go template syntax. See the Data structure for the definition of all supported template fields.

func (*Handler) SetTimeFormat

func (h *Handler) SetTimeFormat(f string)

SetTimeFormat defines the formatting of time used for output into the template.

func (*Handler) SetWriter

func (h *Handler) SetWriter(w io.Writer)

SetWriter defines the writer to use to output log strings (default: stderr).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL