log

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: GPL-3.0 Imports: 9 Imported by: 13

README

crab log

crab log 是一个轻量级log库,支持不同级别不同颜色输出,按天滚动输出日志文件等常用日志功能

Example

Example Output

package main                                                                                                                                                                                                                                              

import (
    "time"

    "dearcode.net/crab/log"
)

func main() {
    log.Debug("default log begin")
    log.Infof("%v test log", time.Now())

    l := log.NewLogger()
    l.Debug("logger 1111111111")
    l.Info("logger 2222222222")
    l.Warningf("logger 33333 %v", time.Now())
    l.Errorf("logger color %v xxxxxx", time.Now().UnixNano())

    //关闭颜色显示
    l.SetColor(false)

    l.Errorf("logger no color %v yyyyyy", time.Now().UnixNano())
    log.Infof("%v default has color test log", time.Now())

    //指定输出文件
    l.SetOutputFile("./vvv.log").SetRolling(true)
    l.Info(time.Now())

}

Installing

Using go get

    $ go get dearcode.net/crab/log  

After this command log is ready to use. Its source will be in:

    $GOPATH/src/dearcode.net/crab/log  

You can use go get -u to update the package.

Documentation

For docs, see http://godoc.org/dearcode.net/crab/log or run:

    $ godoc dearcode.net/crab/log  

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(v ...interface{})

Debug .

func Debugf

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

Debugf .

func Error

func Error(v ...interface{})

Error .

func Errorf

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

Errorf .

func Fatal

func Fatal(v ...interface{})

Fatal .

func Fatalf

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

Fatalf .

func Info

func Info(v ...interface{})

Info .

func Infof

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

Infof .

func SetColor

func SetColor(color bool)

SetColor 设置是否显示颜色.

func SetLevel

func SetLevel(level Level)

SetLevel 设置日志级别.

func SetLevelByString

func SetLevelByString(level string)

SetLevelByString 设置日志级别.

func SetOutputFile added in v1.3.2

func SetOutputFile(f string)

SetOutputFile 初始化时设置输出文件.

func SetRolling added in v1.3.2

func SetRolling(on bool)

SetRolling 每天生成一个文件.

func ToContext added in v1.13.0

func ToContext(ctx context.Context, log *Logger) context.Context

ToContext 保存log对象到ctx中

func Warning

func Warning(v ...interface{})

Warning .

func Warningf

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

Warningf .

Types

type Level added in v1.3.1

type Level int

Level 日志级别.

const (
	//LogFatal fatal.
	LogFatal Level = iota
	//LogError error.
	LogError
	//LogWarning warning.
	LogWarning
	//LogInfo info.
	LogInfo
	//LogDebug debug.
	LogDebug
)

func GetLogLevel

func GetLogLevel() Level

GetLogLevel 获取日志级别.

func (Level) String added in v1.3.1

func (l Level) String() string

Level Level 转字符串.

type Logger

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

Logger 日志对象.

func FromContext added in v1.13.0

func FromContext(ctx context.Context) *Logger

FromContext 从ctx中查找日志对象,找不到返回nil

func FromContextOrDefault added in v1.13.0

func FromContextOrDefault(ctx context.Context) *Logger

FromContextOrDefault 从ctx中查找日志对象,找不到返回默认log对象

func GetLogger added in v1.5.0

func GetLogger() *Logger

GetLogger 获取当前日志对象.

func NewLogger

func NewLogger() *Logger

NewLogger 创建日志对象.

func (*Logger) Debug

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

Debug .

func (*Logger) Debugf

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

Debugf .

func (*Logger) Error

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

Error .

func (*Logger) Errorf

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

Errorf .

func (*Logger) Fatal

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

Fatal .

func (*Logger) Fatalf

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

Fatalf .

func (*Logger) Info

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

Info .

func (*Logger) Infof

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

Infof .

func (*Logger) SetColor

func (l *Logger) SetColor(on bool) *Logger

SetColor 开启/关闭颜色.

func (*Logger) SetLevel

func (l *Logger) SetLevel(level Level) *Logger

SetLevel 设置日志级别.

func (*Logger) SetLevelByString

func (l *Logger) SetLevelByString(level string) *Logger

SetLevelByString 设置字符串格式的日志级别.

func (*Logger) SetOutputFile

func (l *Logger) SetOutputFile(path string) *Logger

SetOutputFile 初始化时设置输出文件.

func (*Logger) SetRolling

func (l *Logger) SetRolling(on bool) *Logger

SetRolling 每天生成一个文件.

func (*Logger) Warning

func (l *Logger) Warning(v ...interface{})

Warning .

func (*Logger) Warningf

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

Warningf .

Jump to

Keyboard shortcuts

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