log

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: MIT Imports: 6 Imported by: 5

README

log

Wraps zerolog so that it can be used in other projects.

How to use

go get -u github.com/jimyag/log

Other examples

package main

import "github.com/jimyag/log"

func main() {
 cfg := log.Config{
  Filename:   "sample.log",
  Level:      log.LevelDebug,
  MaxSize:    10,
  Compress:   false,
  LocalTime:  true,
  MaxBackups: 10,
  MaxAgeDays: 10,
 }
 log := log.NewLog(&cfg)
 log.Debug().Str("foo", "bar").Msg("debug")
 log.Info().Str("foo", "bar").Msg("info")
 log.Error().Str("foo", "bar").Msg("error")
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug added in v0.1.1

func Debug() *zerolog.Event

func Error added in v0.1.1

func Error(errs ...error) *zerolog.Event

func Info added in v0.1.1

func Info() *zerolog.Event

func Panic added in v0.1.1

func Panic(errs ...error) *zerolog.Event

func Warn added in v0.1.1

func Warn(errs ...error) *zerolog.Event

Types

type Config

type Config struct {
	Filename   string `toml:"filename"`     // 日志文件名
	Level      Level  `toml:"level"`        // 日志级别
	MaxSize    int    `toml:"max_size"`     // 单个日志文件的大小 MB
	MaxBackups int    `toml:"max_backups"`  // 保留的日志文件个数
	MaxAgeDays int    `toml:"max_age_days"` // 日志保留的最长时间: 天
	Compress   bool   `toml:"compress"`     // 是否压缩
	// 是否使用当前计算机的时间作为保存日志的名称
	// 默认使用UTC时间
	LocalTime bool `toml:"local_time"`
}

type Level

type Level int8
const (
	LevelDebug Level = iota
	LevelInfo
	LevelError
	LevelPanic
	LevelDisabled
)

type Log

type Log interface {
	Debug() *zerolog.Event
	Info() *zerolog.Event
	Error(...error) *zerolog.Event
	Panic(...error) *zerolog.Event
	RawLogger() *zerolog.Logger
}

func NewLog

func NewLog(cfg *Config) Log

func NewStdLog added in v0.1.1

func NewStdLog(l Level) Log

Directories

Path Synopsis
example
sample command

Jump to

Keyboard shortcuts

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