# README
#Logger
Logger wraps around the logrus logging package giving options for including information about where a log message was called. It includes the function name, file, and line number.
{
"file": "/Users/realugbun/go/src/github.com/realugbun/somepackage/main.go",
"func": "main.someFunc",
"level": "info",
"line": 87,
"msg": "example log message",
"time": "2022-02-06T12:50:44-05:00"
}
It also includes the option to provide a stack trace.
{
"file": "/Users/realugbun/go/src/github.com/realugbun/somepackage/main.go",
"func": "main.someFunc",
"level": "info",
"line": 87,
"msg": "example log message",
"time": "2022-02-06T12:55:51-05:00",
"trace": [
{
"file": "/Users/realugbun/go/src/github.com/realugbun/mongodb/main.go",
"function": "main.main",
"line": 31
},
{
"file": "/usr/local/opt/go/libexec/src/runtime/proc.go",
"function": "runtime.main",
"line": 255
},
{
"file": "/usr/local/opt/go/libexec/src/runtime/asm_amd64.s",
"function": "runtime.goexit",
"line": 1581
}
]
}
Initialization
Logger has two options for initing.
Init()
starts the logger with default options.
- Loggs to standard output
- Log level set to info
- Information about where the log was called is included
InitWithOptions()
allows customizing the logging behavior.
options := logger.NewOptions() // Creates a new options struct
options.SetFile("filename.log") // Sets the file where logs should be written
options.SetIncludeFunc(true) // Include information about the calling function
options.SetLevel("info") // Set the log level
st := logger.NewStackTrace() // Creates a new struct for stack trace options and enables stack tracing
st.SetMaxEntries(5) // Set the maximum number of entries to include in the trace
st.SetStopFile("main.go") // Set a filename once reached the stack trace will stop
st.SetStopFunction("main.main") // Set a function name once reached the stack trace will stop
st.SetLambda(true) // Sets the stack trace to stop when it reaches the function AWS uses to invoke Lambda
options.SetStackTrace(*st) // Sets the stack trace options on logger options
logger.InitWithOptions(options) // Init the logger with options
Usage
Logger supports two types of logging which match closely with logrus. logger.Info()
, logger.Trace()
etc.
The second option allows adding custom fields which are a slice of map[string]interface{}
. These follow the naming convention logger.InfoWithFields(fields)
etc.
# Functions
Debug logs a message at level Debug on the standard logger.
Debugf logs a message at level Debug on the standard logger.
DebugFn logs a message from a func at level Debug on the standard logger.
DebugfWithFields logs a message with custom fields at level Debug on the standard logger.
Debugln logs a message at level Debug on the standard logger.
DebuglnWithFields logs a message with custom fields at level Debug on the standard logger.
DebugWithFields logs a message with custom fields at level Debug on the standard logger.
Error logs a message at level Error on the standard logger.
Errorf logs a message at level Error on the standard logger.
ErrorFn logs a message from a func at level Error on the standard logger.
ErrorfWithFields logs a message with custom fields at level Error on the standard logger.
Errorln logs a message at level Error on the standard logger.
ErrorlnWithFields logs a message with custom fields at level Error on the standard logger.
ErrorWithFields logs a message with custom fields at level Error on the standard logger.
Fatal logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalf logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
FatalFn logs a message from a func at level Fatal on the standard logger then the process will exit with status set to 1.
FatalfWithFields logs a message with custom fields at level Fatal on the standard logger then the process will exit with status set to 1.
Fatalln logs a message at level Fatal on the standard logger then the process will exit with status set to 1.
FatallnWithFields logs a message with custom fields at level Fatal on the standard logger then the process will exit with status set to 1.
FatalWithFields logs a message with custom fields at level Fatal on the standard logger then the process will exit with status set to 1.
Info logs a message at level Info on the standard logger.
Infof logs a message at level Info on the standard logger.
InfoFn logs a message from a func at level Info on the standard logger.
InfofWithFields logs a message with custom fields at level Info on the standard logger.
Infoln logs a message at level Info on the standard logger.
InfolnWithFields logs a message with custom fields at level Info on the standard logger.
InfoWithFields logs a message with custom fields at level Info on the standard logger.
Init sets up the logger with default options: Log level info, IncludeFunc true, and output to standard output.
InitWithOptions inits the logger using the passed options.
No description provided by the author
No description provided by the author
Panic logs a message at level Panic on the standard logger.
Panicf logs a message at level Panic on the standard logger.
PanicFn logs a message from a func at level Panic on the standard logger.
PanicfWithFields logs a message with custom fields at level Panic on the standard logger.
Panicln logs a message at level Panic on the standard logger.
PaniclnWithFields logs a message with custom fields at level Panic on the standard logger.
PanicWithFields logs a message with custom fields at level Panic on the standard logger.
Print logs a message at level Info on the standard logger.
Printf logs a message at level Info on the standard logger.
PrintFn logs a message from a func at level Info on the standard logger.
PrintfWithFields logs a message with custom fields at level Info on the standard logger.
Println logs a message at level Info on the standard logger.
PrintlnWithFields logs a message with custom fields at level Info on the standard logger.
PrintWithFields logs a message with custom fields at level Info on the standard logger.
SetLevel sets the logging level.
Trace logs a message at level Trace on the standard logger.
Tracef logs a message at level Trace on the standard logger.
TraceFn logs a message from a func at level Trace on the standard logger.
TracefWithFields logs a message with custom fields at level Trace on the standard logger.
Traceln logs a message at level Trace on the standard logger.
TracelnWithFields logs a message with custom fields at level Trace on the standard logger.
TraceWithFields logs a message with custom fields at level Trace on the standard logger.
Warn logs a message at level Warn on the standard logger.
Warnf logs a message at level Warn on the standard logger.
WarnFn logs a message from a func at level Warn on the standard logger.
WarnfWithFields logs a message with custom fields at level Warn on the standard logger.
Warning logs a message at level Warn on the standard logger.
Warningf logs a message at level Warn on the standard logger.
WarningFn logs a message from a func at level Warn on the standard logger.
WarningfWithFields logs a message with custom fields at level Warn on the standard logger.
Warningln logs a message at level Warn on the standard logger.
WarninglnWithFields logs a message with custom fields at level Warn on the standard logger.
WarningWithFields logs a message with custom fields at level Warn on the standard logger.
Warnln logs a message at level Warn on the standard logger.
WarnlnWithFields logs a message with custom fields at level Warn on the standard logger.
WarnWithFields logs a message with custom fields at level Warn on the standard logger.