Documentation ¶
Overview ¶
Package log provides convenience functions to allow more granular levels of logging Requirements:
- structured logging - output will most likely be in json, but that shouldn't be known by the log creators
- log levels - limited as possible but convenient and impossible to screw up
- convenient setup and integration with standard baseLogger
- ability to include system/container/service names in logs by default
- include stack traces or other info
Requirements:
plain text output to local log file (io.Writer)
structured json output to CloudWatch (or similar service)
inputs for each level: error OR printf style
Index ¶
- Constants
- func Access(e error) error
- func Accessf(format string, a ...interface{}) string
- func AddOutput(output Output)
- func Audit(e error) error
- func Auditf(format string, a ...interface{}) string
- func Debug(e error) error
- func Debugf(format string, a ...interface{}) string
- func DefaultOutput(m Message)
- func Error(e error) error
- func Errorf(format string, a ...interface{}) string
- func Fatal(e error) error
- func Fatalf(format string, a ...interface{}) string
- func Info(e error) error
- func Infof(format string, a ...interface{}) string
- func JSONOutput(m Message)
- func NewGlobal(id string, outputs ...Output)
- func Warn(e error) error
- func Warnf(format string, a ...interface{}) string
- type Level
- type LevelFlag
- type Logger
- type Message
- type Output
- type StackLogger
- func (l *StackLogger) Access(e error) error
- func (l *StackLogger) Accessf(format string, a ...interface{}) string
- func (l *StackLogger) AddOutput(output Output)
- func (l *StackLogger) Audit(e error) error
- func (l *StackLogger) Auditf(format string, a ...interface{}) string
- func (l *StackLogger) Debug(e error) error
- func (l *StackLogger) Debugf(format string, a ...interface{}) string
- func (l *StackLogger) Error(e error) error
- func (l *StackLogger) Errorf(format string, a ...interface{}) string
- func (l *StackLogger) Fatal(e error) error
- func (l *StackLogger) Fatalf(format string, a ...interface{}) string
- func (l *StackLogger) GetSessionID() string
- func (l *StackLogger) Info(e error) error
- func (l *StackLogger) Infof(format string, a ...interface{}) string
- func (l *StackLogger) IsEmpty() bool
- func (l *StackLogger) New(id string) Logger
- func (l *StackLogger) Pop() (string, error)
- func (l *StackLogger) SetSessionID(id string)
- func (l *StackLogger) Warn(e error) error
- func (l *StackLogger) Warnf(format string, a ...interface{}) string
- type Tracer
- type TracerError
Constants ¶
const (
// FlagDebug is the flag for enabling messages in a logger for Debug messages.
FlagDebug, _ = LevelFlag(1 << iota), iota
// FlagAudit is the flag for enabling messages in a logger for Audit messages.
FlagAudit, _
// FlagInfo is the flag for enabling messages in a logger for Info messages.
FlagInfo, _
// FlagAccess is the flag for enabling messages in a logger for Access messages.
FlagAccess, _
// FlagWarn is the flag for enabling messages in a logger for Warn messages.
FlagWarn, _
// FlagError is the flag for enabling messages in a logger for Error messages.
FlagError, _
// FlagFatal is the flag for enabling messages in a logger for Fatal messages.
FlagFatal, _
// FlagAll has all log level flags set.
FlagAll = (FlagFatal - 1) | FlagFatal
// MaskDefault is set to only record Access, Error and Fatal messages.
MaskDefault = FlagAccess | FlagError | FlagFatal
// MaskVerbose filters everything not between Info and Fatal
MaskVerbose = FlagInfo | FlagWarn | MaskDefault
// MaskDebug filters nothing
MaskDebug = FlagAll
// LevelFatal string for identifying message that are Fatal.
LevelFatal Level = "FATAL"
// LevelError string for identifying message that are Error.
LevelError Level = "ERROR"
// LevelWarn string for identifying message that are Warn.
LevelWarn Level = "WARN"
// LevelAudit string for identifying message that are Audit.
LevelAudit Level = "AUDIT"
// LevelInfo string for identifying message that are Info.
LevelInfo Level = "INFO"
// LevelAccess string for identifying message that are Access.
LevelAccess Level = "ACCESS"
// LevelDebug string for identifying message that are for Debug.
LevelDebug Level = "DEBUG"
)
const (
// MaskEnv is the environment variable that stores the logging mask
MaskEnv = "LOGGING_MASK"
)
Variables ¶
This section is empty.
Functions ¶
func Audit ¶
Audit logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).
func Auditf ¶
Auditf logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).
func DefaultOutput ¶
func DefaultOutput(m Message)
DefaultOutput mimics the behavior of the default logging package by printing to StdErr. This is intended to be passed as one of the output functions to New() or Global().
func Error ¶
Error logs a message regarding a non-fatal internal failure representing a probable code/system issue.
func Errorf ¶
Errorf logs a message regarding a non-fatal internal failure representing a probable code/system issue.
func Fatal ¶
Fatal logs a message regarding a failure that is severe enough to warrant process termination.
func Fatalf ¶
Fatalf logs a message regarding a failure that is severe enough to warrant process termination.
func JSONOutput ¶
func JSONOutput(m Message)
JSONOutput formats the log map into Json and then outputs to stderr (appropriate for aws production services)
func NewGlobal ¶
NewGlobal configures the global logger (analog of New()). Also redirects the standard logger to output through the global logger. This should be used as the first action in main().
Types ¶
type Logger ¶
type Logger interface { // New logger with a copied session and outputs as this logger. Changes to this logger // will not affect the new logger. New(id string) Logger // GetSessionID that is currently in use on this logger GetSessionID() string // SetSessionID that is currently in use on this logger SetSessionID(string) // Fatal logs a message regarding a failure that is severe enough to warrant process termination. Fatal(e error) error // Fatalf logs a message regarding a failure that is severe enough to warrant process termination. Fatalf(format string, a ...interface{}) string // Error logs a message regarding a non-fatal internal failure representing a probable code/system issue. Error(e error) error // Errorf logs a message regarding a non-fatal internal failure representing a probable code/system issue. Errorf(format string, a ...interface{}) string // Warn logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments). Warn(e error) error // Warnf logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments). Warnf(format string, a ...interface{}) string // Audit logs a message regarding normal events that are to be systematically recorded (ex: RMS messages). Audit(e error) error // Auditf logs a message regarding normal events that are to be systematically recorded (ex: RMS messages). Auditf(format string, a ...interface{}) string // Access logs a message regarding information about the state of a successfully executing system. Access(e error) error // Accessf logs a message regarding information about the state of a successfully executing system. Accessf(format string, a ...interface{}) string // Info logs a message regarding information about the state of a successfully executing system. Info(e error) error // Infof logs a message regarding information about the state of a successfully executing system. Infof(format string, a ...interface{}) string // Debug logs a message regarding debug information that would be overly verbose for an info message. Debug(e error) error // Debugf logs a message regarding debug information that would be overly verbose for an info message. Debugf(format string, a ...interface{}) string // AddOutput to this logger AddOutput(Output) }
Logger is the tiered level logging interface
type Message ¶
type Message struct { LogIdentifier string `json:"LogIdentifier,omitempty"` SessionID string `json:"SessionID,omitempty"` Level Level `json:"Level,omitempty"` TimestampUnix int64 `json:"TimestampUnix,omitempty"` Timestamp string `json:"Timestamp,omitempty"` Caller string `json:"Caller,omitempty"` Message string `json:"Message,omitempty"` Stack []string `json:"Stack,omitempty"` Error error `json:"Error,omitempty"` }
Message encapsulates all fields that can possibly be a log message.
func (*Message) JSONString ¶
JSONString representation of this message.
type Output ¶
type Output interface { // Level returns the LevelFlag that this logger output accepts Level() LevelFlag // Log the message passed Log(message Message) }
Output represents a single output in a sequential chain of log message receivers.
func FunctionFromEnv ¶
func FunctionFromEnv() Output
FunctionFromEnv reads the environment variables and returns an appropriate log function
type StackLogger ¶
type StackLogger struct {
// contains filtered or unexported fields
}
StackLogger implments the tiered logging interface with a string stack for the messages
func NewStackLogger ¶
func NewStackLogger() *StackLogger
NewStackLogger puts the log messages onto a stack
func (*StackLogger) Access ¶
func (l *StackLogger) Access(e error) error
Access logs a message regarding access information.
func (*StackLogger) Accessf ¶
func (l *StackLogger) Accessf(format string, a ...interface{}) string
Accessf logs a message regarding access information.
func (*StackLogger) AddOutput ¶
func (l *StackLogger) AddOutput(output Output)
AddOutput StackLogger does not support this for obvious reasons
func (*StackLogger) Audit ¶
func (l *StackLogger) Audit(e error) error
Audit logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).
func (*StackLogger) Auditf ¶
func (l *StackLogger) Auditf(format string, a ...interface{}) string
Auditf logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).
func (*StackLogger) Debug ¶
func (l *StackLogger) Debug(e error) error
Debug logs a message regarding debug information.
func (*StackLogger) Debugf ¶
func (l *StackLogger) Debugf(format string, a ...interface{}) string
Debugf logs a message regarding debug information.
func (*StackLogger) Error ¶
func (l *StackLogger) Error(e error) error
Error logs a message regarding a non-fatal internal failure representing a probable code/system issue.
func (*StackLogger) Errorf ¶
func (l *StackLogger) Errorf(format string, a ...interface{}) string
Errorf logs a message regarding a non-fatal internal failure representing a probable code/system issue.
func (*StackLogger) Fatal ¶
func (l *StackLogger) Fatal(e error) error
Fatal logs a message regarding a failure that is severe enough to warrant process termination.
func (*StackLogger) Fatalf ¶
func (l *StackLogger) Fatalf(format string, a ...interface{}) string
Fatalf logs a message regarding a failure that is severe enough to warrant process termination.
func (*StackLogger) GetSessionID ¶
func (l *StackLogger) GetSessionID() string
GetSessionID empty string
func (*StackLogger) Info ¶
func (l *StackLogger) Info(e error) error
Info logs a message regarding debug information.
func (*StackLogger) Infof ¶
func (l *StackLogger) Infof(format string, a ...interface{}) string
Infof logs a message regarding debug information.
func (*StackLogger) IsEmpty ¶
func (l *StackLogger) IsEmpty() bool
IsEmpty checks if the stack has no messages
func (*StackLogger) Pop ¶
func (l *StackLogger) Pop() (string, error)
Pop returns the last message from the message stack
func (*StackLogger) Warn ¶
func (l *StackLogger) Warn(e error) error
Warn logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments).
func (*StackLogger) Warnf ¶
func (l *StackLogger) Warnf(format string, a ...interface{}) string
Warnf logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments).
type TracerError ¶
TracerError is an amalgamation of the Tracer and error interfaces