log

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2020 License: Apache-2.0 Imports: 1 Imported by: 5

Documentation

Overview

Package log provides a global logger for rz.

Example

This example uses command-line flags to demonstrate various outputs depending on the chosen log level.

setup()
debug := flag.Bool("debug", false, "sets log level to debug")

flag.Parse()

// Default level for this example is info, unless debug flag is present

if *debug {
	logger := log.Logger()
	defer func() {
		log.SetLogger(logger)
	}()
	log.SetLogger(log.With(rz.Level(rz.DebugLevel)))
}

log.Info("This message appears when log level set to Debug or Info")
Output:

{"level":"info","timestamp":1199811905,"message":"This message appears when log level set to Debug or Info"}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append added in v1.2.0

func Append(fields ...rz.Field)

Append the fields to the internal logger's context. It does not create a noew copy of the logger and rely on a mutex to enable thread safety, so `Config(With(fields...))` often is preferable.

func Debug

func Debug(message string, fields ...rz.Field)

Debug starts a new message with debug level.

Example

Example of a log at a particular "level" (in this case, "debug")

setup()
log.Debug("hello world")
Output:

{"level":"debug","timestamp":1199811905,"message":"hello world"}

func Error

func Error(message string, fields ...rz.Field)

Error logs a message with error level.

Example

Example of a log at a particular "level" (in this case, "error")

setup()
log.Error("hello world")
Output:

{"level":"error","timestamp":1199811905,"message":"hello world"}

func Fatal

func Fatal(message string, fields ...rz.Field)

Fatal logs a new message with fatal level. The os.Exit(1) function is then called, which terminates the program immediately.

Example

Example of a log at a particular "level" (in this case, "fatal")

setup()
err := errors.New("A repo man spends his life getting into tense situations")
service := "myservice"

log.Fatal(fmt.Sprintf("Cannot start %s", service), rz.Err(err), rz.String("service", service))

// Outputs: {"level":"fatal","timestamp":1199811905,"error":"A repo man spends his life getting into tense situations","service":"myservice","message":"Cannot start myservice"}
Output:

func Info

func Info(message string, fields ...rz.Field)

Info logs a new message with info level.

Example

Example of a log at a particular "level" (in this case, "info")

setup()
log.Info("hello world")
Output:

{"level":"info","timestamp":1199811905,"message":"hello world"}

func Log added in v0.13.4

func Log(message string, fields ...rz.Field)

Log logs a new message with no level. Setting GlobalLevel to Disabled will still disable events produced by this method.

Example

Example of a log with no particular "level"

setup()
log.Log("hello world")
Output:

{"timestamp":1199811905,"message":"hello world"}

func LogWithLevel added in v1.3.2

func LogWithLevel(level rz.LogLevel, message string, fields ...rz.Field)

LogWithLevel logs a new message with the given level.

func Logger added in v0.13.4

func Logger() rz.Logger

Logger returns log's logger

func NewDict added in v1.3.2

func NewDict(fields ...rz.Field) *rz.Event

NewDict create a new Dict with the logger's configuration

func Panic added in v0.13.4

func Panic(message string, fields ...rz.Field)

Panic logs a new message with panic level. The panic() function is then called, which stops the ordinary flow of a goroutine.

func SetLogger added in v1.3.2

func SetLogger(log rz.Logger)

SetLogger update log's logger

func Warn

func Warn(message string, fields ...rz.Field)

Warn logs a new message with warn level.

Example

Example of a log at a particular "level" (in this case, "warn")

setup()
log.Warn("hello world")
Output:

{"level":"warning","timestamp":1199811905,"message":"hello world"}

func With

func With(options ...rz.LoggerOption) rz.Logger

With duplicates the global logger and update it's configuration.

Types

This section is empty.

Jump to

Keyboard shortcuts

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