golog

package
v0.0.0-...-52d6a69 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

golog

本日志库初期为本人的golang提供日志支持

基础代码基于golang的官方日志库修改

主要功能

  • 增加了log级别设置

  • 去掉默认全局日志接口,使用日志需要实例化给出模块名方便跟踪

  • 可根据模块名设定所有模块日志的层级方便切换想看到的日志

  • 根据内容标记日志颜色

安装方法

go get github.com/davyxu/golog

使用方法

  • 基本使用

    var log *golog.Logger = golog.New("test")

    log.Debugln("hello world")

  • 层级设置

    golog.SetLevelByString( "test", "info")

备注

感觉不错请star, 谢谢!

开源讨论群: 527430600

知乎: http://www.zhihu.com/people/sunicdavy

Documentation

Overview

Package log implements a simple logging package. It defines a type, Logger, with methods for formatting output. It also has a predefined 'standard' Logger accessible through helper functions Print[f|ln], Fatal[f|ln], and Panic[f|ln], which are easier to use than creating a Logger manually. That logger writes to standard error and prints the date and time of each logged message. The Fatal functions call os.Exit(1) after writing the log message. The Panic functions call panic after writing the log message.

Index

Constants

View Source
const (
	// Bits or'ed together to control what's printed. There is no control over the
	// order they appear (the order listed here) or the format they present (as
	// described in the comments).  A colon appears after these items:
	//	2009/01/23 01:23:23.123123 /a/b/c/d.go:23: message
	Ldate         = 1 << iota     // the date: 2009/01/23
	Ltime                         // the time: 01:23:23
	Lmicroseconds                 // microsecond resolution: 01:23:23.123123.  assumes Ltime.
	Llongfile                     // full file name and line number: /a/b/c/d.go:23
	Lshortfile                    // final file name element and line number: d.go:23. overrides Llongfile
	LstdFlags     = Ldate | Ltime // initial values for the standard logger

)

These flags define which text to prefix to each log entry generated by the Logger.

Variables

View Source
var ErrLoggerNotFound = errors.New("logger not found")

Functions

func ClearAll

func ClearAll()

func EnableColorLogger

func EnableColorLogger(loggerName string, enable bool) error

func SetColorDefine

func SetColorDefine(loggerName string, jsonFormat string) error

func SetColorFile

func SetColorFile(loggerName string, colorFileName string) error

func SetLevelByString

func SetLevelByString(loggerName string, level string) error

通过字符串设置某一类日志的级别

func SetOutputLogger

func SetOutputLogger(loggerName string, filename string) error

func SetPanicLevelByString

func SetPanicLevelByString(loggerName string, level string) error

通过字符串设置某一类日志的崩溃级别

func VisitLogger

func VisitLogger(name string, callback func(*Logger) bool) error

Types

type Color

type Color int
const (
	NoColor Color = iota
	Black
	Red
	Green
	Yellow
	Blue
	Purple
	DarkGreen
	White
)

func ColorFromLevel

func ColorFromLevel(l Level) Color

type ColorFile

type ColorFile struct {
	Rule []*ColorMatch
}

func NewColorFile

func NewColorFile() *ColorFile

func (*ColorFile) ColorFromText

func (self *ColorFile) ColorFromText(text string) Color

func (*ColorFile) Load

func (self *ColorFile) Load(data string) error

type ColorMatch

type ColorMatch struct {
	Text  string
	Color string
	// contains filtered or unexported fields
}

type Level

type Level int
const (
	Level_Debug Level = iota
	Level_Info
	Level_Warn
	Level_Error
	Level_Fatal
)

type Logger

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

A Logger represents an active logging object that generates lines of output to an io.Writer. Each logging operation makes a single call to the Writer's Write method. A Logger can be used simultaneously from multiple goroutines; it guarantees to serialize access to the Writer.

func New

func New(name string) *Logger

func (*Logger) DebugColorf

func (self *Logger) DebugColorf(colorName string, format string, v ...interface{})

func (*Logger) DebugColorln

func (self *Logger) DebugColorln(colorName string, v ...interface{})

func (*Logger) Debugf

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

func (*Logger) Debugln

func (self *Logger) Debugln(v ...interface{})

func (*Logger) Errorf

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

func (*Logger) Errorln

func (self *Logger) Errorln(v ...interface{})

func (*Logger) Fatalf

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

func (*Logger) Fatalln

func (self *Logger) Fatalln(v ...interface{})

func (*Logger) Flag

func (self *Logger) Flag() int

func (*Logger) Infof

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

func (*Logger) Infoln

func (self *Logger) Infoln(v ...interface{})

func (*Logger) IsDebugEnabled

func (self *Logger) IsDebugEnabled() bool

func (*Logger) Level

func (self *Logger) Level() Level

func (*Logger) Log

func (self *Logger) Log(c Color, level Level, format string, v ...interface{})

func (*Logger) Output

func (self *Logger) Output(calldepth int, prefix string, text string, c Color, out io.Writer) error

Output writes the output for a logging event. The string s contains the text to print after the prefix specified by the flags of the Logger. A newline is appended if the last character of s is not already a newline. Calldepth is used to recover the PC and is provided for generality, although at the moment on all pre-defined paths it will be 2.

func (*Logger) SetColorFile

func (self *Logger) SetColorFile(file *ColorFile)

注意, 加色只能在Gogland的main方式启用, Test方式无法加色

func (*Logger) SetFlag

func (self *Logger) SetFlag(v int)

func (*Logger) SetLevel

func (self *Logger) SetLevel(lv Level)

func (*Logger) SetLevelByString

func (self *Logger) SetLevelByString(level string)

func (*Logger) SetPanicLevelByString

func (self *Logger) SetPanicLevelByString(level string)

func (*Logger) Warnf

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

func (*Logger) Warnln

func (self *Logger) Warnln(v ...interface{})

Jump to

Keyboard shortcuts

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