log

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2022 License: MIT Imports: 11 Imported by: 1

README

llog

log dependent on logrus and file-rotatelogs

Example

  • console output
import (
	log "github.com/shenjing023/llog"
)

func main(){
    log.SetConsoleLogger(
		log.WithCaller(true),
		log.WithLevel(log.TraceLevel),
	)
    log.Debug("调试信息")
	log.Info("提示信息")
	log.Warn("警告信息")
	log.Error("错误信息")
	log.WithField("key", "value").Warn("warn message")
	log.WithFields(log.Fields{
		"a": "b",
		"c": 1,
	}).Info("xxxxxxxxxxxxxxx")
}

20210106233252.png

import (
	log "github.com/shenjing023/llog"
)

func main(){
    log.SetConsoleLogger(
		log.WithLevel(log.TraceLevel),
        log.WithJSON(true),
	)
    log.Debug("调试信息")
	log.Info("提示信息")
	log.Warn("警告信息")
	log.Error("错误信息")
	log.WithField("key", "value").Warn("warn message")
	log.WithFields(log.Fields{
		"a": "b",
		"c": 1,
	}).Info("xxxxxxxxxxxxxxx")
}
{"level":"debug","msg":"调试信息","time":"2021/01/06 23:36:14.730"}
{"level":"info","msg":"提示信息","time":"2021/01/06 23:36:14.731"}
{"level":"warning","msg":"警告信息","time":"2021/01/06 23:36:14.731"}
{"level":"error","msg":"错误信息","time":"2021/01/06 23:36:14.731"}
{"key":"value","level":"warning","msg":"warn message","time":"2021/01/06 23:36:14.731"}
{"a":"b","c":1,"level":"info","msg":"xxxxxxxxxxxxxxx","time":"2021/01/06 23:36:14.731"}
  • file output
package main

import (
	log "github.com/shenjing023/llog"
)

func main() {
	if err := log.SetFileLogger(
		"test.log"+"-%Y%m%d%H%M",
		log.WithCaller(true),
		log.WithMaxAge(30*time.Second),
		log.WithRotationTime(time.Second*10),
		log.WithJSON(true),
		log.WithPrettyPrint(true),
	); err != nil {
		fmt.Errorf("init log error %v", err)
		return
	}

	log.Debug("调试信息")
	log.Info("提示信息")
	log.Warn("警告信息")
	log.Error("错误信息")
	log.WithField("key", "value").Warn("warn message")
	log.WithFields(log.Fields{
		"a": "b",
		"c": 1,
	}).Info("xxxxxxxxxxxxxxx")
}

Thanks

  • nested-logrus-formatter
  • beego log

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug logs a message at level Debug on the standard logger.

func Debugf

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

Debugf logs a message at level Debug on the standard logger.

func Debugln

func Debugln(args ...interface{})

Debugln logs a message at level Debug on the standard logger.

func Error

func Error(args ...interface{})

Error logs a message at level Error on the standard logger.

func Errorf

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

Errorf logs a message at level Error on the standard logger.

func Errorln

func Errorln(args ...interface{})

Errorln logs a message at level Error on the standard logger.

func Fatal

func Fatal(args ...interface{})

Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Fatalf

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

Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Fatalln

func Fatalln(args ...interface{})

Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.

func Info

func Info(args ...interface{})

Info logs a message at level Info on the standard logger.

func Infof

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

Infof logs a message at level Info on the standard logger.

func Infoln

func Infoln(args ...interface{})

Infoln logs a message at level Info on the standard logger.

func Panic

func Panic(args ...interface{})

Panic logs a message at level Panic on the standard logger.

func Panicf

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

Panicf logs a message at level Panic on the standard logger.

func Panicln

func Panicln(args ...interface{})

Panicln logs a message at level Panic on the standard logger.

func Print

func Print(args ...interface{})

Print logs a message at level Info on the standard logger.

func Printf

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

Printf logs a message at level Info on the standard logger.

func Println

func Println(args ...interface{})

Println logs a message at level Info on the standard logger.

func SetConsoleLogger

func SetConsoleLogger(opts ...Option)

SetConsoleLogger set console option

func SetFileLogger

func SetFileLogger(format string, opts ...Option) (err error)

SetFileLogger set file log option

func SetLevel added in v0.1.4

func SetLevel(l Level)

func Trace

func Trace(args ...interface{})

Trace logs a message at level Trace on the standard logger.

func Tracef

func Tracef(format string, args ...interface{})

Tracef logs a message at level Trace on the standard logger.

func Traceln

func Traceln(args ...interface{})

Traceln logs a message at level Trace on the standard logger.

func Warn

func Warn(args ...interface{})

Warn logs a message at level Warn on the standard logger.

func Warnf

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

Warnf logs a message at level Warn on the standard logger.

func Warning

func Warning(args ...interface{})

Warning logs a message at level Warn on the standard logger.

func Warningf

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

Warningf logs a message at level Warn on the standard logger.

func Warningln

func Warningln(args ...interface{})

Warningln logs a message at level Warn on the standard logger.

func Warnln

func Warnln(args ...interface{})

Warnln logs a message at level Warn on the standard logger.

func WithField

func WithField(key string, value interface{}) *logrus.Entry

WithField creates an entry from the standard logger and adds a field to it. If you want multiple fields, use `WithFields`.

Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.

func WithFields

func WithFields(fields Fields) *logrus.Entry

WithFields creates an entry from the standard logger and adds multiple fields to it. This is simply a helper for `WithField`, invoking it once for each field.

Note that it doesn't log until you call Debug, Print, Info, Warn, Fatal or Panic on the Entry it returns.

Types

type Fields

type Fields map[string]interface{}

Fields type, used to pass to `WithFields`.

type Formatter

type Formatter struct {
	JSONFormat        bool
	DisableColors     bool
	DisableHTMLEscape bool
	PrettyPrint       bool
}

Formatter - logrus formatter, implements logrus.Formatter

func (*Formatter) Format

func (f *Formatter) Format(entry *logrus.Entry) ([]byte, error)

Format an log entry

type Level

type Level uint32

Level from logrus Level

const (
	PanicLevel Level = iota

	FatalLevel

	ErrorLevel

	WarnLevel

	InfoLevel

	DebugLevel

	TraceLevel
)

type Option

type Option func(o *options)

func WithCaller

func WithCaller(include bool) Option

WithCaller set logrus.SetReportCaller

func WithColor

func WithColor(b bool) Option

WithColor set formatter output color

func WithConsole added in v0.1.3

func WithConsole(b bool) Option

WithConsole set formatter output to console

func WithHTMLEscape

func WithHTMLEscape(b bool) Option

WithHTMLEscape set formatter output color

func WithJSON

func WithJSON(b bool) Option

WithJSON set formatter output color

func WithLevel

func WithLevel(l Level) Option

WithLevel set log level

func WithMaxAge

func WithMaxAge(d time.Duration) Option

WithMaxAge 设置文件清理前的最长保存时间

func WithPrettyPrint

func WithPrettyPrint(b bool) Option

WithPrettyPrint set formatter output color

func WithRotationTime

func WithRotationTime(d time.Duration) Option

WithRotationTime 设置日志分割的时间,隔多久分割一次

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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