Documentation ¶
Overview ¶
Package log provides logging support for your application and the goradd framework developers.
The logging package is fashioned after the slog package that was released in Go 1.21, but has some notable differences. In particular, each log level is not just a level, but a separate logger, so that you can create very different application responses depending on the log level of the event being recorded. For example, if you would like to email certain logging events to the sysop, you can create a particular logger for that log level.
While developing the slog package, the Go developers did some performance testing, and found that memory allocation was the slowest part of logging. So, they created *Attrs calls that lazy-loaded the attributes and strings, essentially waiting to make sure that a Log call was going to be used before turning an attribute into a string. This principal is attempted to be used here as well, but will require some transition time.
The default main.go file has a command line flag that calls SetLoggingLevel at startup time.
Index ¶
- Constants
- func CreateDefaultLoggers()
- func Debug(v ...interface{})
- func Debugf(format string, v ...interface{})
- func Error(v ...interface{})
- func Errorf(format string, v ...interface{})
- func FrameworkDebug(v ...interface{})
- func FrameworkDebugf(format string, v ...interface{})
- func FrameworkInfo(v ...interface{})
- func FrameworkInfof(format string, v ...interface{})
- func HasLogger(id int) bool
- func Info(v ...interface{})
- func Infof(format string, v ...interface{})
- func Print(logType int, v ...interface{})
- func Printf(logType int, format string, v ...interface{})
- func SetLogger(id int, l LoggerI)
- func SetLoggingLevel(l int)
- func Sql(v ...interface{})
- func StackTrace(startingDepth int, maxDepth int) (out string)
- func Warning(v ...interface{})
- func Warningf(format string, v ...interface{})
- type EmailLogger
- type LoggerI
- type StandardLogger
Constants ¶
const ( FrameworkDebugLog = -12 // Used by framework developers for debugging the framework SqlLog = -8 // Outputs the SQL from all SQL queries. This should be used carefully since sensitive information may appear in the logs. DebugLog = -4 // For use by the application for application level debugging FrameworkInfoLog = 0 // Used by the framework for logging normal application progress, typically a log of http calls. This is the default logging level. InfoLog = 1 // For use by the application to do any other info level logging. Set this logging level to turn off the frameworks info logs so that only the application info logs are reported. WarningLog = 4 // For use by the framework and the application for information that would need to be sent to the sysop periodically. Reports possible performance issues. ErrorLog = 8 // For use by the framework and application for information that should be sent to the sysop immediately. )
The log constants represent both a separate logger, and a log level. Set the log level to turn on or off specific loggers. These logging levels correspond roughly to slog's logging levels.
Variables ¶
This section is empty.
Functions ¶
func CreateDefaultLoggers ¶
func CreateDefaultLoggers()
CreateDefaultLoggers creates default loggers for the application. After calling this, you can replace the loggers with your own by calling SetLogger, and add additional loggers to the logging array, or remove ones you don't use.
func Debug ¶
func Debug(v ...interface{})
Debug is for application debugging logging. It becomes a no-op in the release build.
func Debugf ¶
func Debugf(format string, v ...interface{})
Debugf prints formatted information to the application Debug logger. It becomes a no-op in the release build.
func Errorf ¶
func Errorf(format string, v ...interface{})
Errorf prints formmated information to the Error logger.
func FrameworkDebug ¶
func FrameworkDebug(v ...interface{})
FrameworkDebug is used by the framework to log debugging information. This is mostly for development of the framework, but it can also be used to track down problems in your own code.
func FrameworkDebugf ¶
func FrameworkDebugf(format string, v ...interface{})
FrameworkDebugf is used by the framework to log formatted debugging information.
func FrameworkInfo ¶ added in v0.29.5
func FrameworkInfo(v ...interface{})
FrameworkInfo is used by the framework to log operational information.
func FrameworkInfof ¶ added in v0.29.5
func FrameworkInfof(format string, v ...interface{})
FrameworkInfof is used by the framework to log formatted operational information.
func Infof ¶
func Infof(format string, v ...interface{})
Infof prints formatted information to the InfoLog logger.
func Print ¶
func Print(logType int, v ...interface{})
Print prints information to the given logger. You can use this to set up your own custom logger.
func SetLogger ¶ added in v0.0.3
SetLogger sets the given logger id to the given logger.
Use this function to set up the loggers at startup time. Pass nil for a logger to delete it.
func SetLoggingLevel ¶ added in v0.29.5
func SetLoggingLevel(l int)
SetLoggingLevel sets the current logger level. The current implementation is only suitable to be set at startup time and not while the application is running.
func Sql ¶ added in v0.25.0
func Sql(v ...interface{})
Sql outputs the sql sent to the database driver.
func StackTrace ¶ added in v0.19.0
StackTrace returns a formatted stack trace, listing files and functions on each line.
Types ¶
type EmailLogger ¶
type EmailLogger struct { StandardLogger EmailAddresses []string }
EmailLogger is a logger that will email logging activity to the emails provided.
func (EmailLogger) Log ¶
func (l EmailLogger) Log(out string)
type StandardLogger ¶
StandardLogger reuses the GO default logger
func (StandardLogger) Log ¶
func (l StandardLogger) Log(out string)