Categorygithub.com/influxdata/wlog
modulepackage
0.0.0-20160411224016-7c63b0a71ef8
Repository: https://github.com/influxdata/wlog.git
Documentation: pkg.go.dev

# README

wlog

Simple log level based Go logger. Provides an io.Writer that filters log messages based on a log level prefix. Valid log levels are: DEBUG, INFO, WARN, ERROR, OFF. Log messages need to begin with a L! where L is one of D, I, W, or E.

Usage

Create a *log.Logger via wlog.New:

package main

import (
    "log"
    "os"

    "github.com/influxdata/wlog"
)

func main() {
    var logger *log.Logger
    logger = wlog.New(os.Stderr, "prefix", log.LstdFlags)
    logger.Println("I! initialized logger")
}

Create a *log.Logger explicitly using wlog.Writer:

package main

import (
    "log"
    "os"

    "github.com/influxdata/wlog"
)

func main() {
    var logger *log.Logger
    logger = log.New(wlog.NewWriter(os.Stderr), "prefix", log.LstdFlags)
    logger.Println("I! initialized logger")
}

Prefix log messages with a log level char and the ! delimiter.

logger.Println("D! this is a debug log")
logger.Println("I! this is an info log")
logger.Println("W! this is a warn log")
logger.Println("E! this is an error log")

The log level can be changed via the SetLevel or the SetLevelFromName functions.

package main

import (
    "log"
    "os"

    "github.com/influxdata/wlog"
)

func main() {
    var logger *log.Logger
    logger = wlog.New(os.Stderr, "prefix", log.LstdFlags)
    wlog.SetLevel(wlog.DEBUG)
    logger.Println("D! initialized logger")
    wlog.SetLevelFromName("INFO")
    logger.Println("D! this message will be dropped")
    logger.Println("I! this message will be printed")
}

# Functions

Retrieve the current logging Level.
Create a new *log.Logger wrapping w in a wlog.Writer.
Create a writer that always append a static log prefix to all messages.
Create a new wlog.Writer wrapping w.
Set the current logging Level.
Set the log level via a string name.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author
No description provided by the author
name to Level mappings.

# Structs

StaticLevelWriter prefixes all log messages with a static log level.
Implements io.Writer.

# Type aliases

No description provided by the author