textformatter

package module
v0.0.0-...-9d8cabd Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2017 License: MIT Imports: 11 Imported by: 0

README

Logrus custom text formatter

Build Status

Logrus formatter inspired by github.com/x-cray/logrus-prefixed-formatter.

WARING!!!

This formatter does not following not original nor x-cray's log format conventions.

Default behaviour of this formatter is adapted to my own need.

Installation

To install formatter, use go get:

$ go get github.com/albenik/logrus-text-formatter

Usage examples

package main

import (
	"github.com/sirupsen/logrus"
	"github.com/albenik/logrus-text-formatter"
)

var log = logrus.New()

func init() {
	log.Formatter = new(textformatter.Instance)
	log.Level = logrus.DebugLevel
}

func main() {
	log.WithFields(logrus.Fields{
		"__p":    "textformatter",
		"__f":    "main",
		"__t":    "unique-batch-identifier",
		"animal": "walrus",
		"number": 8,
	}).Debug("Started observing beach")

	log.WithFields(logrus.Fields{
		"__p":         "sensor",
		"__t":         "onchange",
		"temperature": -4,
	}).Info("Temperature changes")
}

License

MIT

Documentation

Index

Constants

View Source
const DefaultTimestampFormat = "2006-01-02T15:04:05.000000000Z07:00"

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorScheme

type ColorScheme struct {
	Debug  string
	Info   string
	Warn   string
	Error  string
	Fatal  string
	Panic  string
	Prefix string
	Func   string
}

type Instance

type Instance struct {
	// Use colors if TTY detected
	UseColors bool

	// Disable timestamp logging. useful when output is redirected to logging
	// system that already adds timestamps.
	DisableTimestamp bool

	// Print level names in `lowercase` instead of `UPPERCASE`
	LowercaseLevels bool

	// Enable logging the full timestamp when a TTY is attached instead of just
	// the time passed since beginning of execution.
	FullTimestamp bool

	// Timestamp format to use for display when a full timestamp is printed.
	TimestampFormat string

	PrefixFieldName  string
	PrefixFieldWidth int
	FuncFieldName    string

	sync.Once
	// contains filtered or unexported fields
}

func (*Instance) Format

func (f *Instance) Format(entry *logrus.Entry) ([]byte, error)

func (*Instance) SetColorScheme

func (f *Instance) SetColorScheme(colorScheme *ColorScheme)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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