Documentation
¶
Overview ¶
Package cclogger implements a simple log wrapper for the standard log package
cclogger provides a simple way of logging with different levels. Time/Date are not logged because systemd adds them (default, can be changed by setting logdate to true. Additionally log output can be set to a file. Default output is stderr. Uses these prefixes: https://www.freedesktop.org/software/systemd/man/sd-daemon.html
Index ¶
- Variables
- func Abort(v ...any)
- func Abortf(format string, v ...any)
- func ComponentDebug(component string, v ...any)
- func ComponentError(component string, v ...any)
- func ComponentInfo(component string, v ...any)
- func ComponentPrint(component string, v ...any)
- func ComponentWarn(component string, v ...any)
- func Debug(v ...any)
- func Debugf(format string, v ...any)
- func Error(v ...any)
- func Errorf(format string, v ...any)
- func Exit(v ...any)
- func Exitf(format string, v ...any)
- func Fatal(v ...any)
- func Fatalf(format string, v ...any)
- func Info(v ...any)
- func Infof(format string, v ...any)
- func Init(lvl string, logdate bool)
- func Loglevel() string
- func Panic(v ...any)
- func Panicf(format string, v ...any)
- func Print(v ...any)
- func Printf(format string, v ...any)
- func SetOutputFile(lvl string, logfile string)
- func Warn(v ...any)
- func Warnf(format string, v ...any)
Constants ¶
This section is empty.
Variables ¶
var ( DebugWriter io.Writer = os.Stderr InfoWriter io.Writer = os.Stderr WarnWriter io.Writer = os.Stderr ErrWriter io.Writer = os.Stderr CritWriter io.Writer = os.Stderr )
var ( DebugPrefix string = "<7>[DEBUG] " InfoPrefix string = "<6>[INFO] " WarnPrefix string = "<4>[WARNING] " ErrPrefix string = "<3>[ERROR] " CritPrefix string = "<2>[CRITICAL] " )
var ( DebugLog *log.Logger = log.New(DebugWriter, DebugPrefix, log.LstdFlags) InfoLog *log.Logger = log.New(InfoWriter, InfoPrefix, log.LstdFlags|log.Lshortfile) WarnLog *log.Logger = log.New(WarnWriter, WarnPrefix, log.LstdFlags|log.Lshortfile) ErrLog *log.Logger = log.New(ErrWriter, ErrPrefix, log.LstdFlags|log.Llongfile) CritLog *log.Logger = log.New(CritWriter, CritPrefix, log.LstdFlags|log.Llongfile) )
Functions ¶
func Abort ¶
func Abort(v ...any)
Abort logs to STDOUT without string formatting; application exits with error code 1. Used for terminating with message after to be expected errors, e.g. wrong arguments or during init().
func Abortf ¶
Abortf logs to STDOUT with string formatting; application exits with error code 1. Used for terminating with message after to be expected errors, e.g. wrong arguments or during init().
func ComponentDebug ¶
func ComponentError ¶
func ComponentInfo ¶ added in v0.2.0
func ComponentPrint ¶
func ComponentWarn ¶ added in v0.2.0
func Debug ¶
func Debug(v ...any)
Debug logs to DEBUG writer without string formatting; application continues. Used for logging additional information, primarily for development.
func Debugf ¶
Debugf logs to DEBUG writer with string formatting; application continues. Used for logging additional information, primarily for development.
func Error ¶
func Error(v ...any)
Error logs to ERROR writer without string formatting; application continues. Used for logging errors, but code still can return default(s) or nil.
func Errorf ¶
Errorf logs to ERROR writer with string formatting; application continues. Used for logging errors, but code still can return default(s) or nil.
func Exit ¶
func Exit(v ...any)
Exit logs to STDOUT without string formatting; application exits with error code 0. Used for exiting succesfully with message after expected outcome, e.g. successful single-call application runs.
func Exitf ¶
Exitf logs to STDOUT with string formatting; application exits with error code 0. Used for exiting succesfully with message after expected outcome, e.g. successful single-call application runs.
func Fatal ¶
func Fatal(v ...any)
Fatal writes to CRITICAL writer without string formatting; application exits with error code 1. Used for terminating on unexpected errors with date and code location.
func Fatalf ¶
Fatalf logs to CRITICAL writer with string formatting; application exits with error code 1. Used for terminating on unexpected errors with date and code location.
func Info ¶
func Info(v ...any)
Info logs to INFO writer without string formatting; application continues. Used for logging additional information, e.g. notable returns or common fail-cases.
func Infof ¶
Infof log to INFO writer with string formatting; application continues. Used for logging additional information, e.g. notable returns or common fail-cases.
func Init ¶
Init initializes cclogger. lvl indicates the loglevel with such values as "debug", "info", "warn", "err", "fatal", "crit". If logdate is set to true a date and time is added to the log output.
func Panic ¶
func Panic(v ...any)
Panic logs to PANIC function without string formatting; application exits with panic. Used for terminating on unexpected errors with stacktrace.
func Panicf ¶
Panicf logs to PANIC function with string formatting; application exits with panic. Used for terminating on unexpected errors with stacktrace.
func Print ¶
func Print(v ...any)
Print logs to STDOUT without string formatting; application continues. Used for special cases not requiring log information like date or location.
func Printf ¶
Printf logs to STDOUT with string formatting; application continues. Used for special cases not requiring log information like date or location.
func SetOutputFile ¶ added in v0.2.0
SetOutputFile sets the output of selected loglevels to a file indicated by the logfile function argument. All loggers lower than lvl are set to the output file. Example: If lvl is warn, the warn, info, and debug loggers will write to logfile.
Types ¶
This section is empty.