humanlog

package module
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

humanlog

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

Using it

On macOS

brew tap humanlogio/homebrew-tap
brew install humanlog

On linux (and macOS)

curl -L "https://humanlog.io/install.sh" | sh

Otherwise

Grab a release!

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_humanlogio_humanlog__fish_

Usage

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

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

VERSION:
   0.7.2+48f11b1

AUTHOR:
   Antoine Grondin <antoinegrondin@gmail.com>

COMMANDS:
   version  Interact with humanlog versions
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --config value                    specify a config file to use, otherwise uses the default one
   --skip value                      keys to skip when parsing a log entry
   --keep value                      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 value           truncate values that are longer than this length (default: 15)
   --color value                     specify color mode: auto, on/force, off (default: "auto")
   --light-bg                        use black as the base foreground color (for terminals with light backgrounds)
   --time-format value               output time format, see https://golang.org/pkg/time/ for details (default: "Jan _2 15:04:05")
   --ignore-interrupts, -i           ignore interrupts
   --message-fields value, -m value  Custom JSON fields to search for the log message. (i.e. mssge, data.body.message) [$HUMANLOG_MESSAGE_FIELDS]
   --time-fields value, -t value     Custom JSON fields to search for the log time. (i.e. logtime, data.body.datetime) [$HUMANLOG_TIME_FIELDS]
   --level-fields value, -l value    Custom JSON fields to search for the log level. (i.e. somelevel, data.level) [$HUMANLOG_LEVEL_FIELDS]
   --help, -h                        show help
   --version, -v                     print the version

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = func() *HandlerOptions {
	opts := &HandlerOptions{
		TimeFields:    []string{"time", "ts", "@timestamp", "timestamp", "Timestamp"},
		MessageFields: []string{"message", "msg", "Body"},
		LevelFields:   []string{"level", "lvl", "loglevel", "severity", "SeverityText"},
	}
	return opts
}

Functions

func Scan added in v0.7.4

func Scan(ctx context.Context, src io.Reader, sink sink.Sink, opts *HandlerOptions) error

Scan reads JSON-structured lines from src and prettify them onto dst. If the lines aren't JSON-structured, 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 {
	TimeFields    []string
	MessageFields []string
	LevelFields   []string
}

func HandlerOptionsFrom

func HandlerOptionsFrom(cfg config.Config) *HandlerOptions

type JSONHandler

type JSONHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  map[string]string
}

JSONHandler can handle logs emitted by logrus.TextFormatter loggers.

func (*JSONHandler) TryHandle

func (h *JSONHandler) TryHandle(d []byte, out *model.Structured) bool

TryHandle tells if this line was handled by this handler.

func (*JSONHandler) UnmarshalJSON

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

UnmarshalJSON sets the fields of the handler.

type LogfmtHandler

type LogfmtHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  map[string]string
}

LogfmtHandler can handle logs emmited by logrus.TextFormatter loggers.

func (*LogfmtHandler) TryHandle

func (h *LogfmtHandler) TryHandle(d []byte, out *model.Structured) bool

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

func (*LogfmtHandler) UnmarshalLogfmt

func (h *LogfmtHandler) UnmarshalLogfmt(data []byte) bool

HandleLogfmt sets the fields of the handler.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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