Documentation
¶
Overview ¶
Package log implements the Mute logging framework.
See https://github.com/cihub/seelog/wiki/Log-levels for an introduction to the different logging levels.
We want to log all error conditions in Mute, but want to avoid logging them multiple times. Therefore, we log them once as early as possible: When calling external packages that create an error, we wrap that error in a log.Error() call. If we create our own errors, we use log.Error[f]() to do that. If we call panic() we create the error for that with log.Critical[f](). In server packages we might wrap and create errors with log.Warn[f]() instead of log.Error[f](), because the server doesn't handle the error himself and passes it on to a client. On the client the error is wrapped with log.Error(), because it comes from an external source.
Example (Critical) ¶
This example shows when and how to use the critical log level.
package main import ( "github.com/mutecomm/mute/log" ) func main() { alwaysFalseCondition := false // ... if alwaysFalseCondition { panic(log.Critical("package name: this condition should never be true")) } }
Output:
Example (Error) ¶
This example shows when and how to use the error log level.
package main import ( "os" "github.com/mutecomm/mute/log" ) func main() { conditionWhichShouldBeTrue := true // ... // create own error if !conditionWhichShouldBeTrue { log.Error("package name: condition should be true") } // calling external package which can produce an error _, err := os.Create("filename") if err != nil { log.Error(err) } }
Output:
Example (Info) ¶
This example shows when and how to use the info log level.
package main import ( "github.com/mutecomm/mute/log" ) func main() { // server receives message log.Info("server: message received") }
Output:
Example (Warn) ¶
This example shows when and how to use the warn log level.
package main import ( "github.com/mutecomm/mute/log" ) func main() { expiryCondition := true // ... // check condition in server package, error is not handled on the server if !expiryCondition { log.Warnf("server: token has expired") } }
Output:
Index ¶
- func Critical(v ...interface{}) error
- func Criticalf(format string, params ...interface{}) error
- func Debug(v ...interface{})
- func Debugf(format string, params ...interface{})
- func Error(v ...interface{}) error
- func Errorf(format string, params ...interface{}) error
- func Flush()
- func Info(v ...interface{})
- func Infof(format string, params ...interface{})
- func Init(logLevel, cmdPrefix, logDir string, logToConsole bool) error
- func SetLogWriter(writer io.Writer) error
- func Trace(v ...interface{})
- func Tracef(format string, params ...interface{})
- func UseLogger(newLogger seelog.LoggerInterface)
- func Warn(v ...interface{}) error
- func Warnf(format string, params ...interface{}) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Critical ¶
func Critical(v ...interface{}) error
Critical formats message using the default formats for its operands and writes to default logger with log level = Critical.
func Criticalf ¶
Criticalf formats message according to format specifier and writes to default logger with log level = Critical.
func Debug ¶
func Debug(v ...interface{})
Debug formats message using the default formats for its operands and writes to default logger with log level = Debug.
func Debugf ¶
func Debugf(format string, params ...interface{})
Debugf formats message according to format specifier and writes to default logger with log level = Debug.
func Error ¶
func Error(v ...interface{}) error
Error formats message using the default formats for its operands and writes to default logger with log level = Error.
func Errorf ¶
Errorf formats message according to format specifier and writes to default logger with log level = Error.
func Info ¶
func Info(v ...interface{})
Info formats message using the default formats for its operands and writes to default logger with log level = Info.
func Infof ¶
func Infof(format string, params ...interface{})
Infof formats message according to format specifier and writes to default logger with log level = Info.
func Init ¶
Init initializes the Mute logging framework to the given logging level. If logDir is not nil logging is done to a logfile in the directory. If logToConsole is true the console logging is activated. cmdPrefix must be a 5 character long command prefix. If the given level is invalid or the initialization fails, an error is returned.
func SetLogWriter ¶
SetLogWriter uses a specified io.Writer to output library log. Use this func if you are not using Seelog logging system in your app.
func Trace ¶
func Trace(v ...interface{})
Trace formats message using the default formats for its operands and writes to default logger with log level = Trace.
func Tracef ¶
func Tracef(format string, params ...interface{})
Tracef formats message according to format specifier and writes to default logger with log level = Trace.
func UseLogger ¶
func UseLogger(newLogger seelog.LoggerInterface)
UseLogger uses a specified seelog.LoggerInterface to output library log. Use this func if you are using Seelog logging system in your app.
Types ¶
This section is empty.