Documentation
¶
Overview ¶
Package logs provides the low-level routines for directing log messages. It creates several logging channels for debug, info, errors, http, etc. These channels are directed to log files and/or stdout depending on how the application is configured. This package reads its configuration directly from a config file. In here you will find the log rotation config for rotatorr, panic redirection, and external logging methods.
Index ¶
- Variables
- type FileMode
- type LogConfig
- type LogFileInfo
- type LogFileInfos
- type Logger
- func (l *Logger) CapturePanic()
- func (l *Logger) Close() []error
- func (l *Logger) Debug(reqID string, v ...any)
- func (l *Logger) DebugEnabled() bool
- func (l *Logger) Debugf(reqID string, msg string, v ...any)
- func (l *Logger) Error(reqID string, v ...any)
- func (l *Logger) Errorf(reqID string, msg string, v ...any)
- func (l *Logger) ErrorfNoShare(reqID string, msg string, v ...any)
- func (l *Logger) GetAllLogFilePaths() *LogFileInfos
- func (l *Logger) GetDebugLog() *log.Logger
- func (l *Logger) GetErrorLog() *log.Logger
- func (l *Logger) GetInfoLog() *log.Logger
- func (l *Logger) GetLogFiles() map[string]string
- func (l *Logger) NoUploads() bool
- func (l *Logger) Print(reqID string, v ...any)
- func (l *Logger) Printf(reqID string, msg string, v ...any)
- func (l *Logger) Rotate() []error
- func (l *Logger) SetupLogging(config LogConfig)
- func (l *Logger) Trace(reqID string, msg ...any) string
Constants ¶
This section is empty.
Variables ¶
var (
ErrCloseCustom = errors.New("cannot close custom logs directly")
)
Custom errors.
var Log = New()
Functions ¶
This section is empty.
Types ¶
type FileMode ¶ added in v0.1.14
FileMode is used to unmarshal a unix file mode from the config file.
func (FileMode) MarshalText ¶ added in v0.3.0
MarshalText satisfies an encoder.TextMarshaler interface.
func (*FileMode) UnmarshalText ¶ added in v0.1.14
UnmarshalText turns a unix file mode, wrapped in quotes or not, into a usable os.FileMode.
type LogConfig ¶ added in v0.1.6
type LogConfig struct {
AppName string `json:"-" toml:"-" xml:"-" yaml:"-"`
LogFile string `json:"logFile" toml:"log_file" xml:"log_file" yaml:"logFile"`
DebugLog string `json:"debugLog" toml:"debug_log" xml:"debug_log" yaml:"debugLog"`
HTTPLog string `json:"httpLog" toml:"http_log" xml:"http_log" yaml:"httpLog"`
LogFiles int `json:"logFiles" toml:"log_files" xml:"log_files" yaml:"logFiles"`
LogFileMb int `json:"logFileMb" toml:"log_file_mb" xml:"log_file_mb" yaml:"logFileMb"`
FileMode FileMode `json:"fileMode" toml:"file_mode" xml:"file_mode" yaml:"fileMode"`
Debug bool `json:"debug" toml:"debug" xml:"debug" yaml:"debug"`
Trace bool `json:"trace" toml:"trace" xml:"trace" yaml:"trace"`
Quiet bool `json:"quiet" toml:"quiet" xml:"quiet" yaml:"quiet"`
NoUploads bool `json:"noUploads" toml:"no_uploads" xml:"no_uploads" yaml:"noUploads"`
}
LogConfig allows sending logs to rotating files. Setting an AppName will force log creation even if LogFile and HTTPLog are empty.
func (*LogConfig) GetActiveLogFilePaths ¶ added in v0.6.0
GetActiveLogFilePaths returns the configured log file paths.
type LogFileInfo ¶ added in v0.3.0
type LogFileInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Path string `json:"path"`
Size int64 `json:"size"`
Time time.Time `json:"time"`
Mode string `json:"mode"`
Used bool `json:"used"`
User string `json:"user"`
}
LogFileInfo is returned by GetAllLogFilePaths.
type LogFileInfos ¶ added in v0.3.0
type LogFileInfos struct {
Dirs []string `json:"dirs"`
Size int64 `json:"size"`
List []*LogFileInfo `json:"list"`
}
LogFileInfos holds metadata about files.
func GetFilePaths ¶ added in v0.3.0
func GetFilePaths(files ...string) *LogFileInfos
GetFilePaths is a helper function that returns data about similar files in a folder with the provided file(s). This is useful to find "all the log files" or "all the .conf files" in a folder. Simply pass in 1 or more file paths, and any files in the same folder with the same extension will be returned.
func (*LogFileInfos) Len ¶ added in v0.3.0
func (l *LogFileInfos) Len() int
func (*LogFileInfos) Less ¶ added in v0.3.0
func (l *LogFileInfos) Less(i, j int) bool
func (*LogFileInfos) Swap ¶ added in v0.3.0
func (l *LogFileInfos) Swap(i, j int)
type Logger ¶
type Logger struct {
ErrorLog *log.Logger // Shares a Writer with InfoLog.
DebugLog *log.Logger // Shares a Writer with InfoLog by default. Changeable.
InfoLog *log.Logger
HTTPLog *log.Logger
LogConfig LogConfig
// contains filtered or unexported fields
}
Logger provides some methods with baked in assumptions.
func CustomLog ¶ added in v0.1.6
CustomLog allows the creation of ad-hoc rotating log files from other packages. This is not thread safe with Rotate(), so do not call them at the same time.
func New ¶
func New() *Logger
New returns a new Logger with debug and trace off and sends everything to stdout.
func (*Logger) CapturePanic ¶ added in v0.1.15
func (l *Logger) CapturePanic()
CapturePanic can be deferred in any go routine to log any panic that occurs.
func (*Logger) Close ¶ added in v0.1.6
Close closes all open log files. Does not work on custom logs.
func (*Logger) DebugEnabled ¶ added in v0.3.2
func (*Logger) ErrorfNoShare ¶ added in v0.3.2
ErrorfNoShare writes log lines... to stdout and/or a file.
func (*Logger) GetAllLogFilePaths ¶ added in v0.3.0
func (l *Logger) GetAllLogFilePaths() *LogFileInfos
GetAllLogFilePaths searches the disk for log file names.
func (*Logger) GetDebugLog ¶ added in v0.3.2
func (*Logger) GetErrorLog ¶ added in v0.3.2
func (*Logger) GetInfoLog ¶ added in v0.3.2
func (*Logger) GetLogFiles ¶ added in v0.9.0
func (*Logger) Rotate ¶
Rotate rotates the log files. If called on a custom log, only rotates that log file.
func (*Logger) SetupLogging ¶
SetupLogging splits log writers into a file and/or stdout.