log

package module
v0.0.0-...-1e67f5f Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2019 License: Apache-2.0 Imports: 8 Imported by: 38

README

logging(Forked from ngaut/log)

新增SetCallDepth方法,用于修改寻找调用函数对应的调用深度,以便对日志输出进行封装及自定义。

example:[https://github.com/heyHui2018/best-practise]

  • 声明:
type LogP struct {
	TraceId string
}
log.SetCallDepth(5)
  • 封装
func (l *LogP) logP(format string, v ...interface{}) {
	log.Infof(l.TraceId+" "+format, v)
}
  • 调用:
l := new(LogP)
	l.TraceId = time.Now().Format("20060102150405") + utils.GetRandomString()
	l.logP("Register 完成,耗时 = %v", 123)
  • 说明:
  • 实现自定义
  • 准确输出调用层级

Documentation

Overview

high level log wrapper, so it can output different log based on level

Index

Constants

View Source
const (
	Ldate         = log.Ldate
	Llongfile     = log.Llongfile
	Lmicroseconds = log.Lmicroseconds
	Lshortfile    = log.Lshortfile
	LstdFlags     = log.LstdFlags
	Ltime         = log.Ltime
)
View Source
const (
	LOG_FATAL   = LogType(0x1)
	LOG_ERROR   = LogType(0x2)
	LOG_WARNING = LogType(0x4)
	LOG_INFO    = LogType(0x8)
	LOG_DEBUG   = LogType(0x10)
)
View Source
const (
	LOG_LEVEL_NONE  = LogLevel(0x0)
	LOG_LEVEL_FATAL = LOG_LEVEL_NONE | LogLevel(LOG_FATAL)
	LOG_LEVEL_ERROR = LOG_LEVEL_FATAL | LogLevel(LOG_ERROR)
	LOG_LEVEL_WARN  = LOG_LEVEL_ERROR | LogLevel(LOG_WARNING)
	LOG_LEVEL_INFO  = LOG_LEVEL_WARN | LogLevel(LOG_INFO)
	LOG_LEVEL_DEBUG = LOG_LEVEL_INFO | LogLevel(LOG_DEBUG)
	LOG_LEVEL_ALL   = LOG_LEVEL_DEBUG
)
View Source
const FORMAT_TIME_DAY string = "20060102"
View Source
const FORMAT_TIME_HOUR string = "2006010215"

Variables

This section is empty.

Functions

func CrashLog

func CrashLog(file string)

func Debug

func Debug(v ...interface{})

func Debugf

func Debugf(format string, v ...interface{})

func Error

func Error(v ...interface{})

func Errorf

func Errorf(format string, v ...interface{})

func Fatal

func Fatal(v ...interface{})

func Fatalf

func Fatalf(format string, v ...interface{})

func Info

func Info(v ...interface{})

func Infof

func Infof(format string, v ...interface{})

func LogTypeToString

func LogTypeToString(t LogType) (string, string)

func Logger

func Logger() *log.Logger

func New

func New() *logger

func Newlogger

func Newlogger(w io.Writer, prefix string) *logger

func SetFlags

func SetFlags(flags int)

func SetHighlighting

func SetHighlighting(highlighting bool)

func SetLevel

func SetLevel(level LogLevel)

func SetLevelByString

func SetLevelByString(level string)

func SetOutput

func SetOutput(out io.Writer)

func SetOutputByName

func SetOutputByName(path string) error

func SetRotateByDay

func SetRotateByDay()

func SetRotateByHour

func SetRotateByHour()

func Warn

func Warn(v ...interface{})

func Warnf

func Warnf(format string, v ...interface{})

func Warning

func Warning(v ...interface{})

func Warningf

func Warningf(format string, v ...interface{})

Types

type LogLevel

type LogLevel int

func GetLogLevel

func GetLogLevel() LogLevel

func StringToLogLevel

func StringToLogLevel(level string) LogLevel

type LogType

type LogType int

type TLog

type TLog struct {
	TraceId string
}

func (*TLog) Debugf

func (t *TLog) Debugf(format string, v ...interface{})

func (*TLog) Errorf

func (t *TLog) Errorf(format string, v ...interface{})

func (*TLog) Fatalf

func (t *TLog) Fatalf(format string, v ...interface{})

func (*TLog) Infof

func (t *TLog) Infof(format string, v ...interface{})

func (*TLog) Warnf

func (t *TLog) Warnf(format string, v ...interface{})

func (*TLog) Warningf

func (t *TLog) Warningf(format string, v ...interface{})

Jump to

Keyboard shortcuts

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