logformat

package module
v1.0.1-0...-7360a4b Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 7 Imported by: 0

README

Log Format

Some log formatting stuff, it's not super useful for other people.

Documentation

Overview

Package logformat provides some ad-hoc log formatting for some of my projects.

Index

Constants

This section is empty.

Variables

View Source
var DefaultFormatters = Formatters{

	"debug":     colors.Gray,
	"info":      colors.Purple,
	"warn":      colors.Yellow,
	"warning":   colors.Yellow,
	"error":     colors.Red,
	"fatal":     colors.Red,
	"critical":  colors.Red,
	"emergency": colors.Red,

	"string": colors.None,
	"number": colors.None,
	"bool":   colors.None,
	"date":   colors.Gray,

	"object.key":       colors.Purple,
	"object.separator": colors.Gray,
	"object.value":     colors.None,

	"array.delimiter": colors.Gray,
	"array.separator": colors.Gray,

	"message": colors.None,
	"program": colors.Gray,
	"stage":   colors.Gray,
	"version": colors.Gray,
}

DefaultFormatters is a set of default formatters.

View Source
var NoColor = Formatters{

	"debug":     colors.None,
	"info":      colors.None,
	"warn":      colors.None,
	"warning":   colors.None,
	"error":     colors.None,
	"fatal":     colors.None,
	"critical":  colors.None,
	"emergency": colors.None,

	"string": colors.None,
	"number": colors.None,
	"bool":   colors.None,
	"date":   colors.None,

	"object.key":       colors.None,
	"object.separator": colors.None,
	"object.value":     colors.None,

	"array.delimiter": colors.None,
	"array.separator": colors.None,

	"message": colors.None,
	"program": colors.None,
	"stage":   colors.None,
	"version": colors.None,
}

NoColor is a set of formatters resulting in no colors.

Functions

func Compact

func Compact(m map[string]interface{}, options ...Option) string

Compact returns a value in the compact format.

func Expanded

func Expanded(m map[string]interface{}, options ...Option) string

Expanded returns a value in the expanded format.

func Prefix

func Prefix(m map[string]interface{}, options ...Option) string

Prefix returns a prefix for log line special-casing, and removes those fields from the map.

Types

type DateFormatFunc

type DateFormatFunc func(time.Time) string

DateFormatFunc is the function used for formatting dates.

type FormatFunc

type FormatFunc func(string) string

FormatFunc is a function used for formatting values.

type Formatters

type Formatters map[string]FormatFunc

Formatters is a map of formatting functions.

type Option

type Option func(*config)

Option function.

func WithDateFormatter

func WithDateFormatter(v DateFormatFunc) Option

WithDateFormatter overrides the default date formatter.

func WithFlatten

func WithFlatten(v bool) Option

WithFlatten toggles flattening of fields.

func WithFormatters

func WithFormatters(v Formatters) Option

WithFormatters overrides the default formatters.

func WithPrefix

func WithPrefix(s string) Option

WithPrefix sets the prefix of each line.

Directories

Path Synopsis
internal
colors
Package colors provides some colors :)
Package colors provides some colors :)

Jump to

Keyboard shortcuts

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