log

package
v2.16.0-pre Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: MIT Imports: 13 Imported by: 4

Documentation

Overview

Package log is a generated GoMock package.

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

View Source
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"
)
View Source
const (

	// MaskEnv is the environment variable that stores the logging mask
	MaskEnv = "LOGGING_MASK"
)

Variables

This section is empty.

Functions

func Access

func Access(e error) error

Access logs a message regarding access information.

func Accessf

func Accessf(format string, a ...interface{}) string

Accessf logs a message regarding access information.

func AddOutput

func AddOutput(output Output)

AddOutput to the global logger

func Audit

func Audit(e error) error

Audit logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).

func Auditf

func Auditf(format string, a ...interface{}) string

Auditf logs a message regarding normal events that are to be systematically recorded (ex: RMS messages).

func Debug

func Debug(e error) error

Debug logs a message regarding debug information.

func Debugf

func Debugf(format string, a ...interface{}) string

Debugf logs a message regarding debug inforrmation.

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

func Error(e error) error

Error logs a message regarding a non-fatal internal failure representing a probable code/system issue.

func Errorf

func Errorf(format string, a ...interface{}) string

Errorf logs a message regarding a non-fatal internal failure representing a probable code/system issue.

func ExitOnError

func ExitOnError(err error)

ExitOnError will exit if an error is returned

func Fatal

func Fatal(e error) error

Fatal logs a message regarding a failure that is severe enough to warrant process termination.

func Fatalf

func Fatalf(format string, a ...interface{}) string

Fatalf logs a message regarding a failure that is severe enough to warrant process termination.

func Info

func Info(e error) error

Info logs a message regarding debug information.

func Infof

func Infof(format string, a ...interface{}) string

Infof logs a message regarding debug information.

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

func NewGlobal(id string, outputs ...Output)

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().

func Warn

func Warn(e error) error

Warn logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments).

func Warnf

func Warnf(format string, a ...interface{}) string

Warnf logs a message regarding a failure type that is expected to occasionally occur (ex: invalid arguments).

Types

type Level

type Level string

Level represents the importance of a message.

func (Level) Convert

func (f Level) Convert() LevelFlag

Convert this level to a level flag

func (Level) Index

func (f Level) Index() (int, bool)

Index for the passed level in the outputs array.

type LevelFlag

type LevelFlag uint8

LevelFlag identifies the levels that a logger output accepts.

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

func Global

func Global() Logger

Global logger that is currently configured.

func New

func New(id string, outputs ...Output) Logger

New returns an implementation of the tiered 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

func (m *Message) JSONString() string

JSONString representation of this message.

func (*Message) TTYString

func (m *Message) TTYString() string

TTYString for logging this message to console.

type MockLogger added in v2.15.0

type MockLogger struct {
	// contains filtered or unexported fields
}

MockLogger is a mock of Logger interface.

func NewMockLogger added in v2.15.0

func NewMockLogger(ctrl *gomock.Controller) *MockLogger

NewMockLogger creates a new mock instance.

func (*MockLogger) Access added in v2.15.0

func (m *MockLogger) Access(e error) error

Access mocks base method.

func (*MockLogger) Accessf added in v2.15.0

func (m *MockLogger) Accessf(format string, a ...interface{}) string

Accessf mocks base method.

func (*MockLogger) AddOutput added in v2.15.0

func (m *MockLogger) AddOutput(arg0 Output)

AddOutput mocks base method.

func (*MockLogger) Audit added in v2.15.0

func (m *MockLogger) Audit(e error) error

Audit mocks base method.

func (*MockLogger) Auditf added in v2.15.0

func (m *MockLogger) Auditf(format string, a ...interface{}) string

Auditf mocks base method.

func (*MockLogger) Debug added in v2.15.0

func (m *MockLogger) Debug(e error) error

Debug mocks base method.

func (*MockLogger) Debugf added in v2.15.0

func (m *MockLogger) Debugf(format string, a ...interface{}) string

Debugf mocks base method.

func (*MockLogger) EXPECT added in v2.15.0

func (m *MockLogger) EXPECT() *MockLoggerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockLogger) Error added in v2.15.0

func (m *MockLogger) Error(e error) error

Error mocks base method.

func (*MockLogger) Errorf added in v2.15.0

func (m *MockLogger) Errorf(format string, a ...interface{}) string

Errorf mocks base method.

func (*MockLogger) Fatal added in v2.15.0

func (m *MockLogger) Fatal(e error) error

Fatal mocks base method.

func (*MockLogger) Fatalf added in v2.15.0

func (m *MockLogger) Fatalf(format string, a ...interface{}) string

Fatalf mocks base method.

func (*MockLogger) GetSessionID added in v2.15.0

func (m *MockLogger) GetSessionID() string

GetSessionID mocks base method.

func (*MockLogger) Info added in v2.15.0

func (m *MockLogger) Info(e error) error

Info mocks base method.

func (*MockLogger) Infof added in v2.15.0

func (m *MockLogger) Infof(format string, a ...interface{}) string

Infof mocks base method.

func (*MockLogger) New added in v2.15.0

func (m *MockLogger) New(id string) Logger

New mocks base method.

func (*MockLogger) SetSessionID added in v2.15.0

func (m *MockLogger) SetSessionID(arg0 string)

SetSessionID mocks base method.

func (*MockLogger) Warn added in v2.15.0

func (m *MockLogger) Warn(e error) error

Warn mocks base method.

func (*MockLogger) Warnf added in v2.15.0

func (m *MockLogger) Warnf(format string, a ...interface{}) string

Warnf mocks base method.

type MockLoggerMockRecorder added in v2.15.0

type MockLoggerMockRecorder struct {
	// contains filtered or unexported fields
}

MockLoggerMockRecorder is the mock recorder for MockLogger.

func (*MockLoggerMockRecorder) Access added in v2.15.0

func (mr *MockLoggerMockRecorder) Access(e interface{}) *gomock.Call

Access indicates an expected call of Access.

func (*MockLoggerMockRecorder) Accessf added in v2.15.0

func (mr *MockLoggerMockRecorder) Accessf(format interface{}, a ...interface{}) *gomock.Call

Accessf indicates an expected call of Accessf.

func (*MockLoggerMockRecorder) AddOutput added in v2.15.0

func (mr *MockLoggerMockRecorder) AddOutput(arg0 interface{}) *gomock.Call

AddOutput indicates an expected call of AddOutput.

func (*MockLoggerMockRecorder) Audit added in v2.15.0

func (mr *MockLoggerMockRecorder) Audit(e interface{}) *gomock.Call

Audit indicates an expected call of Audit.

func (*MockLoggerMockRecorder) Auditf added in v2.15.0

func (mr *MockLoggerMockRecorder) Auditf(format interface{}, a ...interface{}) *gomock.Call

Auditf indicates an expected call of Auditf.

func (*MockLoggerMockRecorder) Debug added in v2.15.0

func (mr *MockLoggerMockRecorder) Debug(e interface{}) *gomock.Call

Debug indicates an expected call of Debug.

func (*MockLoggerMockRecorder) Debugf added in v2.15.0

func (mr *MockLoggerMockRecorder) Debugf(format interface{}, a ...interface{}) *gomock.Call

Debugf indicates an expected call of Debugf.

func (*MockLoggerMockRecorder) Error added in v2.15.0

func (mr *MockLoggerMockRecorder) Error(e interface{}) *gomock.Call

Error indicates an expected call of Error.

func (*MockLoggerMockRecorder) Errorf added in v2.15.0

func (mr *MockLoggerMockRecorder) Errorf(format interface{}, a ...interface{}) *gomock.Call

Errorf indicates an expected call of Errorf.

func (*MockLoggerMockRecorder) Fatal added in v2.15.0

func (mr *MockLoggerMockRecorder) Fatal(e interface{}) *gomock.Call

Fatal indicates an expected call of Fatal.

func (*MockLoggerMockRecorder) Fatalf added in v2.15.0

func (mr *MockLoggerMockRecorder) Fatalf(format interface{}, a ...interface{}) *gomock.Call

Fatalf indicates an expected call of Fatalf.

func (*MockLoggerMockRecorder) GetSessionID added in v2.15.0

func (mr *MockLoggerMockRecorder) GetSessionID() *gomock.Call

GetSessionID indicates an expected call of GetSessionID.

func (*MockLoggerMockRecorder) Info added in v2.15.0

func (mr *MockLoggerMockRecorder) Info(e interface{}) *gomock.Call

Info indicates an expected call of Info.

func (*MockLoggerMockRecorder) Infof added in v2.15.0

func (mr *MockLoggerMockRecorder) Infof(format interface{}, a ...interface{}) *gomock.Call

Infof indicates an expected call of Infof.

func (*MockLoggerMockRecorder) New added in v2.15.0

func (mr *MockLoggerMockRecorder) New(id interface{}) *gomock.Call

New indicates an expected call of New.

func (*MockLoggerMockRecorder) SetSessionID added in v2.15.0

func (mr *MockLoggerMockRecorder) SetSessionID(arg0 interface{}) *gomock.Call

SetSessionID indicates an expected call of SetSessionID.

func (*MockLoggerMockRecorder) Warn added in v2.15.0

func (mr *MockLoggerMockRecorder) Warn(e interface{}) *gomock.Call

Warn indicates an expected call of Warn.

func (*MockLoggerMockRecorder) Warnf added in v2.15.0

func (mr *MockLoggerMockRecorder) Warnf(format interface{}, a ...interface{}) *gomock.Call

Warnf indicates an expected call of Warnf.

type MockTracer added in v2.15.0

type MockTracer struct {
	// contains filtered or unexported fields
}

MockTracer is a mock of Tracer interface.

func NewMockTracer added in v2.15.0

func NewMockTracer(ctrl *gomock.Controller) *MockTracer

NewMockTracer creates a new mock instance.

func (*MockTracer) EXPECT added in v2.15.0

func (m *MockTracer) EXPECT() *MockTracerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTracer) Trace added in v2.15.0

func (m *MockTracer) Trace() []string

Trace mocks base method.

type MockTracerError added in v2.15.0

type MockTracerError struct {
	// contains filtered or unexported fields
}

MockTracerError is a mock of TracerError interface.

func NewMockTracerError added in v2.15.0

func NewMockTracerError(ctrl *gomock.Controller) *MockTracerError

NewMockTracerError creates a new mock instance.

func (*MockTracerError) EXPECT added in v2.15.0

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockTracerError) Error added in v2.15.0

func (m *MockTracerError) Error() string

Error mocks base method.

func (*MockTracerError) Trace added in v2.15.0

func (m *MockTracerError) Trace() []string

Trace mocks base method.

type MockTracerErrorMockRecorder added in v2.15.0

type MockTracerErrorMockRecorder struct {
	// contains filtered or unexported fields
}

MockTracerErrorMockRecorder is the mock recorder for MockTracerError.

func (*MockTracerErrorMockRecorder) Error added in v2.15.0

Error indicates an expected call of Error.

func (*MockTracerErrorMockRecorder) Trace added in v2.15.0

Trace indicates an expected call of Trace.

type MockTracerMockRecorder added in v2.15.0

type MockTracerMockRecorder struct {
	// contains filtered or unexported fields
}

MockTracerMockRecorder is the mock recorder for MockTracer.

func (*MockTracerMockRecorder) Trace added in v2.15.0

func (mr *MockTracerMockRecorder) Trace() *gomock.Call

Trace indicates an expected call of Trace.

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

func NewFileOutput

func NewFileOutput(level LevelFlag, path string) (Output, error)

NewFileOutput that writes messages of the passed level to the passed file path.

func NewOutput

func NewOutput(level LevelFlag, log func(Message)) Output

NewOutput for use in the log chain.

type StackLogger

type StackLogger struct {
	// contains filtered or unexported fields
}

StackLogger implements 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) New

func (l *StackLogger) New(id string) Logger

New returns this logger

func (*StackLogger) Pop

func (l *StackLogger) Pop() (string, error)

Pop returns the last message from the message stack

func (*StackLogger) SetSessionID

func (l *StackLogger) SetSessionID(id string)

SetSessionID noop

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 Tracer

type Tracer interface {
	Trace() []string
}

Tracer provides a stack trace

type TracerError

type TracerError interface {
	Tracer
	error
}

TracerError is an amalgamation of the Tracer and error interfaces

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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