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/emccode/gournal.
Index ¶
- Variables
- func Debug(ctx context.Context, args ...interface{})
- func Error(ctx context.Context, args ...interface{})
- func Fatal(ctx context.Context, args ...interface{})
- func Info(ctx context.Context, args ...interface{})
- func Panic(ctx context.Context, args ...interface{})
- func Print(ctx context.Context, args ...interface{})
- func Warn(ctx context.Context, args ...interface{})
- type Appender
- type Entry
- type Key
- 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 Appender // DefaultContext is used when a log method is invoked with a nil Context. DefaultContext = context.Background() )
Functions ¶
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.
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, args ...interface{})
// Info emits a log entry at the INFO level.
Info(ctx context.Context, args ...interface{})
// Print emits a log entry at the INFO level.
Print(ctx context.Context, args ...interface{})
// Warn emits a log entry at the WARN level.
Warn(ctx context.Context, args ...interface{})
// Error emits a log entry at the ERROR level.
Error(ctx context.Context, args ...interface{})
// Fatal emits a log entry at the FATAL level.
Fatal(ctx context.Context, args ...interface{})
// Panic emits a log entry at the PANIC level.
Panic(ctx context.Context, 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 Key ¶
type Key uint8
Key is the key type used for storing gournal-related objects in a Context.
const ( // AppenderKey is the key for storing the implementation of the Appender // interface in a Context. AppenderKey Key = iota // LevelKey is the key for storing the log Level constant in a Context. LevelKey // FieldsKey is the key used to store/retrieve the Context-specific field // data to append 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.Cotext, // fields map[string]interface{}, // args ...interface{}) map[string]interface{} FieldsKey )
type Level ¶
type Level uint8
Level is a log level.
const ( // PanicLevel level, highest level of severity. Logs and then calls panic // with the message passed to Debug, Info, ... PanicLevel Level = iota // 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(args ...interface{})
// Debugf is an alias for Debug.
Debugf(format string, args ...interface{})
// Debugln is an alias for Debug.
Debugln(args ...interface{})
// Info emits a log entry at the INFO level.
Info(args ...interface{})
// Infof is an alias for Info.
Infof(format string, args ...interface{})
// Infoln is an alias for Info.
Infoln(args ...interface{})
// Print emits a log entry at the INFO level.
Print(args ...interface{})
// Printf is an alias for Print.
Printf(format string, args ...interface{})
// Println is an alias for Print.
Println(args ...interface{})
// Warn emits a log entry at the WARN level.
Warn(args ...interface{})
// Warnf is an alias for Warn.
Warnf(format string, args ...interface{})
// Warnln is an alias for Warn.
Warnln(args ...interface{})
// Error emits a log entry at the ERROR level.
Error(args ...interface{})
// Errorf is an alias for Error.
Errorf(format string, args ...interface{})
// Errorln is an alias for Error.
Errorln(args ...interface{})
// Fatal emits a log entry at the FATAL level.
Fatal(args ...interface{})
// Fatalf is an alias for Fatal.
Fatalf(format string, args ...interface{})
// Fatalln is an alias for Fatal.
Fatalln(args ...interface{})
// Panic emits a log entry at the PANIC level.
Panic(args ...interface{})
// Panicf is an alias for Panic.
Panicf(format string, args ...interface{})
// Panicln is an alias for Panic.
Panicln(args ...interface{})
}
Logger provides backwards-compatibility for code that does not yet use context-aware logging.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
01
command
|
|
|
02
command
|
|
|
03
command
|
|
|
04
command
|
|
|
Package gae provides a Google App Engine logger that implements the Gournal Appender interface.
|
Package gae provides a Google App Engine logger that implements the Gournal Appender interface. |
|
Package iowriter provides a Gournal Appender that writes to any io.Writer object.
|
Package iowriter provides a Gournal Appender that writes to any io.Writer object. |
|
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. |