logging

package
v0.0.0-...-163fc3c Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2021 License: MIT Imports: 11 Imported by: 0

README

SKT Client: Logging Package

Feature

  • Format and output logs to console and file.
  • Rotate old log files.

Usage

Initialization
logging.Init(path string, level string, age uint32, disableCPrint bool)
  • path: path of log file.
  • loglevel: minimum log level to output. debug, info, warn, error, fatal.
  • age: time to keep logs. One year by default.
Logging
logging.CPrint(level uint32, msg string, formats ...LogFormat) // Output to console and file.
logging.VPrint(level uint32, msg string, formats ...LogFormat) // Output only to file. 
  • level:debug, info, warn, error, fatal.
    • error a call stack will be shown after logged.
    • fatal an exit signal will be sent to system after logged.
  • msg: log message.
  • data: extra content in LogFormat (map of {k-v}).
type LogFormat = map[string]interface{}
Format in log files

tid time level file func logline

Documentation

Index

Constants

View Source
const (
	PanicLevel = "panic"
	FatalLevel = "fatal"
	ErrorLevel = "error"
	WarnLevel  = "warn"
	InfoLevel  = "info"
	DebugLevel = "debug"
	TraceLevel = "trace"
)

const

View Source
const (
	//PANIC log level
	PANIC uint32 = iota
	//FATAL has list msg
	FATAL
	//ERROR has list msg
	ERROR
	//WARN only log
	WARN
	//INFO only log
	INFO
	//DEBUG only log
	DEBUG
	//TRACE only log
	TRACE
)
View Source
const (
	//MsgFormatSingle use info
	MsgFormatSingle uint32 = iota
	//MsgFormatMulti use show all func call relation
	MsgFormatMulti
)

Variables

This section is empty.

Functions

func CPrint

func CPrint(level uint32, msg string, formats ...LogFormat)

CPrint into stdout + log

func GetGID

func GetGID() uint64

GetGID return gid

func Init

func Init(path, filename string, level string, age uint32, disableCPrint bool)

Init loggers

func LoadFunctionHooker

func LoadFunctionHooker(logger *Logger)

LoadFunctionHooker loads a function hooker to the logger

func NewFileRotateHooker

func NewFileRotateHooker(path, filename string, age uint32, formatter logrus.Formatter) logrus.Hook

NewFileRotateHooker enable log file output

func VPrint

func VPrint(level uint32, msg string, formats ...LogFormat)

VPrint into log

Types

type LogFormat

type LogFormat = map[string]interface{}

LogFormat is to log format

type Logger

type Logger struct {
	*logrus.Logger
	//CallRelation to show stack list
	CallRelation uint32
}

func NewLogger

func NewLogger() *Logger

func (*Logger) SetCallRelation

func (logger *Logger) SetCallRelation(button uint32)

SetCallList to set CallList

Jump to

Keyboard shortcuts

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