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

logger

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 9 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"}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 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"`
	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"`
}

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 ILogger

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

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 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 LogrusLogger

type LogrusLogger struct {
	*logrus.Logger
	Fingerprint bool
}

LogrusLogger file logger

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) Warn

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

func (*LogrusLogger) Warnf

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

Jump to

Keyboard shortcuts

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