midlog

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: MIT Imports: 14 Imported by: 9

README

Midlog

GoDoc Build Status codecov Go Report Card

Midlog is a general log framework used in golang, similar to slf4j in Java. You can switch any other logging module without modifying the third-party code,For example : logrus, zap,zerolog,seelog.

midlog framework

Usage

To link : Examples

Languages

Chinese

Documentation

Overview

Package midlog is a log library with middle ware,you can kind log from midlog to different files.

Index

Constants

View Source
const FormatDefault = "$time_local $module $level $ext $msg"

FormatDefault is a recommend fields log format expression

View Source
const FormatJsonFull = "json($time_local,$module,$level,$file,$line,$ext,$msg)"

FormatJsonFull is a full fields json log format expression

View Source
const FormatTextFull = "$time_local $module $level $file:$line $ext $msg"

FormatTextFull is a full fields text log format expression

View Source
const LocalTimeFormat = "2006-01-02 15:04:05"

LocalTimeFormat is a time format expression with 2006-01-02 15:04:05

Variables

This section is empty.

Functions

func CommonFormatField added in v0.2.0

func CommonFormatField(val *interface{})

CommonFormatField is a common format parameter with write log methods

func CommonFormatFields added in v0.2.0

func CommonFormatFields(vals []interface{})

CommonFormatFields is a common format parameters with write log methods

func GetIsRecordCaller added in v0.2.0

func GetIsRecordCaller() bool

GetIsRecordCaller is a function with get configuration with isRecordCaller

func LevelName

func LevelName(level LogLevel) string

LevelName get name string with level code

func SetCustomStdWriter added in v0.3.1

func SetCustomStdWriter(exp string)

SetCustomStdWriter set Writer to midlog with expression

func SetIsRecordCaller added in v0.2.0

func SetIsRecordCaller(val bool)

SetIsRecordCaller is a function with set configuration with isRecordCaller

func SetLevelPower added in v0.2.0

func SetLevelPower(level LogLevel)

SetLevelPower is set powerLevel to filter log

func SetWriter added in v0.3.1

func SetWriter(newWriter LogWriter)

SetWriter is a method with set a new writer to global midlog

Types

type Caller

type Caller struct {
	File string
	Line int
}

Caller is a struct with a invoke stack information

func NewCaller

func NewCaller(file string, line int) *Caller

NewCaller is a function to make a Caller object

type ExtMap added in v0.2.0

type ExtMap map[string]interface{}

ExtMap is a map with map[string]interface{}

type LogFormater added in v0.2.0

type LogFormater interface {
	//init with expression
	Init(exp string) error
	//Format log info with byte array
	Format(module string, level LogLevel, caller *Caller, ext ExtMap, msg ...interface{}) ([]byte, error)
}

LogFormater is a interface with log format

func NewFormater

func NewFormater(exp string) (LogFormater, error)

NewFormater is a funnction to make a LogFormat object with expression

type LogLevel added in v0.2.0

type LogLevel int32

LogLevel is type with int32

const (
	//LevelTrace is a const enums with trace log level
	LevelTrace LogLevel = iota + 1
	//LevelDebug is a const enums with debug log level
	LevelDebug
	//LevelInfo is a const enums with information log level
	LevelInfo
	//LevelRootLog is a const enums with native golang log level
	LevelRootLog
	//LevelWarn is a const enums with warn log level
	LevelWarn LogLevel = 101
	//LevelError1 is a const enums with error log level 1
	LevelError1 LogLevel = 201
	//LevelError2 is a const enums with error log level 2
	LevelError2 LogLevel = 202
	//LevelError3 is a const enums with error log level 3
	LevelError3 LogLevel = 203
)

func GetLevelPower added in v0.2.0

func GetLevelPower() LogLevel

func (LogLevel) Code added in v0.2.0

func (l LogLevel) Code() int32

Code to get code for levelInfo

type LogWriter

type LogWriter interface {
	//Write is a method, invoked when write log
	Write(logger Midlog, level LogLevel, caller *Caller, pams ...interface{})
}

LogWriter is a interface with write log

func GetDefaultWriter added in v0.2.0

func GetDefaultWriter() LogWriter

GetDefaultWriter is get default writer object

type Midlog

type Midlog interface {
	//Ext is a method with write Object with log
	Ext(ext ExtMap) Midlog
	//GetExt is a method with get ext object
	GetExt() ExtMap
	//GetModule is a method with get Module name with logger
	GetModule() string
	//Info is a method with write a log with info level
	Info(pams ...interface{})
	//Trace is a method with write a log with trace level
	Trace(pams ...interface{})
	//Debug is a method with write a log with debug level
	Debug(pams ...interface{})
	//Error1 is a method with write a log with error1 level
	Error1(pams ...interface{})
	//Error2 is a method with write a log with error2 level
	Error2(pams ...interface{})
	//Error3 is a method with write a log with error3 level
	Error3(pams ...interface{})
	//Warn is a method with write a log with warn level
	Warn(pams ...interface{})
	//InfoF is a method with write a log with info level and format with msgExp
	Infof(msgExp string, pams ...interface{})
	//TraceF is a method with write a log with trace level and format with msgExp
	Tracef(msgExp string, pams ...interface{})
	//DebugF is a method with write a log with debug level and format with msgExp
	Debugf(msgExp string, pams ...interface{})
	//Error1F is a method with write a log with error1 level and format with msgExp
	Error1f(msgExp string, pams ...interface{})
	//Error2F is a method with write a log with error2 level and format with msgExp
	Error2f(msgExp string, pams ...interface{})
	//Error3F is a method with write a log with error3 level and format with msgExp
	Error3f(msgExp string, pams ...interface{})
	//WarnF is a method with write a log with warn level and format with msgExp
	Warnf(msgExp string, pams ...interface{})
	//LogF is a method with write a log with parameter level and format with msgExp
	Logf(level LogLevel, msgExp string, pams ...interface{})
	//Log is a method with write a log with parameter level
	Log(level LogLevel, pams ...interface{})
}

Midlog is a interface with write log

func New

func New(module string) Midlog

New is function with get Midlog instance

Directories

Path Synopsis
test module

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳