logging

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MIT Imports: 13 Imported by: 8

Documentation

Index

Constants

View Source
const ModuleId = "machbase.com/neo-logging"

Variables

View Source
var PresetConfigDiscard = Config{
	Console:                     false,
	Filename:                    ".",
	Append:                      false,
	DefaultPrefixWidth:          30,
	DefaultEnableSourceLocation: true,
	DefaultLevel:                "TRACE",
}
View Source
var PresetConfigStdout = Config{
	Console:                     false,
	Filename:                    "-",
	Append:                      true,
	DefaultPrefixWidth:          30,
	DefaultEnableSourceLocation: true,
	DefaultLevel:                "TRACE",
}

Functions

func Configure

func Configure(cfg *Config)

func DefaultPrefixWidth

func DefaultPrefixWidth() int

func LogLevelName

func LogLevelName(level Level) string

func RegisterBootFactory

func RegisterBootFactory()

func SetDefaultEnableSourceLocation

func SetDefaultEnableSourceLocation(flag bool)

func SetDefaultLevel

func SetDefaultLevel(lvl Level)

func SetDefaultPrefixWidth

func SetDefaultPrefixWidth(width int)

func SetLevel

func SetLevel(name string, lvl Level)

func StringToLogLevelHookFunc

func StringToLogLevelHookFunc(f reflect.Type, t reflect.Type, data any) (any, error)

Types

type Config

type Config struct {
	Console                     bool          `json:"console" default:"true" help:"enable console output"`
	Filename                    string        `json:"filename" placeholder:"<path>" help:"log file path"`
	Append                      bool          `json:"append" help:"append to existing log file"`
	RotateSchedule              string        `json:"rotateSchedule" help:"schedule to roate log file"`
	MaxSize                     int           `json:"maxSize" help:"log file max size in MB"`
	MaxBackups                  int           `json:"maxBackups" help:"number of backup files"`
	MaxAge                      int           `json:"maxAge" help:"how many days keep backup files"`
	Compress                    bool          `json:"compress" placeholder:"true|false" default:"false" help:"compress backup files"`
	Levels                      []LevelConfig `json:"levels" hidden:""`
	UTC                         bool          `json:"utc" help:"log time format in UTC"`
	DefaultPrefixWidth          int           `json:"defaultPrefixWidth" default:"20" hidden:""`
	DefaultEnableSourceLocation bool          `json:"defaultEnableSourceLocation" default:"false" hidden:""`
	DefaultLevel                string        `json:"defaultLevel"  enum:"TRACE,DEBUG,INFO,WARN,ERROR" default:"INFO" help:"TRACE,DEBUG,INFO,WARN,ERROR"`
}

type Level

type Level int
const (
	LevelAll Level = iota
	LevelTrace
	LevelDebug
	LevelInfo
	LevelWarn
	LevelError
)

func DefaultLevel

func DefaultLevel() Level

func GetLevel

func GetLevel(name string) Level

func ParseLogLevel

func ParseLogLevel(name string) Level

func ParseLogLevelP

func ParseLogLevelP(name string) (Level, bool)

func (*Level) UnmarshalJSON

func (lvl *Level) UnmarshalJSON(b []byte) error

type LevelConfig

type LevelConfig struct {
	Pattern              string `json:"pattern"`
	Level                string `json:"level" enum:"TRACE,DEBUG,INFO,WARN,ERROR" default:"INFO"`
	EnableSourceLocation bool   `json:"enableSourceLocation"`
}

type Log

type Log interface {
	io.Writer

	TraceEnabled() bool
	Trace(...any)
	Tracef(format string, args ...any)
	DebugEnabled() bool
	Debug(...any)
	Debugf(format string, args ...any)
	InfoEnabled() bool
	Info(...any)
	Infof(format string, args ...any)
	WarnEnabled() bool
	Warn(...any)
	Warnf(format string, args ...any)
	ErrorEnabled() bool
	Error(...any)
	Errorf(format string, args ...any)

	LogEnabled(level Level) bool

	Log(level Level, m ...any)
	Logf(level Level, format string, args ...any)
	LogWithSkipCallstack(lvl Level, skip int, m ...any)
	LogfWithSkipCallstack(lvl Level, skip int, format string, args ...any)

	SetLevel(level Level)
	Level() Level
}

func GetLog

func GetLog(name string) Log

func NewLog

func NewLog(name string, writer io.Writer) Log

func NewLogFile

func NewLogFile(name string, cfg LogFileConf) Log

type LogFileConf

type LogFileConf struct {
	Filename             string
	Level                string
	MaxSize              int
	MaxBackups           int
	MaxAge               int
	Compress             bool
	Append               bool
	RotateSchedule       string
	Console              bool
	PrefixWidth          int
	EnableSourceLocation bool
	LogServer            LogServerConfig
}

type LogServerConfig

type LogServerConfig struct {
	Address string
	Labels  map[string]string
}

type Module

type Module struct {
}

func (*Module) Start

func (m *Module) Start() error

func (*Module) Stop

func (m *Module) Stop()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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