Documentation ¶
Overview ¶
Package deck is a Flexible Logging Framework for Go.
Example ¶
package main import ( "errors" "io" "io/ioutil" "os" "github.com/google/deck" "github.com/google/deck/backends/logger" ) // The global instance of deck can be configured during init, main, or anywhere else, as long // as it happens before log messages are used. func init() { f, err := ioutil.TempFile("", "deck_example") if err != nil { panic(err) } // logger supports an io.Writer, so we can pass a single writer or a multiwriter mw := io.MultiWriter(os.Stdout, f) // Add the backends we want to the global deck instance. deck.Add(logger.Init(mw, 0)) } func WriteToDeck(d *deck.Deck) { d.Infoln("hello from WriteToDeck") } func main() { // The global deck can be used in any package by referencing the top level deck package functions. deck.Info("this is the start of the example") deck.Errorf("this is an example error: %v", errors.New("oh no")) // Custom decks can also be initialized with separate settings and passed around. anotherDeck := deck.New() defer anotherDeck.Close() anotherDeck.Add(logger.Init(os.Stderr, 0)) WriteToDeck(anotherDeck) anotherDeck.Info("this is the end of the example") }
Output:
Index ¶
- func Add(b Backend)
- func Close()
- func Depth(d int) func(*AttribStore)
- func Error(message ...any)
- func Errorf(format string, message ...any)
- func Errorln(message ...any)
- func Fatal(message ...any)
- func Fatalf(format string, message ...any)
- func Fatalln(message ...any)
- func Info(message ...any)
- func Infof(format string, message ...any)
- func Infoln(message ...any)
- func SetVerbosity(v int)
- func V(v int) func(*AttribStore)
- func Warning(message ...any)
- func Warningf(format string, message ...any)
- func Warningln(message ...any)
- type Attrib
- type AttribStore
- type Backend
- type Composer
- type Deck
- func (d *Deck) Add(b Backend)
- func (d *Deck) Close()
- func (d *Deck) Error(message ...any)
- func (d *Deck) ErrorA(message ...any) *Log
- func (d *Deck) Errorf(format string, message ...any)
- func (d *Deck) ErrorfA(format string, message ...any) *Log
- func (d *Deck) Errorln(message ...any)
- func (d *Deck) ErrorlnA(message ...any) *Log
- func (d *Deck) Fatal(message ...any)
- func (d *Deck) FatalA(message ...any) *Log
- func (d *Deck) Fatalf(format string, message ...any)
- func (d *Deck) FatalfA(format string, message ...any) *Log
- func (d *Deck) Fatalln(message ...any)
- func (d *Deck) FatallnA(message ...any) *Log
- func (d *Deck) Info(message ...any)
- func (d *Deck) InfoA(message ...any) *Log
- func (d *Deck) Infof(format string, message ...any)
- func (d *Deck) InfofA(format string, message ...any) *Log
- func (d *Deck) Infoln(message ...any)
- func (d *Deck) InfolnA(message ...any) *Log
- func (d *Deck) SetVerbosity(v int)
- func (d *Deck) Warning(message ...any)
- func (d *Deck) WarningA(message ...any) *Log
- func (d *Deck) Warningf(format string, message ...any)
- func (d *Deck) WarningfA(format string, message ...any) *Log
- func (d *Deck) Warningln(message ...any)
- func (d *Deck) WarninglnA(message ...any) *Log
- type Level
- type Log
- func ErrorA(message ...any) *Log
- func ErrorfA(format string, message ...any) *Log
- func ErrorlnA(message ...any) *Log
- func FatalA(message ...any) *Log
- func FatalfA(format string, message ...any) *Log
- func FatallnA(message ...any) *Log
- func InfoA(message ...any) *Log
- func InfofA(format string, message ...any) *Log
- func InfolnA(message ...any) *Log
- func NewLog(verbosity int) *Log
- func WarningA(message ...any) *Log
- func WarningfA(format string, message ...any) *Log
- func WarninglnA(message ...any) *Log
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Depth ¶
func Depth(d int) func(*AttribStore)
Depth is a general attribute that allows specifying log depth to backends. Depth may be used to modify log rendering under certain circumstances.
func Error ¶
func Error(message ...any)
Error immediately logs a message with no attributes to the default deck at the ERROR level.
func Errorf ¶
Errorf immediately logs a message with no attributes according to the format specifier to the default deck at the ERROR level.
func Errorln ¶
func Errorln(message ...any)
Errorln immediately logs a message with no attributes and with a trailing newline to the default deck at the ERROR level.
func Fatal ¶
func Fatal(message ...any)
Fatal immediately logs a message with no attributes to the default deck at the FATAL level.
func Fatalf ¶
Fatalf immediately logs a message with no attributes according to the format specifier to the default deck at the FATAL level.
func Fatalln ¶
func Fatalln(message ...any)
Fatalln immediately logs a message with no attributes and with a trailing newline to the default deck at the FATAL level.
func Info ¶
func Info(message ...any)
Info immediately logs a message with no attributes to the default deck at the INFO level.
Example ¶
package main import ( "github.com/google/deck" ) func main() { deck.Info("This is a simple log line.") }
Output:
func Infof ¶
Infof immediately logs a message with no attributes according to the format specifier to the default deck at the INFO level.
Example ¶
package main import ( "github.com/google/deck" ) func main() { deck.Infof("Is this a %s line? %t", "format", true) }
Output:
func Infoln ¶
func Infoln(message ...any)
Infoln immediately logs a message with no attributes and with a trailing newline to the default deck at the INFO level.
func SetVerbosity ¶
func SetVerbosity(v int)
SetVerbosity sets the internal verbosity level of the default deck.
func V ¶
func V(v int) func(*AttribStore)
V is a special attribute that sets the verbosity level on a message.
deck.Info("example with verbosity 2").V(2).Go()
func Warning ¶
func Warning(message ...any)
Warning immediately logs a message with no attributes to the default deck at the WARNING level.
Types ¶
type Attrib ¶
type Attrib func(*AttribStore)
An Attrib is an attribute that can be associated with Logs.
Attributes are actually functions which modify values in the AttribStore.
type AttribStore ¶
An AttribStore stores unique attributes associated with a given Log.
The store is a string-keyed value map. Backends can interrogate the store for values, and use the values for their own purposes.
type Backend ¶
Backend is the interface that identifies logging backends with NewMessage and Close methods.
type Composer ¶
type Composer interface { Compose(s *AttribStore) error Write() error }
Composer is the interface that groups Compose and Write methods.
type Deck ¶
type Deck struct {
// contains filtered or unexported fields
}
The Deck is the highest level of the logging hierarchy, consisting of one or more backends. All logs written to the deck get flushed to each backend. Multiple decks can be configured with their own sets of backends.
func (*Deck) Errorf ¶
Errorf immediately logs a message with no attributes according to the format specifier at the ERROR level.
func (*Deck) ErrorfA ¶
ErrorfA constructs a message according to the format specifier at the ERROR level.
func (*Deck) Errorln ¶
Errorln immediately logs a message with no attributes and with a trailing newline at the ERROR level.
func (*Deck) Fatalf ¶
Fatalf immediately logs a message with no attributes according to the format specifier at the FATAL level.
func (*Deck) FatalfA ¶
FatalfA constructs a message according to the format specifier at the FATAL level.
func (*Deck) Fatalln ¶
Fatalln immediately logs a message with no attributes and with a trailing newline at the FATAL level.
func (*Deck) Infof ¶
Infof immediately logs a message with no attributes according to the format specifier at the INFO level.
func (*Deck) InfofA ¶
InfofA constructs a message according to the format specifier at the INFO level.
func (*Deck) Infoln ¶
Infoln immediately logs a message with no attributes and with a trailing newline at the INFO level.
func (*Deck) SetVerbosity ¶
SetVerbosity sets the internal verbosity level of the deck.
Messages are committed if the message's own verbosity level (default 0) is equal to or less than the deck's configured level.
func (*Deck) Warningf ¶
Warningf immediately logs a message with no attributes according to the format specifier at the WARNING level.
func (*Deck) WarningfA ¶
WarningfA constructs a message according to the format specifier at the WARNING level.
func (*Deck) Warningln ¶
Warningln immediately logs a message with no attributes and with a trailing newline at the WARNING level.
func (*Deck) WarninglnA ¶
WarninglnA constructs a message with a trailing newline at the WARNING level.
type Level ¶
type Level uint
A Level is a recognized log level (Info, Error, etc). Behavior of a given level is backend-dependent, but they are generally used to determine how to tag, route, or mark-up individual log lines.
Levels should not be confused with the V() attribute. V() is used to set log verbosity, which can be used to include or exclude logging of events, regardless of their associated level.
type Log ¶
type Log struct {
// contains filtered or unexported fields
}
Log is a single log event that will be flushed to all registered backends.
Each log may have one or more attributes associated with it.
func ErrorfA ¶
ErrorfA constructs a message according to the format specifier in the default deck at the ERROR level.
func ErrorlnA ¶
ErrorlnA constructs a message with a trailing newline in the default deck at the ERROR level.
func FatalfA ¶
FatalfA constructs a message according to the format specifier in the default deck at the FATAL level.
func FatallnA ¶
FatallnA constructs a message with a trailing newline in the default deck at the FATAL level.
func InfofA ¶
InfofA constructs a message according to the format specifier in the default deck at the INFO level.
func InfolnA ¶
InfolnA constructs a message with a trailing newline in the default deck at the INFO level.
func WarningfA ¶
WarningfA constructs a message according to the format specifier in the default deck at the WARNING level.
func WarninglnA ¶
WarninglnA constructs a message with a trailing newline in the default deck at the WARNING level.
Directories ¶
Path | Synopsis |
---|---|
backends
|
|
discard
Package discard provides a deck backend that discards all logs.
|
Package discard provides a deck backend that discards all logs. |
eventlog
Package eventlog is a deck backend for writing log messages to Windows Event Log.
|
Package eventlog is a deck backend for writing log messages to Windows Event Log. |
glog
Package glog provides a deck backend for github.com/golang/glog.
|
Package glog provides a deck backend for github.com/golang/glog. |
logger
Package logger provides a deck backend that leverages Go's core log package.
|
Package logger provides a deck backend that leverages Go's core log package. |
replay
Package replay provides a deck backend for replaying log messages.
|
Package replay provides a deck backend for replaying log messages. |
syslog
Package syslog provides a deck backend for syslog.
|
Package syslog provides a deck backend for syslog. |