log

package module
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: Apache-2.0 Imports: 7 Imported by: 0

README

Logging Utility for Go-Chassis

A structured logger for Go

Usage

Create logger

log.Init(paas_lager.Config{
        LoggerLevel:   loggerLevel,
        LoggerFile:    loggerFile,
        LogFormatText:  false,
})

logger := paas_lager.NewLogger(component)
  • LoggerLevel: 日志级别由低到高分别为 DEBUG, INFO, WARN, ERROR, FATAL 共5个级别,这里设置的级别是日志输出的最低级别,只有不低于该级别的日志才会输出
  • LoggerFile: 输出日志的文件名,为空则输出到 os.Stdout
  • LogFormatText: 设定日志的输出格式是 json 还是 plaintext

Create logger with multiple sinker

	log.Init(log.Config{
		LoggerLevel:   "DEBUG",
		LoggerFile:    "test.log",
		EnableRsyslog: false,
		LogFormatText: false,
		Writers:       []string{"file", "stdout"},
	})

	logger := log.NewLogger("example")

Run log rotate

rotate.RunLogRotate("test.log", &rotate.RotateConfig{}, logger)

Custom your own sinker

type w struct {
}

func (w *w) Write(p []byte) (n int, err error) {
	fmt.Print("fake")
	return 0, nil
}
func main() {
	log.RegisterWriter("test", &w{})
}

See Examples

Documentation

Index

Constants

View Source
const (
	//DEBUG is a constant of string type
	DEBUG = "DEBUG"
	//INFO is constant for info level log
	INFO = "INFO"
	//WARN is constant for warn level log
	WARN = "WARN"
	//ERROR is constant for error level log
	ERROR = "ERROR"
	//FATAL is constant for fail level log
	FATAL = "FATAL"
)

Variables

View Source
var Writers = make(map[string]io.Writer)

Writers is a map

Functions

func Init

func Init(c Config)

Init is a function which initializes all config struct variables

func NewLogger

func NewLogger(component string) lager.Logger

NewLogger is a function

func NewLoggerExt

func NewLoggerExt(component string, appGUID string) lager.Logger

NewLoggerExt is a function which is used to write new logs

func RegisterWriter

func RegisterWriter(name string, writer io.Writer)

RegisterWriter is used to register a io writer

Types

type Config

type Config struct {
	LoggerLevel    string   `yaml:"loggerLevel"`
	LoggerFile     string   `yaml:"loggerFile"`
	Writers        []string `yaml:"writers,flow"`
	LogFormatText  bool     `yaml:"logFormatText"`
	EnableRsyslog  bool
	RsyslogNetwork string
	RsyslogAddr    string
}

Config is a struct which stores details for maintaining logs

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig is a function which retuns config object with default configuration

Directories

Path Synopsis
examples
native command
openlogging command
Package rotate is the package for rotate
Package rotate is the package for rotate
third_party

Jump to

Keyboard shortcuts

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