Help us shape the future of Go! Take the 2026 Go Developer Survey

logger

package module
v1.1.8 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2019 License: MIT Imports: 12 Imported by: 0

README

Logger

Build Status codecov Go Report Card
GoDoc

Golang logger,Integrate logrus and sentry,support logroate

Default logger

default log out to os.Stderr

import "github.com/verystar/logger"

func main(){
    logger.Debug("debug printer %s","hehe")
    logger.Fatal("exit")
}

Setting default logger

logger.Setting(func(c *logger.Config) {
    c.LogMode = "file"
    c.LogLevel = "info"
    c.LogMaxFiles = 15  //store for up to 15 days
    c.LogPath = "/tmp/logs/"
    c.LogSentryDSN = ""
    c.LogSentryType = ""
    c.LogDetail = true
})

New logger

log := logger.NewLogger(func(c *logger.Config) {
    c.LogMode = "file"
    c.LogLevel = "info"
    c.LogMaxFiles = 15  //store for up to 15 days
    c.LogPath = "/tmp/logs/"
    c.LogSentryDSN = ""
    c.LogSentryType = ""
})

log.Debug("this is new log")

Print filename and line no

if LogDetail is true,the log data add filename and line no

{"file":"/Users/fifsky/wwwroot/go/library/src/github.com/fifsky/goblog/handler/index.go","func":"handler.IndexGet","level":"debug","line":16,"msg":"[test]","time":"2018-08-02 22:37:02"}

Log Data

logger.Data(map[string]interface{}{
		"id":   1,
		"name": "test",
	}).Info("[CURL ERROR]", "123123")
{"data":{"id":1,"name":"test"},"level":"info","msg":"[CURL ERROR]123123","time":"2019-01-18 17:05:17"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHook added in v1.0.5

func AddHook(hook logrus.Hook)

func Debug

func Debug(args ...interface{})

func Debugf

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

func Error

func Error(args ...interface{})

func Errorf

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

func Fatal

func Fatal(args ...interface{})

func Fatalf

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

func Info

func Info(args ...interface{})

func Infof

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

func Setting

func Setting(option func(*Config))

func Trace added in v1.0.2

func Trace(args ...interface{})

func Tracef added in v1.0.2

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

func Warn

func Warn(args ...interface{})

func Warnf

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

Types

type Config

type Config struct {
	LogName       string `toml:"log_name" json:"log_name"`
	LogFormat     string `toml:"log_format" json:"log_format"`
	LogPath       string `toml:"log_path" json:"log_path"`
	LogMode       string `toml:"log_mode" json:"log_mode"`
	LogLevel      string `toml:"log_level" json:"log_level"`
	LogDetail     bool   `toml:"log_detail" json:"log_detail"`
	LogMaxFiles   int    `toml:"log_max_files" json:"log_max_files"`
	LogSentryDSN  string `toml:"log_sentry_dsn" json:"log_sentry_dsn"`
	LogSentryType string `toml:"log_sentry_type" json:"log_sentry_type"`
	LogRotate     ILoggerRotate
	LogWriter     io.Writer
}

type FileHook

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

FileHook to send logs via syslog.

func NewFileHook

func NewFileHook(conf *Config) (*FileHook, error)

func (*FileHook) Fire

func (h *FileHook) Fire(entry *logrus.Entry) error

func (*FileHook) Levels

func (h *FileHook) Levels() []logrus.Level

type IBaseLogger added in v1.0.5

type IBaseLogger interface {
	Fatalf(string, ...interface{})
	Debugf(string, ...interface{})
	Infof(string, ...interface{})
	Warnf(string, ...interface{})
	Errorf(string, ...interface{})
	Tracef(string, ...interface{})
	Fatal(...interface{})
	Debug(...interface{})
	Info(...interface{})
	Warn(...interface{})
	Error(...interface{})
	Trace(...interface{})
}

ILogger is the logger interface

func Data added in v1.1.4

func Data(v interface{}) IBaseLogger

func WithFields added in v1.1.0

func WithFields(fields map[string]interface{}) IBaseLogger

type ILogger

type ILogger interface {
	IBaseLogger
	AddHook(hook logrus.Hook)
	WithFields(map[string]interface{}) IBaseLogger
	Data(interface{}) IBaseLogger
}

ILogger is the logger interface

func NewLogger

func NewLogger(options ...func(*Config)) ILogger

func NewLogrusLogger

func NewLogrusLogger(option func(l *LogrusLogger)) ILogger

NewFileLogger providers a file logger based on logrus

type ILoggerRotate added in v1.1.0

type ILoggerRotate interface {
	Current() string
	Prev(n int) string
}

type LineHook

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

func NewLineHook

func NewLineHook(conf *Config) (*LineHook, error)

func (*LineHook) Fire

func (h *LineHook) Fire(entry *logrus.Entry) error

func (*LineHook) Levels

func (h *LineHook) Levels() []logrus.Level

type LoggerRotate added in v1.1.0

type LoggerRotate struct{}

func (*LoggerRotate) Current added in v1.1.0

func (r *LoggerRotate) Current() string

func (*LoggerRotate) Prev added in v1.1.0

func (r *LoggerRotate) Prev(n int) string

type LogrusLogger

type LogrusLogger struct {
	*logrus.Logger
	Fingerprint bool
}

LogrusLogger file logger

func (*LogrusLogger) AddHook added in v1.0.5

func (l *LogrusLogger) AddHook(hook logrus.Hook)

func (*LogrusLogger) Data added in v1.1.4

func (l *LogrusLogger) Data(v interface{}) IBaseLogger

func (*LogrusLogger) Debug

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

func (*LogrusLogger) Debugf

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

func (*LogrusLogger) Error

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

func (*LogrusLogger) Errorf

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

func (*LogrusLogger) Fatal

func (l *LogrusLogger) Fatal(args ...interface{})

func (*LogrusLogger) Fatalf

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

func (*LogrusLogger) Info

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

func (*LogrusLogger) Infof

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

func (*LogrusLogger) Trace added in v1.0.2

func (l *LogrusLogger) Trace(args ...interface{})

func (*LogrusLogger) Tracef added in v1.0.2

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

func (*LogrusLogger) Warn

func (l *LogrusLogger) Warn(args ...interface{})

func (*LogrusLogger) Warnf

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

func (*LogrusLogger) WithFields added in v1.1.0

func (l *LogrusLogger) WithFields(fields map[string]interface{}) IBaseLogger

Jump to

Keyboard shortcuts

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