logging

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: BSD-3-Clause Imports: 16 Imported by: 19

Documentation

Index

Constants

View Source
const (
	KB _UNIT = 1 << (iota * 10)
	MB
	GB
	TB
)
View Source
const (
	MODE_HOUR  _MODE_TIME = 1
	MODE_DAY   _MODE_TIME = 2
	MODE_MONTH _MODE_TIME = 3
)
View Source
const (
	/*无其他格式,只打印日志内容*/ /*no format, Only log content is printed*/
	FORMAT_NANO       _FORMAT = 0

	/*长文件名(文件绝对路径)及行数*/ /*full file name and line number*/
	FORMAT_LONGFILENAME = _FORMAT(8)

	/*短文件名及行数*/          /*final file name element and line number*/
	FORMAT_SHORTFILENAME = _FORMAT(16)

	/*日期时间精确到天*/ /*the date in the local time zone: 2009/01/23*/
	FORMAT_DATE  = _FORMAT(1)

	/*时间精确到秒*/  /*the time in the local time zone: 01:23:23*/
	FORMAT_TIME = _FORMAT(2)

	/*时间精确到微秒*/        /*microsecond resolution: 01:23:23.123123.*/
	FORMAT_MICROSECNDS = _FORMAT(4)
)
View Source
const (
	/*日志级别:ALL 最低级别*/ /*Log level: LEVEL_ALL is the lowest level,If the log level is this level, logs of other levels can be printed*/
	LEVEL_ALL         _LEVEL = iota

	/*日志级别:DEBUG 小于INFO*/ /*Log level: ALL<DEBUG<INFO*/
	LEVEL_DEBUG

	/*日志级别:INFO 小于 WARN*/ /*Log level: DEBUG<INFO<WARN*/
	LEVEL_INFO

	/*日志级别:WARN 小于 ERROR*/ /*Log level: INFO<WARN<ERROR*/
	LEVEL_WARN

	/*日志级别:ERROR 小于 FATAL*/ /*Log level: WARN<ERROR<FATAL*/
	LEVEL_ERROR

	/*日志级别:FATAL 小于 OFF*/ /*Log level: ERROR<FATAL<OFF*/
	LEVEL_FATAL

	/*日志级别:off 不打印任何日志*/ /*Log level: LEVEL_OFF means none of the logs can be printed*/
	LEVEL_OFF
)
View Source
const (
	VERSION string = "0.0.2"
)

Variables

View Source
var DEBUGNAME, INFONAME, WARNNAME, ERRORNAME, FATALNAME = []byte("[DEBUG]"), []byte("[INFO]"), []byte("[WARN]"), []byte("[ERROR]"), []byte("[FATAL]")
View Source
var TIME_DEVIATION time.Duration

Functions

This section is empty.

Types

type Logging

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

————————————————————————————————————————————————————————————————————————————

func Debug

func Debug(v ...interface{}) *Logging

Logs are printed at the DEBUG level

func Error

func Error(v ...interface{}) *Logging

Logs are printed at the ERROR level

func Fatal

func Fatal(v ...interface{}) *Logging

Logs are printed at the FATAL level

func GetStaticLogger

func GetStaticLogger() *Logging

获得全局Logger对象 return the default log object

func Info

func Info(v ...interface{}) *Logging

Logs are printed at the INFO level

func NewLogger

func NewLogger() (log *Logging)

return a new log object

func SetConsole

func SetConsole(on bool) *Logging

print logs on the console or not. default true

func SetFormat

func SetFormat(format _FORMAT) *Logging

设置打印格式

func SetGzipOn

func SetGzipOn(is bool) (l *Logging)

when set true, the specified backup file of both SetRollingFile and SetRollingFileLoop will be save as a compressed file

func SetLevel

func SetLevel(level _LEVEL) *Logging

设置控制台日志级别,默认ALL Setting the log Level

func SetRollingByTime

func SetRollingByTime(fileDir, fileName string, mode _MODE_TIME) (l *Logging, err error)

like SetRollingDaily,but supporte hourly backup ,dayly backup and monthly backup mode : MODE_HOUR MODE_DAY MODE_MONTH

func SetRollingDaily

func SetRollingDaily(fileDir, fileName string) (l *Logging, err error)

yesterday's log data is backed up to a specified log file each day Parameters:

  • fileDir :directory where log files are stored, If it is the current directory, you also can set it to ""
  • fileName : log file name

func SetRollingFile

func SetRollingFile(fileDir, fileName string, maxFileSize int64, unit _UNIT) (l *Logging, err error)

when the log file(fileDir+`\`+fileName) exceeds the specified size(maxFileSize), it will be backed up with a specified file name Parameters:

  • fileDir :directory where log files are stored, If it is the current directory, you also can set it to ""
  • fileName : log file name
  • maxFileSize : maximum size of a log file
  • unit : size unit : KB,MB,GB,TB

func SetRollingFileLoop

func SetRollingFileLoop(fileDir, fileName string, maxFileSize int64, unit _UNIT, maxFileNum int) (l *Logging, err error)

like SetRollingFile,but only keep (maxFileNum) current files - maxFileNum : the number of files that are retained

func Warn

func Warn(v ...interface{}) *Logging

Logs are printed at the WARN level

func (*Logging) Debug

func (t *Logging) Debug(v ...interface{}) *Logging

func (*Logging) Error

func (t *Logging) Error(v ...interface{}) *Logging

func (*Logging) Fatal

func (t *Logging) Fatal(v ...interface{}) *Logging

func (*Logging) Info

func (t *Logging) Info(v ...interface{}) *Logging

func (*Logging) SetConsole

func (t *Logging) SetConsole(_isConsole bool) *Logging

控制台日志是否打开

func (*Logging) SetFormat

func (t *Logging) SetFormat(format _FORMAT) *Logging

func (*Logging) SetGzipOn

func (t *Logging) SetGzipOn(is bool) *Logging

func (*Logging) SetLevel

func (t *Logging) SetLevel(level _LEVEL) *Logging

func (*Logging) SetRollingByTime

func (t *Logging) SetRollingByTime(fileDir, fileName string, mode _MODE_TIME) (l *Logging, err error)

指定按 小时,天,月 分割日志文件 fileDir 日志文件夹路径 fileName 日志文件名 mode 指定 小时,天,月

func (*Logging) SetRollingDaily

func (t *Logging) SetRollingDaily(fileDir, fileName string) (l *Logging, err error)

按日期分割日志文件 fileDir 日志文件夹路径 fileName 日志文件名

func (*Logging) SetRollingFile

func (t *Logging) SetRollingFile(fileDir, fileName string, maxFileSize int64, unit _UNIT) (l *Logging, err error)

按日志文件大小分割日志文件 fileDir 日志文件夹路径 fileName 日志文件名 maxFileSize 日志文件大小最大值 unit 日志文件大小单位

func (*Logging) SetRollingFileLoop

func (t *Logging) SetRollingFileLoop(fileDir, fileName string, maxFileSize int64, unit _UNIT, maxFileNum int) (l *Logging, err error)

按日志文件大小分割日志文件,指定保留的最大日志文件数 fileDir 日志文件夹路径 fileName 日志文件名 maxFileSize 日志文件大小最大值 unit 日志文件大小单位 maxFileNum 留的日志文件数

func (*Logging) Warn

func (t *Logging) Warn(v ...interface{}) *Logging

func (*Logging) Write

func (t *Logging) Write(bs []byte) (n int, err error)

func (*Logging) WriteBin

func (t *Logging) WriteBin(bs []byte) (bakfn string, err error)

Jump to

Keyboard shortcuts

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