log

package
v0.31.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2024 License: MIT Imports: 5 Imported by: 0

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

View Source
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 Error

func Error(v ...interface{})

Error prints to the Error logger.

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 HasLogger

func HasLogger(id int) bool

HasLogger returns true if the given logger is available.

func Info

func Info(v ...interface{})

Info prints information to the Info logger.

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 Printf

func Printf(logType int, format string, v ...interface{})

Printf prints formatted information to the given logger.

func SetLogger added in v0.0.3

func SetLogger(id int, l LoggerI)

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

func StackTrace(startingDepth int, maxDepth int) (out string)

StackTrace returns a formatted stack trace, listing files and functions on each line.

func Warning

func Warning(v ...interface{})

Warning prints to the Warning logger.

func Warningf

func Warningf(format string, v ...interface{})

Warningf prints formatted information to the Warning logger.

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 LoggerI

type LoggerI interface {
	Log(err string)
}

LoggerI is the interface for all loggers.

type StandardLogger

type StandardLogger struct {
	*log.Logger
}

StandardLogger reuses the GO default logger

func (StandardLogger) Log

func (l StandardLogger) Log(out string)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL