func AddFormat(name string, cb func(v interface{}) interface{}) bool
AddFormat assigns a formatting function to the given name.
[CRITICALLY IMPORTANT] You must NOT read from a map directly in the callback because of possible concurrent map access panic.
When formatted logging is used (Verbosef, Networkf, Sysf, Debugf, Infof, Warnf, Errorf, Fatalf), with the given name, it will execute the assigned callback.
The example below will output a specific user property safely (UserFlag is just an example, of course).
log.AddFormat("UserFlag", func(v interface{}) interface{} { // If the value is not *User, we ignore and do nothing if _, ok := v.(*User) { return v } // We make sure to lock the user to print ud := v.(*User) ud.RLock() defer ud.RUnlock() // Format the output as a string formatted := log.Fmt("Properties:", ud.Data["UserFlag"]) return formatted })
func ChangeLogLevelByName(params []string)
ChangeLogLevelByName is automatically called when the server receives SIGUSR1 signal and when there is /tmp/DIARKIS_SIGUSR1.
This function acts as a toggle.
The first line must be ChangeLogLevelByName and the rest will be parameters.
[NOTE] line breaks will be the delimiter.
params[0] = "disable"
params[0] = "enable" params[1] = "$(log_name)" // e.i. MESH, SERVER etc. params[2] = "$(log_level)" // e.i. verbose, network etc.
func CloseFileOutput(next func(error))
CloseFileOutput [INTERNAL USE ONLY] Closes the file descriptor of log data if used
func DisableUnsafeLogging()
DisableUnsafeLogging disables map and struct logging
func EnableUnsafeLogging()
EnableUnsafeLogging enables map and struct logging
func Fmt(vals ...interface{}) string
Fmt alias of fmt.Sprint
func FmtBlue(msg string) string
FmtBlue Colorize the given string
func FmtDBlue(msg string) string
FmtDBlue Colorize the given string
func FmtGreen(msg string) string
FmtGreen Colorize the given string
func FmtGrey(msg string) string
FmtGrey Colorize the given string
func FmtLBlue(msg string) string
FmtLBlue Colorize the given string
func FmtPurple(msg string) string
FmtPurple Colorize the given string
func FmtRed(msg string) string
FmtRed Colorize the given string
func FmtRedBg(msg string) string
FmtRedBg Colorize the given string
func FmtYellow(msg string) string
FmtYellow Colorize the given string
func IsDebug() bool
IsDebug returns true if the log level is debug
func IsError() bool
IsError returns true if the log level is error
func IsFatal() bool
IsFatal returns true if the log level is fatal
func IsInfo() bool
IsInfo returns true if the log level is info
func IsNetwork() bool
IsNetwork returns true if the log level is network
func IsNotice() bool
IsNotice returns true if the log level is notice
func IsSys() bool
IsSys returns true if the log level is sys
func IsVerbose() bool
IsVerbose returns true if the log level is verbose
func IsWarn() bool
IsWarn returns true if the log level is warn
func Level(_level int)
Level Sets logging level
func SetCustomOutput(custom func(formatted bool, name string, prefix string, level string, vals []interface{}) string)
SetCustomOutput Registers a custom function to create a log output string
func SetDebugLevel()
SetDebugLevel set log level to debug
func SetErrorLevel()
SetErrorLevel set log level to error
func SetFatalLevel()
SetFatalLevel set log level to fatal
func SetInfoLevel()
SetInfoLevel set log level to info
func SetNetworkLevel()
SetNetworkLevel set log level to sys
func SetNoticeLevel()
SetNoticeLevel set log level to notice
func SetPrefix(prefix string)
SetPrefix Sets a prefix for every log
func SetSysLevel()
SetSysLevel set log level to sys
func SetVerboseLevel()
SetVerboseLevel set log level to verbose
func SetWarnLevel()
SetWarnLevel set log level to warn
func Setup(confpath string)
Setup Load a configuration file into memory - pass an empty string to load nothing
func UpdateConfigs(configs map[string]interface{})
UpdateConfigs Apply configurations It can be executed in runtime to update the configurations also
func UseCustomOutput()
UseCustomOutput Enables custom output for all log data.
func UseJSONFormat()
UseJSONFormat formats the log with JSON format.
func UseStackdriverLogging()
UseStackdriverLogging is an alias of UseJSONFormat
Logger Logger data structure
type Logger struct { Name string // contains filtered or unexported fields }
func New(name string) *Logger
New Creates a new logger
func (logger *Logger) Debug(vals ...interface{})
Debug Outputs a log to stdout stream
func (logger *Logger) Debugf(vals ...interface{})
Debugf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Debugf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) DisableCustom()
DisableCustom blocks logger.Write()
func (logger *Logger) EnableCustom()
EnableCustom allows logger.Write()
func (logger *Logger) Error(vals ...interface{})
Error Outputs a log to stdout stream
func (logger *Logger) Errorf(vals ...interface{})
Errorf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Errorf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Fatal(vals ...interface{})
Fatal Outputs a log to stdout stream
func (logger *Logger) Fatalf(vals ...interface{})
Fatalf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Fatalf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) FmtDebug(vals ...interface{}) string
FmtDebug Formats given strings and returns it for logging purpose
func (logger *Logger) FmtError(vals ...interface{}) string
FmtError Formats given strings and returns it for logging purpose
func (logger *Logger) FmtFatal(vals ...interface{}) string
FmtFatal Formats given strings and returns it for logging purpose
func (logger *Logger) FmtInfo(vals ...interface{}) string
FmtInfo Formats given strings and returns it for logging purpose
func (logger *Logger) FmtNetwork(vals ...interface{}) string
FmtNetwork Formats given strings and returns it for logging purpose
func (logger *Logger) FmtNotice(vals ...interface{}) string
FmtNotice Formats given strings and returns it for logging purpose
func (logger *Logger) FmtSys(vals ...interface{}) string
FmtSys Formats given strings and returns it for logging purpose
func (logger *Logger) FmtVerbose(vals ...interface{}) string
FmtVerbose Formats given strings and returns it for logging purpose
func (logger *Logger) FmtWarn(vals ...interface{}) string
FmtWarn Formats given strings and returns it for logging purpose
func (logger *Logger) Info(vals ...interface{})
Info Outputs a log to stdout stream
func (logger *Logger) Infof(vals ...interface{})
Infof outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Infof("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Network(vals ...interface{})
Network Outputs a log to stdout stream
func (logger *Logger) Networkf(vals ...interface{})
Networkf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Networkf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Notice(vals ...interface{})
Notice Outputs a log to stdout stream
func (logger *Logger) Noticef(vals ...interface{})
Noticef outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Noticef("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Sys(vals ...interface{})
Sys Outputs a log to stdout stream
func (logger *Logger) Sysf(vals ...interface{})
Sysf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Sysf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Trace(vals ...interface{})
Trace Outputs a log to stdout stream as Sys level log with stack trace. Useful for debugging
func (logger *Logger) Verbose(vals ...interface{})
Verbose Outputs a log to stdout stream
func (logger *Logger) Verbosef(vals ...interface{})
Verbosef outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Verbosef("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Warn(vals ...interface{})
Warn Outputs a log to stdout stream
func (logger *Logger) Warnf(vals ...interface{})
Warnf outputs formatted logging.
This is useful when you need to format the logging message.
[IMPORTANT] FormattedText supports JSON format log output as well.
Example:
logger.Warnf("This is a log", "intVar", 123, "stringVar", "aaa", "object", obj)
func (logger *Logger) Write(vals ...interface{})
Write outputs a log to stdout stream