Documentation ¶
Overview ¶
Package gournal (pronounced "Journal") is a Context-aware logging framework.
Gournal introduces the Google Context type (https://blog.golang.org/context) as a first-class parameter to all common log functions such as Info, Debug, etc.
Instead of being Yet Another Go Log library, Gournal actually takes its inspiration from the Simple Logging Facade for Java (SLF4J). Gournal is not attempting to replace anyone's favorite logger, rather existing logging frameworks such as Logrus, Zap, etc. can easily participate as a Gournal Appender.
For more information on Gournal's features or how to use it, please refer to the project's README file or https://github.com/akutz/gournal.
Index ¶
- Variables
- func AppenderKey() interface{}
- func Debug(ctx context.Context, msg string, args ...interface{})
- func Error(ctx context.Context, msg string, args ...interface{})
- func Fatal(ctx context.Context, msg string, args ...interface{})
- func FieldsKey() interface{}
- func Info(ctx context.Context, msg string, args ...interface{})
- func LevelKey() interface{}
- func Panic(ctx context.Context, msg string, args ...interface{})
- func Print(ctx context.Context, msg string, args ...interface{})
- func Warn(ctx context.Context, msg string, args ...interface{})
- type Appender
- type Entry
- type Level
- type Logger
Constants ¶
This section is empty.
Variables ¶
var ( // ErrorKey defines the key when adding errors using WithError. ErrorKey = "error" // DefaultLevel is used when a Level is not present in a Context. DefaultLevel = ErrorLevel // DefaultAppender is used when an Appender is not present in a Context. DefaultAppender = NewAppender() // DefaultContext is used when a log method is invoked with a nil Context. DefaultContext = context.Background() )
Functions ¶
func AppenderKey ¶
func AppenderKey() interface{}
AppenderKey returns the Context key for storing and retrieving an Appender object.
func FieldsKey ¶
func FieldsKey() interface{}
FieldsKey returns the Context key for storing and retrieving Context-specific data that is appended along with each log entry. Three different types of data are inspected for this context key:
map[string]interface{}
func() map[string]interface{}
func(ctx context.Context, lvl Level, fields map[string]interface{}, msg string) map[string]interface{}
func LevelKey ¶
func LevelKey() interface{}
LevelKey returns the Context key used for storing and retrieving the log level.
Types ¶
type Appender ¶
type Appender interface { // Append is implemented by logging frameworks to accept the log entry // at the provided level, its message, and its associated field data. Append( ctx context.Context, lvl Level, fields map[string]interface{}, msg string) }
Appender is the interface that must be implemented by the logging frameworks which are members of the Gournal facade.
func NewAppender ¶ added in v0.2.0
func NewAppender() Appender
NewAppender returns an Appender that writes to os.Stdout.
func NewAppenderWithOptions ¶ added in v0.2.0
NewAppenderWithOptions returns an Appender that writes to the provided io.Writer object.
type Entry ¶
type Entry interface { // WithField adds a single field to the Entry. The provided key will // override an existing, equivalent key in the Entry. WithField(key string, value interface{}) Entry // WithFields adds a map to the Entry. Keys in the provided map will // override existing, equivalent keys in the Entry. WithFields(fields map[string]interface{}) Entry // WithError adds the provided error to the Entry using the ErrorKey value // as the key. WithError(err error) Entry // Debug emits a log entry at the DEBUG level. Debug(ctx context.Context, msg string, args ...interface{}) // Info emits a log entry at the INFO level. Info(ctx context.Context, msg string, args ...interface{}) // Print emits a log entry at the INFO level. Print(ctx context.Context, msg string, args ...interface{}) // Warn emits a log entry at the WARN level. Warn(ctx context.Context, msg string, args ...interface{}) // Error emits a log entry at the ERROR level. Error(ctx context.Context, msg string, args ...interface{}) // Fatal emits a log entry at the FATAL level. Fatal(ctx context.Context, msg string, args ...interface{}) // Panic emits a log entry at the PANIC level. Panic(ctx context.Context, msg string, args ...interface{}) }
Entry is the interface for types that contain information to be emmitted to a log appender.
func WithError ¶
WithError adds the provided error to the Entry using the ErrorKey value as the key.
func WithField ¶
WithField adds a single field to the Entry. The provided key will override an existing, equivalent key in the Entry.
func WithFields ¶
WithFields adds a map to the Entry. Keys in the provided map will override existing, equivalent keys in the Entry.
type Level ¶
type Level uint8
Level is a log level.
const ( // UnknownLevel is an unknown level. UnknownLevel Level = iota // PanicLevel level, highest level of severity. Logs and then calls panic // with the message passed to Debug, Info, ... PanicLevel // FatalLevel level. Logs and then calls os.Exit(1). It will exit even // if the logging level is set to Panic. FatalLevel // ErrorLevel level. Logs. Used for errors that should definitely be noted. // Commonly used for hooks to send errors to an error tracking service. ErrorLevel // WarnLevel level. Non-critical entries that deserve eyes. WarnLevel // InfoLevel level. General operational entries about what's going on // inside the application. InfoLevel // DebugLevel level. Usually only enabled when debugging. Very verbose // logging. DebugLevel )
These are the different logging levels.
func ParseLevel ¶
ParseLevel parses a string and returns its constant.
type Logger ¶
type Logger interface { // Debug emits a log entry at the DEBUG level. Debug(msg string, args ...interface{}) // Info emits a log entry at the INFO level. Info(msg string, args ...interface{}) // Print emits a log entry at the INFO level. Print(msg string, args ...interface{}) // Warn emits a log entry at the WARN level. Warn(msg string, args ...interface{}) // Error emits a log entry at the ERROR level. Error(msg string, args ...interface{}) // Fatal emits a log entry at the FATAL level. Fatal(msg string, args ...interface{}) // Panic emits a log entry at the PANIC level. Panic(msg string, args ...interface{}) }
Logger provides backwards-compatibility for code that does not yet use context-aware logging.
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
Package logrus provides a Logrus logger that implements the Gournal Appender interface.
|
Package logrus provides a Logrus logger that implements the Gournal Appender interface. |
Package stdlib provides a StdLib logger that implements the Gournal Appender interface.
|
Package stdlib provides a StdLib logger that implements the Gournal Appender interface. |
Package zap provides a Zap logger that implements the Gournal Appender interface.
|
Package zap provides a Zap logger that implements the Gournal Appender interface. |