console

package
v5.0.0+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2018 License: MIT Imports: 8 Imported by: 30

Documentation

Overview

Package console allows for log messages to be sent to a any writer, default os.Stderr.

Example

simple console

package main

import (
    "errors"

    "github.com/go-playground/log"
    "github.com/go-playground/log/handlers/console"
)

func main() {
    cLog := console.New(true)
    log.AddHandler(cLog, log.AllLevels...)

    // Trace
    defer log.WithTrace().Info("took this long")

    log.Debug("debug")
    log.Info("info")
    log.Notice("notice")
    log.Warn("warn")
    log.Error("error")
    // log.Panic("panic") // this will panic
    log.Alert("alert")
    // log.Fatal("fatal") // this will call os.Exit(1)

    err := errors.New("the is an error")
    // logging with fields can be used with any of the above
    log.WithError(err).WithFields(log.F("key", "value")).Info("test info")

    // predefined global fields
    log.WithDefaultFields(log.Fields{
        {"program", "test"},
        {"version", "0.1.3"},
    }...)

    log.WithField("key", "value").Info("testing default fields")

    // or request scoped default fields
    logger := log.WithFields(
        log.F("request", "req"),
        log.F("scoped", "sco"),
    )

    logger.WithField("key", "value").Info("test")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Console

type Console struct {
	// contains filtered or unexported fields
}

Console is an instance of the console logger

func New

func New(redirectSTDOut bool) *Console

New returns a new instance of the console logger

func (*Console) Log

func (c *Console) Log(e log.Entry)

Log handles the log entry

func (*Console) SetDisplayColor

func (c *Console) SetDisplayColor(b bool)

SetDisplayColor tells Console to output in color or not Default is : true

func (*Console) SetTimestampFormat

func (c *Console) SetTimestampFormat(format string)

SetTimestampFormat sets Console's timestamp output format Default is : "2006-01-02T15:04:05.000000000Z07:00"

func (*Console) SetWriter

func (c *Console) SetWriter(w io.Writer)

SetWriter sets Console's wriiter Default is : os.Stderr

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL