logging

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: MIT Imports: 6 Imported by: 0

README

logging

zerolog + file-rotatelogs 简单封装


package main

import (
	"github.com/rs/zerolog"
	"github.com/hookover/logging"
)

func init() {
	conf := &logging.Conf{DefaultLogFile: "./logs/app.log"}

	conf.Channels = append(conf.Channels,
		&logging.Channel{
			Name:    "sql",
			LogFile: "./logs/sql.log",
		},
		&logging.Channel{
			Name:    "console",
			Days:    3,
			Level:   zerolog.WarnLevel,
			LogFile: "./logs/console.log",
		},
	)

	if _, err := logging.Initialization(conf); err != nil {
		panic(err)
	}
}

func main() {
	logging.Info().Msg("test")
	logging.Chan("sql").Warn().Msg("sql warning")
	logging.Chan("console").Error().Msg("console error")
	logging.Chan("console").Debug().Msg("console debug")
}


日志文件

-rw-r--r--  1 hookover  staff    69B Oct 31 17:15 app-2019-10-31.log
-rw-r--r--  1 hookover  staff    79B Oct 31 17:15 console-2019-10-31.log
-rw-r--r--  1 hookover  staff    76B Oct 31 17:15 sql-2019-10-31.log

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Chan

func Chan(channel string) *zerolog.Logger

func Debug

func Debug() *zerolog.Event

func Error

func Error() *zerolog.Event

func Fatal

func Fatal() *zerolog.Event

func Hook

func Hook(h zerolog.Hook) zerolog.Logger

func Info

func Info() *zerolog.Event

func Level

func Level(lvl zerolog.Level) zerolog.Logger

func Log

func Log() *zerolog.Event

func Output

func Output(w io.Writer) zerolog.Logger

func Panic

func Panic() *zerolog.Event

func Printf

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

func Sample

func Sample(s zerolog.Sampler) zerolog.Logger

func UpdateContext

func UpdateContext(update func(c zerolog.Context) zerolog.Context)

func Warn

func Warn() *zerolog.Event

func With

func With() zerolog.Context

func WithLevel

func WithLevel(lvl zerolog.Level) *zerolog.Event

func Write

func Write(p []byte) (n int, err error)

Types

type Channel

type Channel struct {
	Name    string
	LogFile string
	Format  string
	Level   zerolog.Level
	Days    time.Duration
}

type Conf

type Conf struct {
	Channels       []*Channel
	DefaultLogFile string
}

type Logging

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

func Initialization

func Initialization(config *Conf) (*Logging, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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