All Projects → x-cray → Logrus Prefixed Formatter

x-cray / Logrus Prefixed Formatter

Licence: mit
Logrus Prefixed Log Formatter

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Logrus Prefixed Formatter

Exceptionless
Exceptionless server and jobs
Stars: ✭ 2,107 (+1064.09%)
Mutual labels:  logging
Winston Cloudwatch
Send logs to Amazon Cloudwatch using Winston.
Stars: ✭ 172 (-4.97%)
Mutual labels:  logging
Monolog Bridge
Provides integration for Monolog with various Symfony components.
Stars: ✭ 2,238 (+1136.46%)
Mutual labels:  logging
Zap
Blazing fast, structured, leveled logging in Go.
Stars: ✭ 14,384 (+7846.96%)
Mutual labels:  logging
Logster
Easily parsable single line, plain text and JSON logger for Plug and Phoenix applications
Stars: ✭ 171 (-5.52%)
Mutual labels:  logging
Blackhole
Yet another logging library.
Stars: ✭ 173 (-4.42%)
Mutual labels:  logging
Loglevel
📒 Minimal lightweight logging for JavaScript, adding reliable log level methods to wrap any available console.log methods
Stars: ✭ 2,133 (+1078.45%)
Mutual labels:  logging
Dayperiodformatter
A formatter for localized day periods (morning, afternoon, night, etc.)
Stars: ✭ 181 (+0%)
Mutual labels:  formatter
Tomcat Slf4j Logback
Tomcat, SLF4J and Logback integration Releases
Stars: ✭ 172 (-4.97%)
Mutual labels:  logging
Laravel Auditing
Record the change log from models in Laravel
Stars: ✭ 2,210 (+1120.99%)
Mutual labels:  logging
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+6852.49%)
Mutual labels:  logging
Nixpkgs Fmt
Nix code formatter for nixpkgs [[email protected]]
Stars: ✭ 171 (-5.52%)
Mutual labels:  formatter
Defmt
Efficient, deferred formatting for logging on embedded systems
Stars: ✭ 172 (-4.97%)
Mutual labels:  logging
Logstash
Logstash - transport and process your logs, events, or other data
Stars: ✭ 12,543 (+6829.83%)
Mutual labels:  logging
Yii2 Debug
Debug Extension for Yii 2
Stars: ✭ 179 (-1.1%)
Mutual labels:  logging
Pyrollbar
Error tracking and logging from Python to Rollbar
Stars: ✭ 169 (-6.63%)
Mutual labels:  logging
Graylog Ansible Role
Ansible role which installs and configures Graylog
Stars: ✭ 173 (-4.42%)
Mutual labels:  logging
Logrange
High performance data aggregating storage
Stars: ✭ 181 (+0%)
Mutual labels:  logging
Cloudlog
Web based amateur radio logging application built using PHP & MySQL supports general station logging tasks from HF to Microwave with supporting applications to support CAT control.
Stars: ✭ 179 (-1.1%)
Mutual labels:  logging
Cls Rtracer
Request Tracer - CLS-based request id generation for Express, Fastify, Koa and Hapi, batteries included
Stars: ✭ 175 (-3.31%)
Mutual labels:  logging

Logrus Prefixed Log Formatter

Build Status

Logrus formatter mainly based on original logrus.TextFormatter but with slightly modified colored output and support for log entry prefixes, e.g. message source followed by a colon. In addition, custom color themes are supported.

Formatter screenshot

Just like with the original logrus.TextFormatter when a TTY is not attached, the output is compatible with the logfmt format:

time="Oct 27 00:44:26" level=debug msg="Started observing beach" animal=walrus number=8
time="Oct 27 00:44:26" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
time="Oct 27 00:44:26" level=warning msg="The group's number increased tremendously!" number=122 omg=true
time="Oct 27 00:44:26" level=debug msg="Temperature changes" temperature=-4
time="Oct 27 00:44:26" level=panic msg="It's over 9000!" animal=orca size=9009
time="Oct 27 00:44:26" level=fatal msg="The ice breaks!" number=100 omg=true
exit status 1

Installation

To install formatter, use go get:

$ go get github.com/x-cray/logrus-prefixed-formatter

Usage

Here is how it should be used:

package main

import (
	"github.com/sirupsen/logrus"
	prefixed "github.com/x-cray/logrus-prefixed-formatter"
)

var log = logrus.New()

func init() {
	log.Formatter = new(prefixed.TextFormatter)
	log.Level = logrus.DebugLevel
}

func main() {
	log.WithFields(logrus.Fields{
		"prefix": "main",
		"animal": "walrus",
		"number": 8,
	}).Debug("Started observing beach")

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

API

prefixed.TextFormatter exposes the following fields and methods.

Fields

  • ForceColors bool — set to true to bypass checking for a TTY before outputting colors.
  • DisableColors bool — force disabling colors. For a TTY colors are enabled by default.
  • DisableUppercase bool — set to true to turn off the conversion of the log level names to uppercase.
  • ForceFormatting bool — force formatted layout, even for non-TTY output.
  • DisableTimestamp bool — disable timestamp logging. Useful when output is redirected to logging system that already adds timestamps.
  • FullTimestamp bool — enable logging the full timestamp when a TTY is attached instead of just the time passed since beginning of execution.
  • TimestampFormat string — timestamp format to use for display when a full timestamp is printed.
  • DisableSorting bool — the fields are sorted by default for a consistent output. For applications that log extremely frequently and don't use the JSON formatter this may not be desired.
  • QuoteEmptyFields bool — wrap empty fields in quotes if true.
  • QuoteCharacter string — can be set to the override the default quoting character " with something else. For example: ', or `.
  • SpacePadding int — pad msg field with spaces on the right for display. The value for this parameter will be the size of padding. Its default value is zero, which means no padding will be applied.

Methods

SetColorScheme(colorScheme *prefixed.ColorScheme)

Sets an alternative color scheme for colored output. prefixed.ColorScheme struct supports the following fields:

  • InfoLevelStyle string — info level style.
  • WarnLevelStyle string — warn level style.
  • ErrorLevelStyle string — error style.
  • FatalLevelStyle string — fatal level style.
  • PanicLevelStyle string — panic level style.
  • DebugLevelStyle string — debug level style.
  • PrefixStyle string — prefix style.
  • TimestampStyle string — timestamp style.

Color styles should be specified using mgutz/ansi style syntax. For example, here is the default theme:

InfoLevelStyle:  "green",
WarnLevelStyle:  "yellow",
ErrorLevelStyle: "red",
FatalLevelStyle: "red",
PanicLevelStyle: "red",
DebugLevelStyle: "blue",
PrefixStyle:     "cyan",
TimestampStyle:  "black+h"

It's not necessary to specify all colors when changing color scheme if you want to change just specific ones:

formatter.SetColorScheme(&prefixed.ColorScheme{
    PrefixStyle:    "blue+b",
    TimestampStyle: "white+h",
})

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].