Socket
Book a DemoInstallSign in
Socket

src.userspace.com.au/felix/logger

Package Overview
Dependencies
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

src.userspace.com.au/felix/logger

Go Modules
Version
v1.0.0
Version published
Created
Source

Simple structured logger for Go

A simple logger package that provides levels, a number of output formats, and named sub-logs. Output formats include key/value, JSON, null and AMQP/RabbitMQ

Installation

Install using go get src.userspace.com.au/felix/logger.

Documentation is available at http://godoc.org/src.userspace.com.au/felix/logger

Usage

There is a package level logger that is set to level 'WARN'.

Create a key/value logger

log := logger.New(logger.Name("app"), logger.Level(logger.DEBUG))
log.Error("unable to do anything")
... [info] app: unable to do anything

Add structure

log.Warn("invalid something", "id", 344, "error", "generally broken")
... [warn] app: invalid something id=344 error="generally broken"

Create a named sub-logger

sublog := log.Named("database")
sublog.Info("connection initialised")
... [info] app.database: connection initialised

Create a new Logger with pre-defined values

For major sub-systems there is no need to repeat values for each log call:

reqID := "555"
msgLog := sublog.Field("request", reqID)
msgLog.Error("failed to process message")
... [info] app.database: failed to process message request=555

There is also a Log command with no defined level. These messages are always printed:

log.Log("metrics or whatnot", "something", large)
... metrics or whatnot something="12345678"

Comparison

BenchmarkCoreLogger-12           5000000               288 ns/op
BenchmarkLocal-12                2000000               654 ns/op
BenchmarkLogrus-12               1000000              1738 ns/op
BenchmarkFieldsLocal-12          1000000              1024 ns/op
BenchmarkFieldsLogrus-12         1000000              2061 ns/op

FAQs

Package last updated on 18 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts