Define a Level type to represent the severity level for a log entry.
const (
LevelInfo Level = iota// Has the value 0. LevelError // Has the value 1. LevelFatal // Has the value 2. LevelOff // Has the value 3.)
Initialize constants which represent a specific severity level. We use the iota
keyword as a shortcut to assign successive integer values to the constants.
type Logger struct {
// contains filtered or unexported fields
}
Define a custom Logger type. This holds the output destination that the log entries
will be written to, the minimum severity level that log entries will be written for,
plus a mutex for coordinating the writes.
Declare some helper methods for writing log entries at the different levels. Notice
that these all accept a map as the second parameter which can contain any arbitrary
'properties' that you want to appear in the log entry.
We also implement a Write() method on our Logger type so that it satisfies the
io.Writer interface. This writes a log entry at the ERROR level with no additional
properties.