logz

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2020 License: MIT Imports: 6 Imported by: 0

README

logz

Simple log wrapper to provide leveled, structured logging.

Usage
package main

import (
    "errors"
    "go.nuvuli.com/logz"
)

func main() {
    logger := logz.NewLogger(logz.Error) // only print errors

    logger.Info("key", "value", "key2", "value2") // not printed

    logger.InfoWithMessage("heyo") // "msg", "heyo" // not printed

    err := errors.New("something is wrong!")

    logger.Error(err, "key", "value") 
    // prints {"caller":"main.go:17","err":"something is wrong!","key":"value","level":"error","ts":"2019-09-30T13:33:26.253478Z"}
}

Documentation

Index

Constants

View Source
const All = Level("all")

All specifies all messages should be written. It is an alias for Debug.

View Source
const Debug = Level("debug")

Debug specifies that only messages of Level Info, Warn, Debug or Error are written

View Source
const Error = Level("error")

Error specifies that only messages of Level Error are written

View Source
const Info = Level("info")

Error specifies that only messages of Level Info, Warn, or Error are written

View Source
const Warn = Level("warn")

Warn specifies that only messages of Level Error or Warn are written

Variables

This section is empty.

Functions

This section is empty.

Types

type Level

type Level string

Level represents the log level of a logger

func ParseLevel

func ParseLevel(lvl string) Level

func (Level) Option

func (l Level) Option() level.Option

type Logger

type Logger interface {
	// Info writes Info level logs of key/value pairs
	InfoWithData(keyvals ...interface{})
	// InfoWithMessage writes Info level logs of key/value pairs. The msg is written with a key of "msg".
	Info(msg string, keyvals ...interface{})

	// Warn writes Warn level logs of key/value pairs
	WarnWithData(keyvals ...interface{})
	// WarnWithMessage writes Warn level logs of key/value pairs. The msg is written with a key of "msg".
	Warn(msg string, keyvals ...interface{})

	// Error writes Error level logs of key/value pairs. err is written with a key of "err".
	ErrorWithData(err error, keyvals ...interface{})
	// ErrorWithMessage writes Error level logs of key/value pairs. err is written with a key of "err". The msg is written with a key of "msg".
	Error(err error, msg string, keyvals ...interface{})

	// Debug writes Debug level logs of key/value pairs
	DebugWithData(keyvals ...interface{})
	// DebugWithMessage writes Debug level logs of key/value pairs. The msg is written with a key of "msg".
	Debug(msg string, keyvals ...interface{})

	// FatalError writes an Error level message and the calls os.Exit(1) if err is not nil. The "fataL" key value will be "true".
	FatalError(err error, keyvals ...interface{})
}

Logger is a basic logging interface for a structured logger.

func NewLogger

func NewLogger(lvl Level) Logger

NewLogger creates a new instance of Logger using the specified Level as the lowest level that will be logged.

func NewNullLogger

func NewNullLogger() Logger

NewNullLogger returns a no op logger. Useful if your testing code that has a Logger dependency.

func With

func With(theLogger Logger, keyvals ...interface{}) Logger

With wrapps theLogger with a new logger that will always include keyvals in its output.

Jump to

Keyboard shortcuts

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