log

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

README

log

A simple structured log library.

import "github.com/goduang/log"

log.SetLogger(nil)
log.SetLogger(&log.Config{
    Level: "debug",  // debug, info, warn, error
    Format: "text",  // text, json
    NoCaller: false, // print caller info
})

log.Debug("key", "val", "key1", "val1")
log.Info("key", "val", "key1", "val1")
log.Warn("key", "val", "key1", "val1")
log.Error("key", "val", "key1", "val1")
log.Fatal("key", "val", "key1", "val1")

log.With("name", "controller").Info("key", "value")

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(msg string, keyvals ...interface{})

Debug prints a msg and Key/DebugValue pair

func Error

func Error(msg string, keyvals ...interface{})

Error prints a msg and Key/ErrorValue pair

func Fatal

func Fatal(msg string, keyvals ...interface{})

Fatal prints a msg and Key/ErrorValue pair and exit

func Info

func Info(msg string, keyvals ...interface{})

Info prints a msg and Key/InfoValue pair

func SetLogger

func SetLogger(config *Config)

SetLogger initializes a logger with the given configuration

func Warn

func Warn(msg string, keyvals ...interface{})

Warn prints a msg and Key/WarnValue pair

func With

func With(keyvals ...interface{}) loggingT

With returns a new contextual logger with keyvals prepended

Types

type Config

type Config struct {
	Level    string
	Format   string
	Layout   string
	NoCaller bool
}

Config contains all the logger settings

Jump to

Keyboard shortcuts

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