interfaces

package
v0.0.2-dev Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2022 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:file:enable":      `Enable writing log to file`,
	"log:hidetraceconsole": `Don't print trace log to console, if false, maybe performance impact`,
	"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`,
}

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 {
	// Create New Logger Object
	New() Logger
	// New Modules init
	// namespace is service name, and version is service version
	Init(namespace, version string)
	// Return Service name
	ServiceName() string
	// Return Service version
	ServiceVersion() string
	// Set Logging Level, see LogLevel options
	SetLogLevel(level DebugLevel)
	// Set Logging File
	SetLogFile(LoggingFile)
	// Get Current Log Level
	GetLogLevel() (level DebugLevel)
	// If true, will be print to console
	SetPrintToConsole(pr bool)
	// Get current value of print to console
	GetPrintToConsole() (pr bool)
	// Hooks on new incoming logger
	SetOnLoggerHandler(f func(msg LoggerMessage, raw string))
	// Set logger output format, default or json
	SetOutputFormat(OutputFormat)
	// Get current logger format
	GetOutputFormat() OutputFormat
	// Parsing logger message object to string format
	ParsingLog(msg LoggerMessage) (raw string)
	// Write byte to current io.writer
	Write(p []byte) (int, error)
	// Same format with fmt.Sprint
	Trace(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Debug(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Notice(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Info(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Warning(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Success(format interface{}, input ...interface{})
	// Same format with fmt.Sprint
	Error(format interface{}, input ...interface{}) Logger
	// Return New default system logger
	NewSystemLogger() *log.Logger
	// Same format with fmt.Sprint
	Printf(string, ...interface{})
	// Force Exit application
	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"`
	HideTraceConsole bool        `yaml:"hidetraceconsole" default:"false" desc:"log:hidetraceconsole"`
	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"`
}

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