log

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 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.Debug("this is debug message", "key", "val")
log.Info("this is info message", "key", "val")
log.Warn("this is warn message", "key", "val")
log.Error("this is error message", "key", "val")
log.Fatal("this is error message", "key", "val")

log.With("name", "controller").Info("this is info message", "key", "value")

Documentation

Overview

Package log defines some simple functions for logging.

In your main.go file, use `log.SetLogger(&log.Config{})` to initialize the logger.

In other go files, use `log.Info("the log message", "key", "value")` to print the log messages.

Example:

log.SetLogger(&log.Config{
	Level: "debug",
	Format: "text",
	Layout: "2006-01-02T15:04:05.000000Z",
	NoCaller: false,
})

log.Info("the info log message", "key", "value")
log.Debug("the debug log message")

ctrLog := log.With("name", "controller")
ctrLog.Info("the info log message", "key", "value")
ctrLog.Debug("the debug log message")

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