interfaces

package
v1.0.1002 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2024 License: MIT Imports: 6 Imported by: 17

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":      `Directory 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":    `Compress the backup files (older than max age) in gzip format`,
	"log:sendToDataDog":    `Send every logs to datadog`,
	"log:logNoOfChunk":     `How to many logs send to exporter at once`,
	"log:logSendInterval":  `Time interval to send logs to exporter, in ms, default 200ms`,
	"log:datadogExporterContentEncoding": `datadog exporter content encoding, valid value is
		- gzip
		- deflate
		- identity
	`,
}

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 DatadogTraceLog

type DatadogTraceLog struct {
	ServiceName string
	TraceID     string
	SpanID      string
	Msg         any
	Key         string
	Level       LogLevel
	Env         string
	Caller      string
	Operation   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
	LogLevelFatal
)

type Logger

type Logger interface {
	// New - Clone logger instance
	New() Logger
	// Init - Deprecated, use InitWithConfig instead
	Init(namespace, version string)
	InitWithConfig(namespace, version string, config *LoggerConfig)
	// Close - Close logger instance, this will block until all log has been sent
	Close()
	// CloseWithTimeout - Close logger instance with timeout, this will block until all log has been sent
	CloseWithTimeout(timeout time.Duration)
	ServiceName() string
	ServiceVersion() string
	SetLogLevel(level DebugLevel)
	SetLogFile(*LoggingFile)
	GetLogLevel() (level DebugLevel)
	SetPrintToConsole(pr bool)
	GetPrintToConsole() (pr bool)
	SetOnLoggerHandler(f func(msg LoggerMessage, raw string))
	SetOutputFormat(OutputFormat)
	GetOutputFormat() OutputFormat
	ParsingLog(msg LoggerMessage) (raw string)
	SetSendToDatadog(send bool)
	SetLogNoOfChunk(cc int)
	SetLogSendInterval(cc int)
	SetDatadogExporterContentEncoding(en 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
	NewSystemLogger() *log.Logger
	Printf(string, ...interface{})
	Quit()
	// Clean - Clean logger instance, send interrupt signal to this group process
	Clean() Logger
	// Kill - Kill logger instance, send interrupt signal to this process
	Kill()
	// SendDataDogTraceLog - Send datadog trace log
	// DD_API_KEY and DD_SITE must be set
	SendDataDogTraceLog(data *DatadogTraceLog)
	// RunDatadogTraceLogExporter - Start datadog trace log exporter
	RunDatadogTraceLogExporter()
}

Logger modules interface, using for dynamic modules

type LoggerConfig

type LoggerConfig struct {
	Level                          string       `yaml:"level" default:"verbose" desc:"log:level" validate:"oneof=trace verbose info warning error"`
	Format                         string       `yaml:"format" default:"default" desc:"log:format" validate:"oneof=default json"`
	File                           *LoggingFile `yaml:"file"`
	SendToDataDog                  bool         `yaml:"sendToDataDog" desc:"log:sendToDataDog"`
	LogNoOfChunk                   int          `yaml:"logNoOfChunk" default:"10" desc:"log:logNoOfChunk" validate:"min=10,max=1000"`
	LogSendInterval                int          `yaml:"logSendInterval" default:"200" desc:"log:logSendInterval" validate:"min=100,max=3000"`
	DatadogExporterContentEncoding string       `` /* 136-byte string literal not displayed */
}

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"`
	Internal  bool        `json:"internal"`
}

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"  desc:"log:file:compress"`
}

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