nazalog

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2020 License: MIT Imports: 10 Imported by: 230

Documentation

Overview

package nazalog 日志库

Index

Constants

This section is empty.

Variables

View Source
var ErrLog = errors.New("naza.log:fxxk")

Functions

func Assert added in v0.9.0

func Assert(expected interface{}, actual interface{})

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 Fatalln added in v0.10.0

func Fatalln(v ...interface{})

func Info

func Info(v ...interface{})

func Infof

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

func Init

func Init(modOptions ...ModOption) error

这里不加锁保护,如果要调用Init函数初始化全局的Logger,那么由调用方保证调用Init函数时不会并发调用全局Logger的其他方法

func Out

func Out(level Level, calldepth int, s string)

func Output

func Output(calldepth int, s string) error

func Panic

func Panic(v ...interface{})

func Panicf

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

func Panicln added in v0.10.0

func Panicln(v ...interface{})

func Print added in v0.10.0

func Print(v ...interface{})

func Printf added in v0.10.0

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

func Println added in v0.10.0

func Println(v ...interface{})

func Sync added in v0.8.0

func Sync()

func Warn

func Warn(v ...interface{})

func Warnf

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

Types

type AssertBehavior added in v0.9.0

type AssertBehavior uint8
const (
	AssertError AssertBehavior // 1
	AssertFatal
	AssertPanic
)

type Level

type Level uint8
const (
	LevelDebug Level // 1
	LevelInfo
	LevelWarn
	LevelError
	LevelFatal
	LevelPanic
)

type Logger

type Logger interface {
	Debugf(format string, v ...interface{})
	Infof(format string, v ...interface{})
	Warnf(format string, v ...interface{})
	Errorf(format string, v ...interface{})
	Fatalf(format string, v ...interface{}) // 打印日志并退出程序
	Panicf(format string, v ...interface{})

	Debug(v ...interface{})
	Info(v ...interface{})
	Warn(v ...interface{})
	Error(v ...interface{})
	Fatal(v ...interface{})
	Panic(v ...interface{})

	Out(level Level, calldepth int, s string)

	// 断言失败后的行为由配置项Option.AssertBehavior决定
	// 注意,expected和actual的类型必须相同,比如int(1)和int32(1)是不相等的
	Assert(expected interface{}, actual interface{})

	// flush to disk, typically
	Sync()

	// 添加前缀,新生成一个Logger对象,如果老Logger也有prefix,则老Logger依然打印老prefix,新Logger打印多个prefix
	WithPrefix(s string) Logger

	// 下面这些打印接口是为兼容标准库,让某些已使用标准库日志的代码替换到nazalog方便一些
	Output(calldepth int, s string) error
	Print(v ...interface{})
	Printf(format string, v ...interface{})
	Println(v ...interface{})
	Fatalln(v ...interface{})
	Panicln(v ...interface{})
}

func New

func New(modOptions ...ModOption) (Logger, error)

func WithPrefix added in v0.10.0

func WithPrefix(s string) Logger

type ModOption

type ModOption func(option *Option)

type Option

type Option struct {
	Level Level `json:"level"` // 日志级别,大于等于该级别的日志才会被输出

	// 文件输出和控制台输出可同时打开
	// 控制台输出主要用做开发时调试,打开后level字段使用彩色输出
	Filename   string `json:"filename"`     // 输出日志文件名,如果为空,则不写日志文件。可包含路径,路径不存在时,将自动创建
	IsToStdout bool   `json:"is_to_stdout"` // 是否以stdout输出到控制台

	IsRotateDaily bool `json:"is_rotate_daily"` // 日志按天翻转

	ShortFileFlag bool `json:"short_file_flag"` // 是否在每行日志尾部添加源码文件及行号的信息

	AssertBehavior AssertBehavior `json:"assert_behavior"` // 断言失败时的行为
}

Jump to

Keyboard shortcuts

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