golog

package module
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2023 License: Apache-2.0 Imports: 5 Imported by: 12

README

golog

本日志模块自定义程度高,搭配出自己喜欢的样式。

使用方法

  • 设置level

    SetLogLevel(LOGLEVEL_ALL)
    
  • 简单日志样式

      simplelog := NewSimpleLog()
      simplelog.Logln("这是一个测试的日志。")
    
  • 设置日志样式

      Trace("hello ", "pop\n")
      GetCommonLog().TraceTag.Tag = "NewTag"
      Trace("New Hello.\n")
    
  • 打印日志

      Fatal("fatal\n")
      Error("error\n")
      Warn("warn\n")
      Info("info\n")
      Debug("debug\n")
      Trace("trace\n")
    

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LOGLEVEL_SLIENT int    = 7
	LOGLEVEL_FATAL  int    = 6
	LOGLEVEL_ERROR  int    = 5
	LOGLEVEL_WARN   int    = 4
	LOGLEVEL_INFO   int    = 3
	LOGLEVEL_DEBUG  int    = 2
	LOGLEVEL_TRACE  int    = 1
	LOGLEVEL_ALL    int    = 0
	LOGTAG_FATAL    string = "FATAL"
	LOGTAG_ERROR    string = "ERROR"
	LOGTAG_WARN     string = "WARN"
	LOGTAG_INFO     string = "INFO"
	LOGTAG_DEBUG    string = "DEBUG"
	LOGTAG_TRACE    string = "TRACE"
)

7:slient/off:完全不输出信息 6:fatal:导致程序退出,输出程序退出时的错误信息 5:error:错误信息 4:warn:警告信息 3:info:用于输出信息 2:debug:输出调试信息 1:trace: 程序运行时的跟踪信息 0:all: 所有信息

View Source
var (
	// Unified log date format
	UnifiedLogData LogDate
	// unified log format
	UnifiedLogTag LogTag
	// unified format
	UnifiedLogFormatString string
)

Functions

func CatchError added in v0.0.11

func CatchError(err error) bool

运行时错误。当err不为空时,会提示错误信息,并且会打印函数的调用堆栈。 可以将上层的err直接传到这里,这里处理err。 demo: _, err := function() if CatchError(err) { ......处理错误的代码 } @param err @return bool。如果返回true,表明有错误;false没有发生错误。

func Debug added in v0.0.9

func Debug(msg ...string)

打印debug级别的日志

func Error added in v0.0.9

func Error(msg ...string)

打印error级别的日志

func Fatal added in v0.0.9

func Fatal(msg ...string)

打印fatal级别的日志

func Info added in v0.0.9

func Info(msg ...string)

打印info级别的日志

func SetLogLevel added in v0.0.13

func SetLogLevel(level int) int

设置日志显示等级。默认等级为7(ALL)

func Trace added in v0.0.9

func Trace(msg ...string)

打印trace级别的日志

func Warn added in v0.0.9

func Warn(msg ...string)

打印error级别的日志

Types

type CommonLog added in v0.0.15

type CommonLog struct {
	DateElement LogDate
	FatalTag    LogTag
	ErrorTag    LogTag
	InfoTag     LogTag
	WarnTag     LogTag
	DebugTag    LogTag
	TraceTag    LogTag
	Format      string
	MsgAttr     MsgAttribute
}

func GetCommonLog added in v0.0.10

func GetCommonLog() *CommonLog

获取通用日志对象,通常都使用这个对象进行自定义配置

func NewCommonLog added in v0.0.15

func NewCommonLog() CommonLog

func (CommonLog) Debug added in v0.0.15

func (commlog CommonLog) Debug(msg ...string)

打印debug级别的日志

func (CommonLog) Error added in v0.0.15

func (commlog CommonLog) Error(msg ...string)

打印error级别的日志

func (CommonLog) Fatal added in v0.0.15

func (commlog CommonLog) Fatal(msg ...string)

//////////////////////////////////////////////////// //////////////////////////////////////////////////// //////////////////////////////////////////////////// 打印fatal级别的日志

func (CommonLog) Info added in v0.0.15

func (commlog CommonLog) Info(msg ...string)

打印info级别的日志

func (CommonLog) Trace added in v0.0.15

func (commlog CommonLog) Trace(msg ...string)

打印trace级别的日志

func (CommonLog) Warn added in v0.0.15

func (commlog CommonLog) Warn(msg ...string)

打印error级别的日志

type IElement added in v0.0.15

type IElement interface {
	// get flag of elememt
	Flag() string
	// print
	ToColorString() string
}

type ILog added in v0.0.5

type ILog interface {
}

type ITag added in v0.0.15

type ITag interface {
}

type LogDate added in v0.0.5

type LogDate struct {
	FormatString string
	Font         color.Attribute
	Bgcolor      color.Attribute
	Fgcolor      color.Attribute
}

func (LogDate) Flag added in v0.0.5

func (t LogDate) Flag() string

func (LogDate) ToColorString added in v0.0.15

func (t LogDate) ToColorString() string

type LogTag added in v0.0.15

type LogTag struct {
	FormatString string
	Font         color.Attribute
	Bgcolor      color.Attribute
	Fgcolor      color.Attribute
}

func (LogTag) Flag added in v0.0.15

func (tag LogTag) Flag() string

func (LogTag) ToColorString added in v0.0.15

func (tag LogTag) ToColorString() string

type MsgAttribute added in v0.0.5

type MsgAttribute struct {
	Font    color.Attribute
	Bgcolor color.Attribute
	Fgcolor color.Attribute
}

func (MsgAttribute) GenColor added in v0.0.15

func (m MsgAttribute) GenColor() color.Color

type SimpleLog added in v0.0.5

type SimpleLog struct {
	// 日志中的日期元素
	Data LogDate
	// 日志中的标签原色
	Tag LogTag
	// 日志的格式化字符串
	FormatString string
	// 日志消息
	Msg MsgAttribute
}

func NewSimpleLog added in v0.0.5

func NewSimpleLog() SimpleLog

新建一个simplelog

func (SimpleLog) Log added in v0.0.5

func (simplelog SimpleLog) Log(strs ...string)

print a log

func (SimpleLog) Logln added in v0.0.6

func (simplelog SimpleLog) Logln(strs ...string)

Jump to

Keyboard shortcuts

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