interfaces

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2023 License: MIT Imports: 6 Imported by: 27

Documentation

Index

Constants

This section is empty.

Variables

View Source
var LoggerConfigManual = map[string]string{
	"log:level": `logging level, valid value is
		- trace
		- verbose
		- info
		- warning
		- error
	`,
	"log:format": `logging output format, valid value is
		- default
		- json
	`,
	"log:hideconsole":   `Don't print log to console`,
	"log:disablecolor":  `Don't use color in log`,
	"log:file:enable":   `Enable writing log to file`,
	"log:file:output":   `File log output location`,
	"log:file:maxsize":  `Max log file size (in megabytes) before retain`,
	"log:file:maxage":   `Max log file age (in days) before retain`,
	"log:file:compress": `If true, old file will be compressed`,
	"log:file:json":     `If true, always write in json format`,
}

Functions

func GetLogLevelPrintString

func GetLogLevelPrintString(level LogLevel) string

func GetLogLevelString

func GetLogLevelString(level LogLevel) string

func SetManual

func SetManual(man map[string]string) map[string]string

Types

type Caller

type Caller struct {
	File       string `json:"file"`
	Line       int    `json:"line"`
	Fname      string `json:"fname"`
	FnameShort string `json:"-"`
}

func GetCaller

func GetCaller(skip int) (cs Caller)

func (Caller) String

func (c Caller) String() string

type DebugLevel

type DebugLevel int
const (
	DebugLevelTrace DebugLevel = iota + 1
	DebugLevelVerbose
	DebugLevelInfo
	DebugLevelWarning
	DebugLevelError
)

func GetDebugLevelFromString

func GetDebugLevelFromString(level string) DebugLevel

type LogLevel

type LogLevel int
const (
	LogLevelTrace LogLevel = iota + 1
	LogLevelDebug
	LogLevelNotice
	LogLevelInfo
	LogLevelWarning
	LogLevelError
	LogLevelSuccess
)

type Logger

type Logger interface {
	New() Logger
	Init(namespace, version string)
	ServiceName() string
	ServiceVersion() string
	SetLogLevel(level DebugLevel)
	SetLogFile(LoggingFile)
	GetLogLevel() (level DebugLevel)
	SetPrintToConsole(pr bool)
	GetPrintToConsole() (pr bool)
	DisableColor(val bool)
	SetOnLoggerHandler(f func(msg LoggerMessage, raw string))
	SetOutputFormat(OutputFormat)
	GetOutputFormat() OutputFormat
	ParsingLog(msg LoggerMessage) (raw string)
	Write(p []byte) (int, error)
	Trace(format interface{}, input ...interface{})
	Debug(format interface{}, input ...interface{})
	Notice(format interface{}, input ...interface{})
	Info(format interface{}, input ...interface{})
	Warning(format interface{}, input ...interface{})
	Success(format interface{}, input ...interface{})
	Error(format interface{}, input ...interface{}) Logger
	Debugf(format string, input ...interface{})
	Errorf(format string, input ...interface{})
	Infof(format string, input ...interface{})
	Warnf(format string, input ...interface{})
	NewSystemLogger() *log.Logger
	Printf(string, ...interface{})
	Quit()
}

Logger modules interface, using for dynamic modules

type LoggerConfig

type LoggerConfig struct {
	Level        string      `yaml:"level" default:"verbose" desc:"log:level"`
	Format       string      `yaml:"format" default:"default" desc:"log:format"`
	HideConsole  bool        `yaml:"hideconsole" default:"false" desc:"log:hideconsole"`
	DisableColor bool        `yaml:"disablecolor" default:"false" desc:"log:disablecolor"`
	File         LoggingFile `yaml:"file"`
}

type LoggerMessage

type LoggerMessage struct {
	ID        string      `json:"id"`
	Level     LogLevel    `json:"level"`
	LevelName string      `json:"levelName"`
	File      string      `json:"file"`
	Line      int         `json:"line"`
	FuncName  string      `json:"funcName"`
	Time      time.Time   `json:"time"`
	Message   interface{} `json:"message"`
}

type LoggingFile

type LoggingFile struct {
	Enable   bool   `yaml:"enable" default:"false" desc:"log:file:enable"`
	Output   string `yaml:"output" default:"./logs/app.log" desc:"log:file:output"`
	MaxSize  int    `yaml:"maxsize" default:"100" desc:"log:file:maxsize"`
	MaxAge   int    `yaml:"maxage" default:"28" desc:"log:file:maxage"`
	Compress bool   `yaml:"compress" default:"false" desc:"log:file:compress"`
	Json     bool   `yaml:"json" default:"false" desc:"log:file:json"`
}

type OutputFormat

type OutputFormat int
const (
	OutputFormatDefault OutputFormat = iota + 1
	OutputFormatJSON
)

func GetOutputFormatFromString

func GetOutputFormatFromString(op string) OutputFormat

Jump to

Keyboard shortcuts

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