log

package module
v0.0.0-...-68a090e Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2023 License: MPL-2.0 Imports: 4 Imported by: 13

Documentation

Overview

Package log defines the logger engine. The unique feature is that it can create a child logger derived from the parent logger. Each logger defines a unique color style for the message outputs.

Create a child logger for the packages that the service is calling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fatal

func Fatal(title string, kv ...interface{})

Fatal calls the Error, then os.Exit()

Types

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger is the wrapper over the logger and keeps the style. The style is generated randomly.

func New

func New(prefix string, timestamp bool) (*Logger, error)

New logger with the prefix and timestamp. It generates the random color style.

func (*Logger) Child

func (logger *Logger) Child(prefix string, kv ...interface{}) *Logger

Child logger from the parent with its own color style.

When to use it?

For example:

parent, _ := log.New("main", false)
db_log, _ := parent.Child("database")
reply, _ := parent.Child("server")

parent.Info("starting", "security_enabled", true)
db_log.Info("starting")
reply.Info("starting", "port", 443)

// prints the following
// INFO main: starting: security_enabled=true
// INFO main::database: starting
// INFO main::server: starting, port=443

func (*Logger) Error

func (logger *Logger) Error(title string, kv ...interface{})

Error prints the error message

func (*Logger) Fatal

func (logger *Logger) Fatal(title string, kv ...interface{})

Fatal prints the error message and then calls the os.Exit()

func (*Logger) Info

func (logger *Logger) Info(title string, kv ...interface{})

Info prints the information

func (*Logger) Prefix

func (logger *Logger) Prefix() string

func (*Logger) Warn

func (logger *Logger) Warn(title string, kv ...interface{})

Warn prints the warning message

func (*Logger) Write

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

type LoggerStyle

type LoggerStyle struct {
	// contains filtered or unexported fields
}

LoggerStyle defines the various colors for each log parts.

Jump to

Keyboard shortcuts

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