unilog

package module
v0.0.0-...-4fbcdce Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

README

unilog

unilog is a simple log libary wrap uber zap libary

example

import (
	"github.com/leanfra/unilog"
	"go.uber.org/zap"
)

func main() {
	unilog.SetSimpleLogger("json", "./a.log", zap.DebugLevel)

	unilog.L().Debug("a log 1")
	unilog.L().Debug("a log 2")

	unilog.SetSimpleLogger("console", "/dev/stderr", zap.DebugLevel)
	unilog.L().Debug("b log 1")
	unilog.L().Debug("b log 2")

	unilog.L().Sugar().Error("b error 1")
}

documents

run

go doc --all

Documentation

Index

Constants

View Source
const (
	// LogFormatJSON means json log
	LogFormatJSON = "json"
	// LogFormatConsole means console log
	LogFormatConsole = "console"

	// KeyTime is default TimeKey in zapcore.EncoderConfig
	KeyTime = "time"
	// KeyLevel is default LevelKey in zapcore.EncoderConfig
	KeyLevel = "level"
	// KeyName is default NameKey in zapcore.EncoderConfig
	KeyName = "logger"
	// KeyCaller is default CallerKey in zapcore.EncoderConfig
	KeyCaller = "caller"
	// KeyMessage is default MessageKey in zapcore.EncoderConfig
	KeyMessage = "msg"
	// KeyStackTrace is default StacktraceKey in zapcore.EncoderConfig
	KeyStackTrace = "stacktrace"

	// MaxSizeMB is default max size of log file in MB
	MaxSizeMB = 1
	// MaxBackups is default max count of backup log files
	MaxBackups = 5
	// MaxAge is default max age of log file before delete
	MaxAge = 7
)

Variables

This section is empty.

Functions

func L

func L() *zap.Logger

L return *zap.Logger

func SetLogger

func SetLogger(option *LogOption)

SetLogger create default zap logger

func SetSimpleLogger

func SetSimpleLogger(format string, filename string, level zapcore.Level)

SetSimpleLogger set a simple zap logger

Types

type LogOption

type LogOption struct {
	Format     string
	MaxSizeMB  int
	MaxBackups int
	MaxAge     int
	Level      zapcore.Level
	FileName   string
}

LogOption is option struct

func DefaultLogOption

func DefaultLogOption() *LogOption

DefaultLogOption return default LogOption

func (*LogOption) SetFileName

func (l *LogOption) SetFileName(f string) *LogOption

SetFileName set filename of log file

func (*LogOption) SetFormat

func (l *LogOption) SetFormat(f string) *LogOption

SetFormat set format name of log

func (*LogOption) SetLevel

func (l *LogOption) SetLevel(level zapcore.Level) *LogOption

SetLevel set log level

func (*LogOption) SetMaxAge

func (l *LogOption) SetMaxAge(days int) *LogOption

SetMaxAge set max age in days

func (*LogOption) SetMaxBackups

func (l *LogOption) SetMaxBackups(count int) *LogOption

SetMaxBackups set max backup count

func (*LogOption) SetMaxSizeMB

func (l *LogOption) SetMaxSizeMB(size int) *LogOption

SetMaxSizeMB set max size in MB

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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