Documentation
¶
Overview ¶
Example ¶
This example demonstrates the use of llog.NewWriter() to filter out log messages based on their importance levels.
package main
import (
"errors"
"log"
"os"
"github.com/andrewslotin/llog"
)
func main() {
// configure standard logger to write warning messages and above to STDERR
log.SetOutput(llog.NewWriter(os.Stdout, llog.WarnLevel))
// error level, will be printed out
log.Println("error reading file")
// warn level, will be printed out
log.Printf("warn: failed to close the output file: %s", errors.New("no such file"))
// info level, will be ignored
log.Println("something just happened")
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Level ¶
type Level int8
Level is the log level used by the Writer.
Valid log levels for the Writer
type Writer ¶
Writer wraps an io.Writer filtering out log messages based on the current log level.
func (*Writer) Write ¶
Write determines the log level of the message and writes it to the underlying io.Writer if the log level is greater than or equal to the Writer's log level. The log level of the message is determined by the case-sensitive message prefix: * messages starting with "missing" or "fatal" are considered fatal errors * messages starting with "error" or "failed" are considered errors * messages starting with "warn" are considered warnings * messages starting with "debug:" (including the colon) are considered debug messages * anything else is considered to be an info