log

package module
v0.0.0-...-28566f3 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: MIT Imports: 9 Imported by: 0

README

log

logger module based on uber zap

USAGE

package main

import (
	"github.com/nectarian/log"
	"go.uber.org/zap"
)

func main() {
	log.Debug("Go", zap.Int("id", 1))
	log.Info("Go", zap.Int("id", 2))
	log.Warn("Go", zap.Int("id", 3))
	log.Error("Go", zap.Int("id", 4))
	log.Fatal("Go", zap.Int("id", 5))
	// log.DPanic("Go")
	// log.Panic("Go")
}

package log will read logger.toml file in current folder , create and initialize zap logger. default config will be used if logger.toml does not exsist.

log.Config property

  • Level : Main logger level, Can be one of : debug, info, warn, error, dpanic, panic, fatal. Case insensitive, default : INFO
  • Output.File : Whether to output to fil? default : false
  • Output.FilePath : File path for output to file, default : /tmp/$APP_NAME.log
  • Output.MaxSize : Log file max size, Unit : MB, default : 10
  • Output.MaxBackups : How many copies can be stored in the archive, default : 30
  • Output.MaxAge : How many days the archive can be kept at most, default : 7
  • Output.Compress : Compressed the archive or not , default : false
  • Output.Console : Whether to output to the console? Fix function will change this value as true if File is false, default : true
  • Context.Format : log format, can be one of : json, console. default : console
  • Context.Fileds : additional fields, type : map[string]string, default : nil
  • Context.Caller : whether to record the caller file name and line number, default : true

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

func DPanic(msg string, fields ...zapcore.Field)

DPanic call main logger DPanic function

func Debug

func Debug(msg string, fields ...zapcore.Field)

Debug call main logger Debug function

func Error

func Error(msg string, fields ...zapcore.Field)

Error call main logger Error function

func Fatal

func Fatal(msg string, fields ...zapcore.Field)

Fatal call main logger Fatal function

func Info

func Info(msg string, fields ...zapcore.Field)

Info call main logger Info function

func InitLogger

func InitLogger(conf Config) *zap.Logger

InitLogger initialize main logger

func Panic

func Panic(msg string, fields ...zapcore.Field)

Panic call main logger Panic function

func Sync

func Sync() error

Sync logger sync

func Warn

func Warn(msg string, fields ...zapcore.Field)

Warn call main logger Warn function

Types

type Config

type Config struct {
	Level   string      `mapstructure:"level" json:"level" yaml:"level" toml:"level"`
	Context LineContext `mapstructure:"context" json:"context" yaml:"context" toml:"context"`
	Output  Output      `mapstructure:"output" json:"output" yaml:"output" toml:"output"`
}

Config logger config

func (*Config) Default

func (conf *Config) Default()

Default make config default

func (*Config) Fix

func (conf *Config) Fix()

Fix validate and fix config

type LineContext

type LineContext struct {
	Format     string            `mapstructure:"format" json:"format" yaml:"format" toml:"format"`
	Fileds     map[string]string `mapstructure:"fileds" json:"fileds" yaml:"fileds" toml:"fileds"`
	ShowCaller bool              `mapstructure:"show_caller" json:"show_caller" yaml:"show_caller" toml:"show_caller"`
}

LineContext log context config

type Output

type Output struct {
	File       bool   `mapstructure:"file" json:"file" yaml:"file" toml:"file"`
	FilePath   string `mapstructure:"file_path" json:"file_path" yaml:"file_path" toml:"file_path"`
	MaxSize    int    `mapstructure:"max_size" json:"max_size" yaml:"max_size" toml:"max_size"`
	MaxBackups int    `mapstructure:"max_backups" json:"max_backups" yaml:"max_backups" toml:"max_backups"`
	MaxAge     int    `mapstructure:"max_age" json:"max_age" yaml:"max_age" toml:"max_age"`
	Compress   bool   `mapstructure:"compress" json:"compress" yaml:"compress" toml:"compress"`
	Console    bool   `mapstructure:"console" json:"console" yaml:"console" toml:"console"`
}

Output log output config

Jump to

Keyboard shortcuts

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