logs

package
v0.1.140 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	LevelNone   = 0x00
	LevelDebug  = 0x01
	LevelInfo   = 0x02
	LevelNotice = 0x04
	LevelWarn   = 0x08
	LevelError  = 0x10
	LevelFatal  = 0x20
	LevelAll    = 0xFF

	TargetConsole = "console"
	TargetFile    = "file"

	SkipKey = "__"
)

Variables

This section is empty.

Functions

func LevelToString

func LevelToString(level int) string

LevelToString convert int level to string

func StringToLevel

func StringToLevel(level string) int

StringToLevel convert string to int level

Types

type Console

type Console struct {
	Target
}

ConsoleTarget target for console

func (*Console) Flush

func (c *Console) Flush(final bool)

Flush flush log to stdout

func (*Console) Process

func (c *Console) Process(item *LogItem)

Process write log to stdout

type File

type File struct {
	Target
	// contains filtered or unexported fields
}

func (*File) Flush

func (f *File) Flush(final bool)

Flush flush log buffer to file

func (*File) Init

func (f *File) Init()

func (*File) Process

func (f *File) Process(item *LogItem)

Process check and rotate log file if rotate is enable, write log to buffer, flush buffer to file if buffer is full.

func (*File) SetFilePath

func (f *File) SetFilePath(filePath string)

SetFilePath set file path, default "@runtime/app.log"

func (*File) SetLogFormatter added in v0.1.133

func (f *File) SetLogFormatter(s string)

SetLogFormatter set formatter - json for JSON formmatter

func (*File) SetMaxBufferByte

func (f *File) SetMaxBufferByte(maxBufferByte int)

SetMaxBufferByte set max buffer bytes, default 10MB

func (*File) SetMaxBufferLine

func (f *File) SetMaxBufferLine(maxBufferLine int)

SetMaxBufferLine set max buffer lines, default 10000

func (*File) SetMaxLogFile

func (f *File) SetMaxLogFile(maxLogFile int)

SetMaxLogFile set max log backups, default 10

func (*File) SetRotate

func (f *File) SetRotate(rotate string)

SetRotate set rotate policy(none, hourly, daily), default "daily"

type IFormatter

type IFormatter interface {
	Format(item *LogItem) string
}
var (
	// JSONFormatter log JSON formatter
	JSONFormatter IFormatter = jsonFormatter{}

	// JSONAccessFormatter access log with JSON formatter
	JSONAccessFormatter iface.IAccessLogFormat = jsonAccessFormatter{}
)

type ILogger added in v0.1.7

type ILogger interface {
	Debug(format string, v ...interface{})
	Info(format string, v ...interface{})
	Notice(format string, v ...interface{})
	Warn(format string, v ...interface{})
	Error(format string, v ...interface{})
	Fatal(format string, v ...interface{})
}

type ITarget

type ITarget interface {
	SetLevels(v interface{})
	SetFormatter(v interface{})
	IsHandling(level int) bool
	Format(item *LogItem) string
	Process(item *LogItem)
	Flush(final bool)
}

func NewConsole

func NewConsole(dftConfig ...map[string]interface{}) ITarget

func NewFile

func NewFile(runtimePath string, dftConfig ...map[string]interface{}) ITarget

File target for file, configuration: info:

class: "@pgo/logs/File"
levels: "DEBUG,INFO,NOTICE"
filePath: "@runtime/info.log"
maxLogFile: 10
maxBufferByte: 10485760
maxBufferLine: 10000
rotate: "daily"

type Log

type Log struct {
	// contains filtered or unexported fields
}

func NewLog

func NewLog(runtimePath string, config map[string]interface{}) *Log

Log the log component, configuration: log:

levels: "ALL"
traceLevels: "DEBUG"
chanLen: 1000
flushInterval: "60s"
targets:
    info:
        name: "file"
        levels: "DEBUG,INFO,NOTICE"
        filePath: "@runtime/info.log"
        maxLogFile: 10
        rotate: "daily"
    error: {
        name: "file"
        levels: "WARN,ERROR,FATAL"
        filePath: "@runtime/error.log"
        maxLogFile: 10
        rotate: "daily"

func (*Log) Flush

func (d *Log) Flush()

Flush close msg chan and wait loop end

func (*Log) Init

func (d *Log) Init()

func (*Log) Logger

func (d *Log) Logger(name, logId string) *Logger

GetLogger get a new logger with name and id specified

func (*Log) Profiler

func (d *Log) Profiler() *Profiler

GetProfiler get a new profiler

func (*Log) SetChanLen

func (d *Log) SetChanLen(len int)

SetChanLen set length of log channel, default 1000

func (*Log) SetFlushInterval

func (d *Log) SetFlushInterval(v string)

SetFlushInterval set interval to flush log, default "60s"

func (*Log) SetLevels

func (d *Log) SetLevels(v interface{})

SetLevels set levels to handle, default "ALL"

func (*Log) SetTarget

func (d *Log) SetTarget(name string, target ITarget)

SetTarget set output target

func (*Log) SetTargets

func (d *Log) SetTargets(targets map[string]interface{})

SetTargets set output target, ConsoleTarget will be used if no targets specified

func (*Log) SetTraceLevels

func (d *Log) SetTraceLevels(v interface{})

SetTraceLevels set levels to trace, default "DEBUG"

func (*Log) Target

func (d *Log) Target(name string) ITarget

type LogItem

type LogItem struct {
	When    time.Time
	Level   int
	Name    string
	LogId   string
	Trace   string
	Message string
}

LogItem represent an item of log

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

Logger

func NewLogger

func NewLogger(name, logId string, log *Log) *Logger

func (*Logger) Debug

func (l *Logger) Debug(format string, v ...interface{})

func (*Logger) Error

func (l *Logger) Error(format string, v ...interface{})

func (*Logger) Fatal

func (l *Logger) Fatal(format string, v ...interface{})

func (*Logger) Info

func (l *Logger) Info(format string, v ...interface{})

func (*Logger) Init

func (l *Logger) Init(name, logId string, log *Log)

func (*Logger) LogId

func (l *Logger) LogId() string

func (*Logger) Notice

func (l *Logger) Notice(format string, v ...interface{})

func (*Logger) SetLogId

func (l *Logger) SetLogId(v string)

func (*Logger) Warn

func (l *Logger) Warn(format string, v ...interface{})

type Profiler

type Profiler struct {
	ProfileEnable bool
	// contains filtered or unexported fields
}

Profiler

func NewProfiler

func NewProfiler() *Profiler

func (*Profiler) Counting

func (p *Profiler) Counting(key string, hit, total int)

Counting add counting info, the counting string is key=sum(hit)/sum(total)

func (*Profiler) CountingString

func (p *Profiler) CountingString() string

GetCountingString get counting info string

func (*Profiler) ProfileAdd

func (p *Profiler) ProfileAdd(key string, elapse time.Duration)

ProfileAdd add profile info, the profile string is key=sum(elapse)/count

func (*Profiler) ProfileStart

func (p *Profiler) ProfileStart(key string)

ProfileStart mark start of profile

func (*Profiler) ProfileStop

func (p *Profiler) ProfileStop(key string)

ProfileStop mark stop of profile

func (*Profiler) ProfileString

func (p *Profiler) ProfileString() string

GetProfileString get profile info string

func (*Profiler) PushLog

func (p *Profiler) PushLog(key string, v interface{})

PushLog add push log, the push log string is key=Util.ToString(v)

func (*Profiler) PushLogString

func (p *Profiler) PushLogString() string

GetPushLogString get push log string

func (*Profiler) Reset

func (p *Profiler) Reset()

func (*Profiler) SetProfileEnable added in v0.1.120

func (p *Profiler) SetProfileEnable(v bool)

SetEnable log switch

type Target

type Target struct {
	// contains filtered or unexported fields
}

Target base class of output

func (*Target) Format

func (t *Target) Format(item *LogItem) string

Format format log item to string

func (*Target) IsHandling

func (t *Target) IsHandling(level int) bool

IsHandling check whether this target is handling the log item

func (*Target) SetFormatter

func (t *Target) SetFormatter(v interface{})

SetFormatter set user-defined log formatter, eg. "Lib/Log/Formatter"

func (*Target) SetLevels

func (t *Target) SetLevels(v interface{})

SetLevels set levels for target, eg. "DEBUG,INFO,NOTICE"

Jump to

Keyboard shortcuts

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