log

package module
v0.0.0-...-fa52841 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2024 License: ISC Imports: 10 Imported by: 18

README

go-log

Introduction

The go-log library provides hierarchical loggers with a simple interface and support for multiple backends.

Go-log output

Usage

Go-log supports hierarchical logging: loggers are identified by a domain, a multi-part string identifying the software component they are part of. This is extremely useful when filtering large quantity of log messages in complex software.

Loggers can create children. The domain of a child logger starts with the domain of its parent; it also inherits its set of data.

Go-log currently supports the following backends:

  • terminal: write human-readable log messages to the standard error output.
  • json: write log messages encoded as JSON objects to the standard error output.

Refer to the Go package documentation for information about the API, and see the example program.

The go-service library demonstrates how to use go-log loggers for larger programs.

Licensing

Go-log is open source software distributed under the ISC license.

Documentation

Index

Constants

View Source
const (
	DefaultTimestampKey    = "time"
	DefaultTimestampLayout = time.RFC3339Nano
	DefaultDomainKey       = "domain"
	DefaultLevelKey        = "level"
	DefaultMessageKey      = "msg"
	DefaultDataKey         = "data"
)

Variables

View Source
var (
	ColorBlack   = Color(0)
	ColorRed     = Color(1)
	ColorGreen   = Color(2)
	ColorYellow  = Color(3)
	ColorBlue    = Color(4)
	ColorMagenta = Color(5)
	ColorCyan    = Color(6)
	ColorWhite   = Color(7)
)

Functions

This section is empty.

Types

type Backend

type Backend interface {
	Log(Message)
}

type BackendType

type BackendType string
const (
	BackendTypeTerminal BackendType = "terminal"
	BackendTypeJSON     BackendType = "json"
)

type Color

type Color int

type Data

type Data map[string]Datum

func MergeData

func MergeData(dataList ...Data) Data

type Datum

type Datum interface{}

type JSONBackend

type JSONBackend struct {
	Cfg JSONBackendCfg
}

func NewJSONBackend

func NewJSONBackend(cfg JSONBackendCfg) *JSONBackend

func (*JSONBackend) Log

func (b *JSONBackend) Log(msg Message)

type JSONBackendCfg

type JSONBackendCfg struct {
	TimestampKey    string `json:"timestamp_key,omitempty"`
	TimestampLayout string `json:"timestamp_layout,omitempty"`
	DomainKey       string `json:"domain_key,omitempty"`
	LevelKey        string `json:"level_key,omitempty"`
	MessageKey      string `json:"message_key,omitempty"`
	DataKey         string `json:"data_key,omitempty"`
}

type Level

type Level string
const (
	LevelDebug Level = "debug"
	LevelInfo  Level = "info"
	LevelError Level = "error"
)

type Logger

type Logger struct {
	Cfg        LoggerCfg
	Backend    Backend
	Domain     string
	Data       Data
	DebugLevel int
}

func DefaultLogger

func DefaultLogger(name string) *Logger

func NewLogger

func NewLogger(name string, cfg LoggerCfg) (*Logger, error)

func (*Logger) Child

func (l *Logger) Child(domain string, data Data) *Logger

func (*Logger) Debug

func (l *Logger) Debug(level int, format string, args ...interface{})

func (*Logger) DebugData

func (l *Logger) DebugData(data Data, level int, format string, args ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, args ...interface{})

func (*Logger) ErrorData

func (l *Logger) ErrorData(data Data, format string, args ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, args ...interface{})

func (*Logger) InfoData

func (l *Logger) InfoData(data Data, format string, args ...interface{})

func (*Logger) Log

func (l *Logger) Log(msg Message)

func (*Logger) StdLogger

func (l *Logger) StdLogger(level Level) *log.Logger

func (*Logger) Write

func (l *Logger) Write(data []byte) (int, error)

type LoggerCfg

type LoggerCfg struct {
	BackendType     BackendType         `json:"backend_type"`
	TerminalBackend *TerminalBackendCfg `json:"terminal_backend,omitempty"`
	JSONBackend     *JSONBackendCfg     `json:"json_backend,omitempty"`
	DebugLevel      int                 `json:"debug_level,omitempty"`
}

type Message

type Message struct {
	Time       *time.Time
	Level      Level
	DebugLevel int
	Message    string
	Data       Data
	// contains filtered or unexported fields
}

func (Message) FullLevel

func (msg Message) FullLevel() string

type TerminalBackend

type TerminalBackend struct {
	Cfg TerminalBackendCfg
	// contains filtered or unexported fields
}

func NewTerminalBackend

func NewTerminalBackend(cfg TerminalBackendCfg) *TerminalBackend

func (*TerminalBackend) Log

func (b *TerminalBackend) Log(msg Message)

type TerminalBackendCfg

type TerminalBackendCfg struct {
	Color       bool `json:"color,omitempty"`
	ForceColor  bool `json:"force_color,omitempty"`
	DomainWidth int  `json:"domain_width,omitempty"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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