logfarm

package module
v0.0.0-...-f0c3d3c Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: GPL-3.0 Imports: 16 Imported by: 0

README

log-farm

a tool to write logs to file or on the screen with values by separator

Introduce

Installation
go get -u github.com/go-trellis/log-farm
Usage
// NewLoggersFromConfig(filepath string) (err errors.ErrorCode) 
if err := logfarm.NewLoggersFromConfig("sample.conf"); err != nil {
	panic(err)
}
logfarm.Debug("test", "first_example")
Log functions
// Debug 调试
func Debug(msg string, fields ...interface{}) {
	publishLog(DebugLevel, msg, fields...)
}

// Info 信息
func Info(msg string, fields ...interface{}) {
	publishLog(InfoLevel, msg, fields...)
}

// Error 错误
func Error(msg string, fields ...interface{}) {
	publishLog(ErrorLevel, msg, fields...)
}

// Warn 警告
func Warn(msg string, fields ...interface{}) {
	publishLog(WarnLevel, msg, fields...)
}

// Panic 异常
func Panic(msg string, fields ...interface{}) {
	publishLog(PanicLevel, msg, fields...)
}
Param Information
writer type
// FileWriterType 文件打印类型
FileWriterType = "file_writer"
// StdWriterType 标准打印类型
StdWriterType = "std_writer"
params
  • filename: the log path & name, see more in example. only use in file writer
  • filepath: log file' path
  • chanbuffer: length of the log chan buffer
  • maxfilelength: the max length of log file, default: 0 is unlimit
  • movefiletype: move file by per-minite(1) or hourly(2) or daily(3), 0 is doing nothing
  • maxbackupfile: the max number of backup files, default: 0 is unlimit
  • separator: log values' separator, such as: "|", "\t"
  • prefixes: is a slice to writing into the file or printing on screen before the log values
More Example

Documentation

Index

Constants

View Source
const (

	// FileWriterType 文件打印类型
	FileWriterType = "file_writer"
	// StdWriterType 标准打印类型
	StdWriterType = "std_writer"
)
View Source
const (
	MinLevel = Level(iota)
	DebugLevel
	InfoLevel
	WarnLevel
	ErrorLevel
	PanicLevel

	LevelNameUnknown = "Unknown"
	LevelNameDebug   = "DEBUG"
	LevelNameInfo    = "INFO"
	LevelNameWarn    = "WARN"
	LevelNameError   = "ERROR"
	LevelNamePanic   = "PANIC"
)

define levels

View Source
const DefaultLogEventName = "trellis::logfarm::event"

DefaultLogEventName default event name for logging

Variables

View Source
var (
	ErrNilConfig        = errors.TN(errorNamespace, 1, "config is nil")
	ErrFailedInitWriter = errors.TN(errorNamespace, 2, "failed initial writer: {{.err}}")
)

errors

Functions

func ClearSubscribers

func ClearSubscribers()

ClearSubscribers 释放所有的对象

func Debug

func Debug(msg string, fields ...interface{})

Debug 调试

func Debugf

func Debugf(msg string, fields ...interface{})

Debugf 调试

func Error

func Error(msg string, fields ...interface{})

Error 错误

func Errorf

func Errorf(msg string, fields ...interface{})

Errorf 错误

func FileWriter

func FileWriter(cfg config.Configuration) errors.ErrCode

FileWriter get file logger farm

func Info

func Info(msg string, fields ...interface{})

Info 信息

func Infof

func Infof(msg string, fields ...interface{})

Infof 信息

func NewLoggers

func NewLoggers(cfg config.Configuration) (err errors.ErrCode)

NewLoggers var loggers map[string]LoggerWriter

func NewLoggersFromConfig

func NewLoggersFromConfig(filepath string) (err errors.ErrCode)

NewLoggersFromConfig var loggers map[string]LoggerWriter

func Panic

func Panic(msg string, fields ...interface{})

Panic 异常

func Panicf

func Panicf(msg string, fields ...interface{})

Panicf 异常

func RemoveSubscriber

func RemoveSubscriber(ids ...string) errors.ErrCode

RemoveSubscriber 删除个人的操作函数

func Stack

func Stack() string

Stack stores a stacktrace under the key "stacktrace".

func StdWriter

func StdWriter(config config.Configuration) errors.ErrCode

StdWriter 标准窗体的输出对象

func Subscriber

func Subscriber(fn func(...interface{})) (*event.Subscriber, errors.ErrCode)

Subscriber 注册个人的操作函数

func ToLevelName

func ToLevelName(lvl Level) string

ToLevelName 等级转换为名称

func Warn

func Warn(msg string, fields ...interface{})

Warn 警告

func Warnf

func Warnf(msg string, fields ...interface{})

Warnf 警告

Types

type Event

type Event struct {
	Time    time.Time
	Level   Level
	Message string
	Fields  []interface{}
	// contains filtered or unexported fields
}

Event log mesage

type FileSort

type FileSort []os.FileInfo

FileSort 文件排序

func (FileSort) Len

func (fs FileSort) Len() int

func (FileSort) Less

func (fs FileSort) Less(i, j int) bool

func (FileSort) Swap

func (fs FileSort) Swap(i, j int)

type Level

type Level int32

Level log level

type MoveFileType

type MoveFileType int

MoveFileType move file type

const (
	MoveFileTypeNothing MoveFileType = iota
	MoveFileTypePerMinite
	MoveFileTypeHourly
	MoveFileTypeDaily
)

MoveFileTypes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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