glog

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

简介

作者:京城郭少

关于项目

  • 依赖logrus和file-rotatelogs

特点

  • 每个level都会独立输出到不同的文件。
  • 支持日志切割。
  • 支持输出文件名、函数名和行号。
  • 非DEBUG模式不输出到终端。

Question

问:为什么要自己实现一个输出行号的Hook?

答:logrus作者也不建议输出行号,这会降低程序的性能,这也是logrus迟迟不增加这项功能的原因。而glog的Hook在INFO这个level上是不打日志的,所以性能的损耗一般可以忽略。

版本日志

Version 1.2.0

  • 支持通过配置文件创建Logger,进而自定义是否输出Caller等信息。

Version 1.3.0

  • 支持Windows。rotatelogs这个库对Win10老版本、win10以前的版本、go1.11以下下版本支持得很不好,会出现无法创建软连接的问题。这个版本通过不创建软链接来解决。

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConf = Conf{
	LogDir:            "./logs",
	LogLevel:          InfoLevel,
	LogFileCount:      24,
	IsStdoutPrint:     false,
	CallerPrintLevels: []LogLevel{PanicLevel, FatalLevel, ErrorLevel, WarnLevel},
}

Functions

func GetWriter

func GetWriter(pathLogFile string, logFileCount uint) (*rotatelogs.RotateLogs, error)

得到日志切割的输出对象

func NewLogger

func NewLogger(logDir, logLevel string, AllLevelReportCaller bool, logFileCount uint) (*logrus.Logger, error)

func NewLoggerWithConf added in v0.0.2

func NewLoggerWithConf(conf Conf) (*logrus.Logger, error)

Types

type Conf added in v0.0.2

type Conf struct {
	LogDir            string
	LogLevel          LogLevel
	LogFileCount      uint
	IsStdoutPrint     bool //是否将日志输出到标准输出
	CallerPrintLevels []LogLevel
}

type LogLevel added in v0.0.2

type LogLevel logrus.Level

type PrintFileAndNumHook

type PrintFileAndNumHook struct {
	CallerPrintLevels []logrus.Level
}

指定日志等级输出文件名+行号的hook

func (*PrintFileAndNumHook) Fire

func (hook *PrintFileAndNumHook) Fire(entry *logrus.Entry) error

func (*PrintFileAndNumHook) Levels

func (hook *PrintFileAndNumHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

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