Help us shape the future of Go! Take the 2026 Go Developer Survey

seclog

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 8 Imported by: 2

README

seclog

A secure log tool fo go

Usage

Create logger

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

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

Create logger with multiple sinker

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

	logger := seclog.NewLogger("example")

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() {
	seclog.RegisterWriter("test", &w{})
}

See Examples

Change log level on-fly

l.SetLogLevel(lager.ERROR)

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"`
	LogFormatText bool     `yaml:"logFormatText"`

	//for rotate
	RotateDisable bool `yaml:"rotateDisable"`
	MaxSize       int  `yaml:"maxSize"`
	MaxAge        int  `yaml:"maxAge"`
	MaxBackups    int  `yaml:"maxBackups"`
	Compress      bool `yaml:"compress"`
}

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
third_party

Jump to

Keyboard shortcuts

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