logx

package module
v0.0.0-...-ce6c9d4 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2018 License: MIT Imports: 8 Imported by: 12

README

logx

GoDoc Build Status Codecov Go Report Card

Logx is simple and fast logging library designed taking into account to work in the containerized environments.

In the base Logx using go build tags to configure logging level.

Usage

package main

import "github.com/akaspin/logx"

func main() {
    log := logx.GetLog("test")
    
    log.Trace("too chatty")
    log.Debug("less chatty")
    log.Info("ok")
    log.Notice("something serious")
    log.Warning("oh")
    log.Error("bang")
}

By default all trace and debug calls are completely omitted from output:

$ go run ./main.go 
INFO test main.go:10 ok
NOTICE test main.go:11 something serious
WARNING test main.go:12 oh
ERROR test main.go:13 bang

To make app extremely chatty use "trace" build tag:

$ go run -tags=trace ./main.go 
TRACE test main.go:8 too chatty
DEBUG test main.go:9 less chatty
INFO test main.go:10 ok
NOTICE test main.go:11 something serious
WARNING test main.go:12 oh
ERROR test main.go:13 bang

In opposite to make app quiet use "notice":

$ go run -tags=notice ./main.go 
NOTICE test main.go:11 something serious
WARNING test main.go:12 oh
ERROR test main.go:13 bang

Documentation

Index

Constants

View Source
const (
	// Ldate adds the date in the local time zone: 2009/01/23
	Ldate = 1 << iota

	// Ltime adds the time in the local time zone: 01:23:23
	Ltime

	// Lmicroseconds adds microsecond resolution: 01:23:23.123123. Assumes LTime.
	Lmicroseconds

	// Llongfile adds full file name and line number: /a/b/c/d.go:23
	Llongfile

	// Lshortfile adds final file name element and line number: d.go:23.
	// overrides Llongfile
	Lshortfile

	// LUTC if Ldate or Ltime is set, use UTC rather than the local time zone
	LUTC

	// Lcompact removes whitespace from log lines
	Lcompact

	// LstdFlags initial values for the standard logger
	LstdFlags = Lshortfile | Lcompact
)

Variables

View Source
var DefaultAppender = NewTextAppender(os.Stderr, LstdFlags)

Default TextAppender

Functions

This section is empty.

Types

type Appender

type Appender interface {

	// Append sends log line to appender. Append should be thread-safe.
	Append(level, line string)

	// Clone returns new appender with given prefix and tags.
	Clone(prefix string, tags []string) Appender
}

Appender accepts log entries

type Log

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

func GetLog

func GetLog(prefix string, tags ...string) *Log

GetLog returns new independent log instance with given prefix

func NewLog

func NewLog(appender Appender, prefix string, tags ...string) (res *Log)

Create new log

func (*Log) Critical

func (l *Log) Critical(v ...interface{})

Critical logs value with CRITICAL severity level.

func (*Log) Criticalf

func (l *Log) Criticalf(format string, v ...interface{})

Criticalf logs formatted value with CRITICAL severity level.

func (*Log) Debug

func (*Log) Debug(v ...interface{})

Debug logs value with DEBUG severity level only if "debug" tag is provided on build.

func (*Log) Debugf

func (*Log) Debugf(format string, v ...interface{})

Debugf logs formatted value with DEBUG severity level only if "debug" tag is provided on build.

func (*Log) Error

func (l *Log) Error(v ...interface{})

Error logs value with ERROR severity level.

func (*Log) Errorf

func (l *Log) Errorf(format string, v ...interface{})

Errorf logs formatted value with ERROR severity level.

func (*Log) GetLog

func (l *Log) GetLog(prefix string, tags ...string) (res *Log)

NewTextAppender log with given prefix and tags.

func (*Log) Info

func (l *Log) Info(v ...interface{})

Info logs value with INFO severity level.

func (*Log) Infof

func (l *Log) Infof(format string, v ...interface{})

Infof logs formatted value with INFO severity level.

func (*Log) Notice

func (l *Log) Notice(v ...interface{})

Notice logs value with NOTICE severity level.

func (*Log) Noticef

func (l *Log) Noticef(format string, v ...interface{})

Noticef logs formatted value with NOTICE severity level.

func (*Log) Prefix

func (l *Log) Prefix() (res string)

Log prefix.

func (*Log) Print

func (l *Log) Print(v ...interface{})

Print is synonym to Info used for compatibility with "log" package.

func (*Log) Printf

func (l *Log) Printf(format string, v ...interface{})

Printf is synonym to Infof used for compatibility "log" package.

func (*Log) Tags

func (l *Log) Tags() (res []string)

Log tags.

func (*Log) Trace

func (*Log) Trace(v ...interface{})

Trace logs value with TRACE severity level only if "trace" tag is provided on build.

func (*Log) Tracef

func (*Log) Tracef(format string, v ...interface{})

Tracef logs formatted value with TRACE severity level only if "trace" tag is provided on build.

func (*Log) Warning

func (l *Log) Warning(v ...interface{})

Warning logs value with WARNING severity level.

func (*Log) Warningf

func (l *Log) Warningf(format string, v ...interface{})

Warningf logs formatted value with WARNING severity level.

func (*Log) WithTags

func (l *Log) WithTags(tags ...string) (res *Log)

NewTextAppender log instance wit given tags

type TextAppender

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

TextAppender is default for logx

Format:

time LEVEL prefix [tags] file:line message

func NewTextAppender

func NewTextAppender(output io.Writer, flags int) (a *TextAppender)

NewTextAppender returns new appender without prefix and tags

func (*TextAppender) Append

func (a *TextAppender) Append(level, line string)

func (*TextAppender) Clone

func (a *TextAppender) Clone(prefix string, tags []string) (a1 Appender)

Clone returns copy of TextAppender with given prefix and tags

Jump to

Keyboard shortcuts

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