humanlog

package module
Version: v0.0.0-...-37c9c3e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

humanlog

Read logs from stdin and prints them back to stdout, but prettier.

Using it

Grab a release or :

With Go installed

$ go get -u github.com/aybabtme/humanlog/...

On linux

wget -qO- https://github.com/aybabtme/humanlog/releases/download/0.2.1/humanlog_Linux_x86_64.tar.gz | tar xvz

On OS X

brew tap aybabtme/homebrew-tap
brew install humanlog

Example

If you emit logs in JSON or in logfmt, you will enjoy pretty logs when those entries are encountered by humanlog. Unrecognized lines are left unchanged.

$ humanlog < /var/log/logfile.log

2__fish___users_antoine_gocode_src_github_com_aybabtme_humanlog__fish_

Contributing

How to help:

  • support more log formats: by submitting human.Handler implementations.
  • live querying: add support for filtering in log output in real time.
  • charting: some key-values have semantics that could be charted in real time. For instance, durations, frequency of numeric values, etc. See the l2met project.

Usage

NAME:
   humanlog - reads structured logs from stdin, makes them pretty on stdout!

USAGE:
   humanlog [global options] command [command options] [arguments...]

VERSION:
   0.2.1

AUTHOR:
  Antoine Grondin - <antoine@digitalocean.com>

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --skip '--skip option --skip option'   keys to skip when parsing a log entry
   --keep '--keep option --keep option'   keys to keep when parsing a log entry
   --sort-longest       sort by longest key after having sorted lexicographically
   --skip-unchanged        skip keys that have the same value than the previous entry
   --truncate           truncates values that are longer than --truncate-length
   --truncate-length '15'     truncate values that are longer than this length
   --help, -h           show help
   --version, -v        print the version

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = &HandlerOptions{
	SortLongest:    true,
	SkipUnchanged:  false,
	Truncates:      true,
	LightBg:        false,
	TruncateLength: 15,
	TimeFormat:     time.Stamp,

	KeyColor:              color.New(color.FgGreen),
	ValColor:              color.New(color.FgHiWhite),
	TimeLightBgColor:      color.New(color.FgBlack),
	TimeDarkBgColor:       color.New(color.FgWhite),
	MsgLightBgColor:       color.New(color.FgBlack),
	MsgAbsentLightBgColor: color.New(color.FgHiBlack),
	MsgDarkBgColor:        color.New(color.FgHiWhite),
	MsgAbsentDarkBgColor:  color.New(color.FgWhite),
	DebugLevelColor:       color.New(color.FgMagenta),
	InfoLevelColor:        color.New(color.FgCyan),
	WarnLevelColor:        color.New(color.FgYellow),
	ErrorLevelColor:       color.New(color.FgRed),
	PanicLevelColor:       color.New(color.BgRed),
	FatalLevelColor:       color.New(color.BgHiRed, color.FgHiWhite),
	UnknownLevelColor:     color.New(color.FgMagenta),
}

Functions

func Scanner

func Scanner(src io.Reader, dst io.Writer, opts *HandlerOptions) error

Scanner reads logfmt'd lines from src and prettify them onto dst. If the lines aren't logfmt, it will simply write them out with no prettification.

Types

type Handler

type Handler interface {
	CanHandle(line []byte) bool
	Prettify(skipUnchanged bool) []byte
	logfmt.Handler
}

Handler can recognize it's log lines, parse them and prettify them.

type HandlerOptions

type HandlerOptions struct {
	Skip           map[string]struct{}
	Keep           map[string]struct{}
	SortLongest    bool
	SkipUnchanged  bool
	Truncates      bool
	LightBg        bool
	TruncateLength int
	TimeFormat     string

	KeyColor              *color.Color
	ValColor              *color.Color
	TimeLightBgColor      *color.Color
	TimeDarkBgColor       *color.Color
	MsgLightBgColor       *color.Color
	MsgAbsentLightBgColor *color.Color
	MsgDarkBgColor        *color.Color
	MsgAbsentDarkBgColor  *color.Color
	DebugLevelColor       *color.Color
	InfoLevelColor        *color.Color
	WarnLevelColor        *color.Color
	ErrorLevelColor       *color.Color
	PanicLevelColor       *color.Color
	FatalLevelColor       *color.Color
	UnknownLevelColor     *color.Color
}

func (*HandlerOptions) SetKeep

func (h *HandlerOptions) SetKeep(keep []string)

func (*HandlerOptions) SetSkip

func (h *HandlerOptions) SetSkip(skip []string)

type JSONHandler

type JSONHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  map[string]string
	// contains filtered or unexported fields
}

JSONHandler can handle logs emmited by logrus.TextFormatter loggers.

func (*JSONHandler) Prettify

func (h *JSONHandler) Prettify(skipUnchanged bool) []byte

Prettify the output in a logrus like fashion.

func (*JSONHandler) TryHandle

func (h *JSONHandler) TryHandle(d []byte) bool

TryHandle tells if this line was handled by this handler.

func (*JSONHandler) UnmarshalJSON

func (h *JSONHandler) UnmarshalJSON(data []byte) error

UnmarshalJSON sets the fields of the handler.

type JournalJSONHandler

type JournalJSONHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  map[string]string
	// contains filtered or unexported fields
}

JournalJSONHandler can handle logs emmited by logrus.TextFormatter loggers.

func (*JournalJSONHandler) Prettify

func (h *JournalJSONHandler) Prettify(skipUnchanged bool) []byte

Prettify the output in a logrus like fashion.

func (*JournalJSONHandler) TryHandle

func (h *JournalJSONHandler) TryHandle(d []byte) bool

TryHandle tells if this line was handled by this handler.

func (*JournalJSONHandler) TryHandleEntry

func (h *JournalJSONHandler) TryHandleEntry(entry map[string]interface{}) bool

TryHandleMap tells if this line was handled by this handler.

func (*JournalJSONHandler) UnmarshalJournalEntry

func (h *JournalJSONHandler) UnmarshalJournalEntry(raw map[string]interface{}) error

func (*JournalJSONHandler) UnmarshalJournalJSON

func (h *JournalJSONHandler) UnmarshalJournalJSON(data []byte) error

UnmarshalJournalJSON sets the fields of the handler.

type LogrusHandler

type LogrusHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  map[string]string
	// contains filtered or unexported fields
}

LogrusHandler can handle logs emmited by logrus.TextFormatter loggers.

func (*LogrusHandler) CanHandle

func (h *LogrusHandler) CanHandle(d []byte) bool

CanHandle tells if this line can be handled by this handler.

func (*LogrusHandler) Prettify

func (h *LogrusHandler) Prettify(skipUnchanged bool) []byte

Prettify the output in a logrus like fashion.

Directories

Path Synopsis
cmd
parser

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL