Documentation ¶
Overview ¶
Package syslog provides logger that generates syslog messages as defined in RFC 5424.
Index ¶
- Constants
- func Alert(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Critical(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Debug(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Emergency(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Error(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Info(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func KeyBySeverity(severity log_level.Priority) string
- func NewWriter(out io.Writer, pri log_level.Priority, hostname, appName, procid string) io.Writer
- func Notice(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- func Warning(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
- type Facility
- type Logger
- type SDElement
- type StructuredData
Examples ¶
Constants ¶
const ( // From /usr/include/sys/syslog.h. // These are the same up to FTP on Linux, BSD, and OS X. KERN log_level.Priority = iota << 3 USER MAIL DAEMON AUTH SYSLOG LPR NEWS UUCP CRON AUTHPRIV FTP LOCAL0 LOCAL1 LOCAL2 LOCAL3 LOCAL4 LOCAL5 LOCAL6 LOCAL7 )
Variables ¶
This section is empty.
Functions ¶
func Critical ¶
func Critical(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
func Emergency ¶
func Emergency(l Logger, msgId string, sd StructuredData, format string, a ...interface{})
func KeyBySeverity ¶
func NewWriter ¶
NewWriter wrappes another io.Writer and returns a new io.Writer that generates syslog messages as defined in RFC 5424 and writes them to the given io.Writer. The returned io.Writer is NOT safe for concurrent use by multiple goroutines.
Example ¶
package main import ( "github.com/confetti-framework/syslog" "github.com/confetti-framework/syslog/log_level" "log" "os" ) func main() { const msg = "Start HTTP server (addr=:8080)" hostname := "laptop" appName := "testapp" procid := "123" wrappedWriter := syslog.NewWriter(os.Stdout, syslog.USER|log_level.NOTICE, hostname, appName, procid) logger := log.New(wrappedWriter, "", 0) logger.Println(msg) // Output is similar to this: // <13>1 2017-08-15T23:13:15.335+02:00 laptop testapp 123 - - Start HTTP server (addr=:8080) }
Output:
Types ¶
type Logger ¶
type Logger interface { // Log generates a syslog message. Log(severity log_level.Priority, msgId string, sd StructuredData, msgFormat string, a ...interface{}) }
Logger generates syslog messages.
func NewLogger ¶
NewLogger returns a new syslog logger that writes to the specified io.Writer. The returned Logger is safe for concurrent use by multiple goroutines.
Example ¶
package main import ( "bytes" "fmt" "github.com/confetti-framework/syslog" ) func main() { buf := &bytes.Buffer{} l := syslog.NewLogger(buf, syslog.USER, "hostname", "appName", "procid") // without structured data syslog.Info(l, "ImageUploaded", nil, "image uploaded by %s: %s", "username", "image.jpg") // with structured data sd := syslog.StructuredData{} sd.Element("id1").Set("par1", "val1") syslog.Error(l, "LoginFailed", sd, "login failed: %s", "username") fmt.Print(buf.String()) // Output is similar to this: // <14>1 2017-08-15T23:13:15.335+02:00 hostname appName procid ImageUploaded - image uploaded by username: image.jpg // <11>1 2017-08-15T23:13:15.335+02:00 hostname appName procid LoginFailed [id1 par1="val1"] login failed: username }
Output:
type SDElement ¶
SDElement represents a structured data element and consists name-value pairs.
type StructuredData ¶
StructuredData provides a mechanism to express information in a well defined, easily parseable and interpretable data format. There are multiple usage scenarios. For example, it may express meta- information about the syslog message or application-specific information such as traffic counters or IP addresses.
StructuredData can contain zero, one, or multiple structured data elements, which are referred to as SDElement.
func (StructuredData) Element ¶
func (d StructuredData) Element(id string) SDElement
Element returns an SDElement associated with the given id. If an element with the id does not exist a new SDElement will be created.
func (StructuredData) Ids ¶
func (d StructuredData) Ids() []string
Ids returns the ids of the SDElements in lexicographical order.
func (StructuredData) String ¶
func (d StructuredData) String() string
Strings returns the string representation of the structured data.