cli

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2018 License: MIT Imports: 5 Imported by: 2

README

Cli log handler

For short running cli and human read

Usage

package main

import (
	"os"
	"time"
	
	dlog "github.com/dyweb/gommon/log"
	"github.com/dyweb/gommon/log/handlers/cli"
)

var log = dlog.NewApplicationLogger()

func main() {
	dlog.SetHandlerRecursive(log, cli.New(os.Stderr, true))
	log.Info("hi")
	log.Infof("open file %s", "foo.yml")
	log.InfoF("open", dlog.Fields{
		dlog.Str("file", "foo.yml"),
		dlog.Int("mode", 0666),
	})
	log.Warn("I am yellow")
	func() {
		defer func() {
			if r := recover(); r != nil {
				log.Info("recovered", r)
			}
		}()
		log.Panic("Panic reason")
	}()
	dlog.SetLevelRecursive(log, dlog.DebugLevel)
	log.Debug("I will sleep for a while")
	time.Sleep(1 * time.Second)
	log.Fatal("I am red")
}

Result in

INFO 0000 hi
INFO 0000 open file foo.yml
INFO 0000 open file=foo.yml mode=438
WARN 0000 I am yellow
PANI 0000 Panic reason
INFO 0000 recoveredPanic reason
DEBU 0000 I will sleep for a while
FATA 0001 I am red

It has color (only tested on Linux (Ubuntu)) and can't be disabled

gommon_log_cli_handler

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

func New

func New(w io.Writer, delta bool) *Handler

func (*Handler) Flush

func (h *Handler) Flush()

func (*Handler) HandleLog

func (h *Handler) HandleLog(level log.Level, time time.Time, msg string)

func (*Handler) HandleLogWithFields

func (h *Handler) HandleLogWithFields(level log.Level, time time.Time, msg string, fields log.Fields)

func (*Handler) HandleLogWithSource

func (h *Handler) HandleLogWithSource(level log.Level, time time.Time, msg string, source string)

func (*Handler) HandleLogWithSourceFields

func (h *Handler) HandleLogWithSourceFields(level log.Level, time time.Time, msg string, source string, fields log.Fields)

Jump to

Keyboard shortcuts

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