Documentation ¶
Overview ¶
Provides logging capabilities using the GELF (https://www.graylog.org/resources/gelf-2/) log format
Example ¶
c, _ := NewClient() c.Dial("udp://localhost") l, _ := c.NewLogger() l.SetAttr("facility", "example.facility") wait := make(chan int) go func() { for idx := 1; idx <= 10; idx++ { l.Dbgm( map[string]interface{}{ "attr1": "val1", "attr2": 1234}, "Test %v", idx) idx += 1 } wait <- 1 }() <-wait
Output:
Example (DefaultLogger) ¶
c, _ := NewClient() c.Dial("udp://localhost") l, _ := c.NewLogger() l.SetAttr("facility", "example.facility") DefaultLogger(l) wait := make(chan int) go func() { for idx := 1; idx <= 10; idx++ { Dbgm( map[string]interface{}{ "attr1": "val1", "attr2": 1234}, "Test %v", idx) idx += 1 } wait <- 1 }() <-wait
Output:
Index ¶
- Constants
- func Alert(msg string) error
- func Alertf(format string, va ...interface{}) error
- func Alertm(attrs map[string]interface{}, format string, va ...interface{}) error
- func Crit(msg string) error
- func Critf(format string, va ...interface{}) error
- func Critm(attrs map[string]interface{}, format string, va ...interface{}) error
- func Dbg(msg string) error
- func Dbgf(format string, va ...interface{}) error
- func Dbgm(attrs map[string]interface{}, format string, va ...interface{}) error
- func DefaultLogger(l *Logger)
- func Emerg(msg string) error
- func Emergf(format string, va ...interface{}) error
- func Emergm(attrs map[string]interface{}, format string, va ...interface{}) error
- func Err(msg string) error
- func Errf(format string, va ...interface{}) error
- func Errm(attrs map[string]interface{}, format string, va ...interface{}) error
- func Info(msg string) error
- func Infof(format string, va ...interface{}) error
- func Infom(attrs map[string]interface{}, format string, va ...interface{}) error
- func Notice(msg string) error
- func Noticef(format string, va ...interface{}) error
- func Noticem(attrs map[string]interface{}, format string, va ...interface{}) error
- func Warn(msg string) error
- func Warnf(format string, va ...interface{}) error
- func Warnm(attrs map[string]interface{}, format string, va ...interface{}) error
- type Client
- type ClientConfig
- type Logger
- func (l *Logger) Alert(msg string) error
- func (l *Logger) Alertf(format string, va ...interface{}) error
- func (l *Logger) Alertm(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) Attr(name string) interface{}
- func (l *Logger) Clone() *Logger
- func (l *Logger) Crit(msg string) error
- func (l *Logger) Critf(format string, va ...interface{}) error
- func (l *Logger) Critm(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) Dbg(msg string) error
- func (l *Logger) Dbgf(format string, va ...interface{}) error
- func (l *Logger) Dbgm(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) Emerg(msg string) error
- func (l *Logger) Emergf(format string, va ...interface{}) error
- func (l *Logger) Emergm(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) Err(msg string) error
- func (l *Logger) Errf(format string, va ...interface{}) error
- func (l *Logger) Errm(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) Info(msg string) error
- func (l *Logger) Infof(format string, va ...interface{}) error
- func (l *Logger) Infom(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) NewMessage() *Message
- func (l *Logger) Notice(msg string) error
- func (l *Logger) Noticef(format string, va ...interface{}) error
- func (l *Logger) Noticem(attrs map[string]interface{}, format string, va ...interface{}) error
- func (l *Logger) RemAttr(name string)
- func (l *Logger) SetAttr(name string, val interface{})
- func (l *Logger) Warn(msg string) error
- func (l *Logger) Warnf(format string, va ...interface{}) error
- func (l *Logger) Warnm(attrs map[string]interface{}, format string, va ...interface{}) error
- type Message
Examples ¶
Constants ¶
const ( COMP_NONE = iota // No compression COMP_GZIP // gzip compression COMP_ZLIB // zlib compression )
Compression type to use for GELF messages that are sent
const ( LEVEL_EMERG = iota // Emergency LEVEL_ALERT // Alert LEVEL_CRIT // Critical LEVEL_ERR // Error LEVEL_WARN // Warning LEVEL_NOTICE // Notice LEVEL_INFO // Informational LEVEL_DBG // Debug )
Levels to be used when logging messages. These match syslog levels as the GELF spec specifies.
Variables ¶
This section is empty.
Functions ¶
func Alertf ¶
Log a message at LEVEL_ALERT with 'format' populated with values from 'va' on the default logger
func Alertm ¶
Log a message at LEVEL_ALERT with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Critf ¶
Log a message at LEVEL_CRIT with 'format' populated with values from 'va' on the default logger
func Critm ¶
Log a message at LEVEL_CRIT with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Dbgf ¶
Log a message at LEVEL_DBG with 'format' populated with values from 'va' on the default logger
func Dbgm ¶
Log a message at LEVEL_DBG with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func DefaultLogger ¶
func DefaultLogger(l *Logger)
Set the default Logger. Any calls to log messages not associated with a specific Logger (such as calling l.Dbg()) will use the default logger.
func Emergf ¶
Log a message at LEVEL_EMERG with 'format' populated with values from 'va' on the default logger
func Emergm ¶
Log a message at LEVEL_EMERG with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Errf ¶
Log a message at LEVEL_ERR with 'format' populated with values from 'va' on the default logger
func Errm ¶
Log a message at LEVEL_ERR with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Infof ¶
Log a message at LEVEL_INFO with 'format' populated with values from 'va' on the default logger
func Infom ¶
Log a message at LEVEL_INFO with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Noticef ¶
Log a message at LEVEL_NOTICE with 'format' populated with values from 'va' on the default logger
func Noticem ¶
Log a message at LEVEL_NOTICE with 'format' populated with values from 'va' on the default logger. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func Warnf ¶
Log a message at LEVEL_WARN with 'format' populated with values from 'va' on the default logger
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
Create a new Client instance with the default values for ClientConfig:
{ ChunkSize: 1420, Compression: COMP_GZIP, }
func NewClientWithConfig ¶
func NewClientWithConfig(config ClientConfig) (*Client, error)
Create a new Client instance with the given ClientConfig
func (*Client) Close ¶
Close the connection to the server. This call will block until all the currently queued messages for the client are sent.
type ClientConfig ¶
type ClientConfig struct { ChunkSize int // The data size for each chunk sent to the server Compression int // Compression to use for messagec. }
Configuration used when creating a server instance
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
A Logger is a set of attributes associated with a Client. When a message is sent with the Logger, the attributes from that Logger will be added to the message.
func (*Logger) Alertm ¶
Log a message at LEVEL_ALERT with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) Attr ¶
Retrieve the current value of the Logger level attribute named 'name'. Returns nil if the attribute was not found
func (*Logger) Critm ¶
Log a message at LEVEL_CRIT with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) Dbgm ¶
Log a message at LEVEL_DBG with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) Emergm ¶
Log a message at LEVEL_EMERG with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) Errm ¶
Log a message at LEVEL_ERR with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) Infom ¶
Log a message at LEVEL_INFO with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) NewMessage ¶
Create a new message associated with a Logger. When the message is sent, it will use the attributes associated with the Logger it was created from in addition to its own
func (*Logger) Noticef ¶
Log a message at LEVEL_NOTICE with 'format' populated with values from 'va'
func (*Logger) Noticem ¶
Log a message at LEVEL_NOTICE with 'format' populated with values from 'va'. The attributes from 'attrs' will be included with the message, overriding any that may be set at the Logger level
func (*Logger) SetAttr ¶
Set an attribute named 'name' to the value 'val' at the Logger level of attributes
type Message ¶
type Message struct { Level int // Log level for the message (see LEVEL_DBG, etc) Hostname string // Hostname of the client Timestamp *time.Time // Timestamp for the message. Populated automatically if left nil ShortMessage string // Short log message FullMessage string // Full message (optional). Can be used for things like stack traces. Attrs map[string]interface{} // A list of attributes to add to the message // contains filtered or unexported fields }
A message to be serialized and sent to the GELF server