humanlog

package module
v0.8.9 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

README

humanlog

Read logs from stdin and prints them back to stdout, but prettier. It's also a localhost observability platform, supporting logs and distributed traces.

Using it

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

Read more at 👉 how to install in our docs.

Getting started

You can use humanlog in the CLI to make your logs prettier. You can also use it as a localhost observability platform to be able to explore the logs and traces that you ingested. Logs parsed by humanlog are persisted in a local database. Similary, traces are ingested and persisted in a local database when sent via OpenTelemetry/OTLP.

Read more at 👉 how to get started in our docs.

Example - pretty-printing logs

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

example CLI usage

When the logs are parsed, they are persisted in a local database. You can then query and explore them via the web UI.

Example - using it as a localhost observability platform

With the query engine turned on (this is the default on new installations), you can query the logs and traces that you ingested. Run a query with:

$ humanlog query "spans | where duration > 100ms"

querying

Learn more at 👉 how to query in our docs.

Example - ingesting traces

You can ingest traces via OpenTelemetry/OTLP. Using your language of choices' OpenTelemetry client will work out of the box using the default configuration. If not, point your exporter to http://localhost:4317 or http://localhost:4318 (these are the default values).

Other valid values for OTEL_EXPORTER_OTLP_ENDPOINT are:

Situation OTEL_EXPORTER_OTLP_ENDPOINT
Default (same host, OTLP/HTTP) http://localhost:4317
Default (same host, OTLP/gRPC) http://localhost:4318
Docker, Orbstack, kind (OTLP/HTTP) http://host.docker.internal:4317
Docker, Orbstack, kind (OTLP/gRPC) http://host.docker.internal:4318

Learn more at 👉 ingesting OpenTelemetry/OTLP in our docs.

Support and help

Open an issue on this repo or contribute a PR if you find a bug or want to add a feature in the CLI.

Need more help or want to give feedback? Join our community channels.

License

The core CLI is Apache 2 licensed (everything in this repo). Official releases are available at humanlog.io and include proprietary code that is inserted at build time (the query engine).

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = func() *HandlerOptions {
	opts := &HandlerOptions{
		TimeFields: []string{"time", "ts", "@timestamp", "timestamp", "Timestamp", "asctime",
			"stageTimestamp", "requestReceivedTimestamp",
		},
		MessageFields: []string{"message", "msg", "Body"},
		LevelFields:   []string{"level", "lvl", "loglevel", "severity", "SeverityText"},
		timeNow:       time.Now,
		newULID: func() *typesv1.ULID {
			u := ulid.Make()
			return typesv1.ULIDFromBytes(nil, u)
		},
	}
	return opts
}
View Source
var TimeFormats = []string{
	"2006-01-02 15:04:05.999999999 -0700 MST",
	"2006-01-02 15:04:05",
	"2006-01-02T15:04:05-0700",
	"2006-01-02T15:04:05.999-0700",
	"2006-01-02T15:04:05.999999Z07:00",
	time.RFC3339,
	time.RFC3339Nano,
	time.RFC822,
	time.RFC822Z,
	time.RFC850,
	time.RFC1123,
	time.RFC1123Z,
	time.UnixDate,
	time.RubyDate,
	time.ANSIC,
	time.Kitchen,
	time.Stamp,
	time.StampMilli,
	time.StampMicro,
	time.StampNano,
	"2006/01/02 15:04:05",
	"2006/01/02 15:04:05.999999999",
	"06-01-02 15:04:05,999",
	"2006-01-02T15:04:05.999999999",
}

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
	DetectTimestamp bool
	DetectDuration  bool
	// contains filtered or unexported fields
}

func HandlerOptionsFrom

func HandlerOptionsFrom(cfg *typesv1.ParseConfig) *HandlerOptions

type JSONHandler

type JSONHandler struct {
	Opts *HandlerOptions

	Level   string
	Time    time.Time
	Message string
	Fields  []*typesv1.KV
}

JSONHandler can handle logs emitted by logrus.TextFormatter loggers.

func (*JSONHandler) TryHandle

func (h *JSONHandler) TryHandle(d []byte, out *typesv1.Log) 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  []*typesv1.KV
}

LogfmtHandler can handle logs emmited by logrus.TextFormatter loggers.

func (*LogfmtHandler) TryHandle

func (h *LogfmtHandler) TryHandle(d []byte, out *typesv1.Log) 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.

Jump to

Keyboard shortcuts

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