zdpgo_log

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2022 License: MIT Imports: 5 Imported by: 15

README

zdpgo_log

Golang处理日志的专用库

项目地址:https://github.com/zhangdapeng520/zdpgo_log

版本历史

  • 2022年3月28日 版本0.1.0 基本日志功能

使用案例

案例1:基本使用
package main

import "github.com/zhangdapeng520/zdpgo_log"

func main() {
	config := zdpgo_log.LogConfig{
		Debug: true,
		Path:  "logs/zdpgo/zdpgo_log.log",
		Level: zdpgo_log.LEVEL_DEBUG,
	}
	log := zdpgo_log.New(config)
	log.SetDebug(true) // 开启debug模式
	log.Debug("debug...")
	log.Info("info...")
	log.Warning("warning...")
	log.Error("error...")
	//log.Panic("panic...")

	// 关闭debug模式,日志不再输出到控制台
	log.SetDebug(false)
	log.Debug("debug 111...")
	log.Info("info 111...")
	log.Warning("warning 111...")
	log.Error("error 111...")

	// 修改日志等级
	log.SetLevel(zdpgo_log.LEVEL_WARNING)
	log.Debug("debug 222...")
	log.Info("info 222...")
	log.Warning("warning 222...")
	log.Error("error 222...")
}

Documentation

Index

Constants

View Source
const (
	LEVEL_DEBUG = iota
	LEVEL_INFO
	LEVEL_WARNING
	LEVEL_ERROR
	LEVEL_PANIC
)

日志等级

Variables

This section is empty.

Functions

This section is empty.

Types

type Log

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

Log 核心日志对象

func New

func New(config LogConfig) *Log

New 创建日志对象

func (*Log) Debug

func (l *Log) Debug(args ...interface{})

Debug 记录debug类型的日志

func (*Log) Error

func (l *Log) Error(args ...interface{})

记录error类型的日志

func (*Log) Info

func (l *Log) Info(args ...interface{})

Info 记录info类型的日志

func (*Log) IsDebug

func (log *Log) IsDebug() bool

IsDebug 是否为debug模式

func (*Log) Panic

func (l *Log) Panic(args ...interface{})

Panic 记录panic类型的日志,会panic出异常

func (*Log) SetDebug

func (l *Log) SetDebug(flag bool)

SetDebug 设置日志的debug模式

func (*Log) SetLevel

func (l *Log) SetLevel(level int)

SetLevel 设置日志的等级

func (*Log) Warning

func (l *Log) Warning(args ...interface{})

Warning 记录warning类型的日志

type LogConfig

type LogConfig struct {
	Debug bool   `yaml:"debug" json:"debug"` // 是否为debug模式
	Path  string `yaml:"path" json:"path"`   // 日志存放路径
	Level int    `yaml:"level" json:"level"` // 日志等级
}

LogConfig 日志配置

Directories

Path Synopsis
examples
z01_hello command

Jump to

Keyboard shortcuts

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