mlog

package module
v0.0.0-...-4d12e7f Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: MIT Imports: 7 Imported by: 5

README

mlog

log library with go, console、file、syslog3164(nlog) supported, this repo mainly depends on uber/zap

Installation

go get -u github.com/bsync-tech/mlog

Quick Start

    f := `name: fapp
        mode: console
        level: debug
        file_path: "./log"
        file_max_size: 128
        file_retain_days: 30
        file_max_backups: 30
        file_compress: true

        nlog_tag:
          debug: 5401
          info: 5402
          warn: 5403
          error: 5404
          default: 5401
        nlog_remote_addr: 192.168.64.113:5211`
        
    var c mlog.LogConfig
    err := yaml.Unmarshal(f, &c)
    if err != nil {
        panic(err)
    }
    
    mlog.Init(&c)
    defer mlog.Sync()
    
    mlog.Debug("debug msg")
    mlog.Info("info msg")
    mlog.Warn("warn msg")
    mlog.Error("error msg")

Released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DPanic

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

func Debug

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

func Error

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

func Fatal

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

func GetAtomicLevel

func GetAtomicLevel(level string) zap.AtomicLevel

func GetAtomicLevelEnableFuncEqual

func GetAtomicLevelEnableFuncEqual(level string) zap.LevelEnablerFunc

func GetLogger

func GetLogger() *zap.Logger

func Info

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

func Init

func Init(c *LogConfig)

func Panic

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

func Sync

func Sync()

func Warn

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

Types

type ConsoleLogger

type ConsoleLogger struct {
}

func (*ConsoleLogger) Init

type DflogLogger

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

func (*DflogLogger) Init

func (*DflogLogger) Write

func (d *DflogLogger) Write(p []byte) (int, error)

type FileLogger

type FileLogger struct {
}

func (*FileLogger) Init

type LogConfig

type LogConfig struct {
	// AppName
	Name string `yaml:"name" json:"name"`
	// console file nlog
	Mode string `yaml:"mode" json:"mode"`
	// debug info warn error
	Level string `yaml:"level" json:"level"`
	// file path
	FilePath string `yaml:"file_path" json:"file_path"`
	// file max size
	FileMaxSize int `yaml:"file_max_size" json:"file_max_size"`
	// file retain days
	FileRetainDays int `yaml:"file_retain_days" json:"file_retain_days"`
	// file max backups
	FileMaxBackups int `yaml:"file_max_backups" json:"file_max_backups"`
	// file compress
	FileCompress bool `yaml:"file_compress" json:"file_compress"`

	// nlog tags
	NlogTags map[string]string `yaml:"nlog_tag" json:"nlog_tag"`
	// nlog remote addr
	NlogRemoteAddr string `yaml:"nlog_remote_addr" json:"nlog_remote_addr"`

	DflogSubsys string `yaml:"dflog_subsys" json:"dflog_subsys"`

	DflogModule string `yaml:"dflog_module" json:"dflog_module"`

	DflogRemoteAddr string `yaml:"dflog_remote_addr" json:"dflog_remote_addr"`
}

type MLogger

type MLogger interface {
	Init(c *LogConfig) zapcore.WriteSyncer
}

type NlogLogger

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

func (*NlogLogger) Init

func (*NlogLogger) Write

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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