log

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2020 License: MIT Imports: 10 Imported by: 7

README

Stroom Log™

Build Status GoDoc Go report

Simple logger inspired by bwmarrin/lit with fields, opentracing and json output support.

Design Philosophy

The design of the API is inspired by Grafana's Loki log aggregation system and structured logging practices. As a result, it heavily favours using fields to log variable data and having log messages be the same regardless of the contextual data.

Example:

log.WithFields(log.Fields{
    "userId": user.id,
    "requestId": requestId,
}).Info("user logged in successfully")

instead of

log.Info("request %s user %d logged in successfully", user.id, requestId)

Usage

Fetch the package:

go get github.com/Strum355/log

and import it:

import (
    "github.com/Strum355/log"
)

initialize the logger for development:

log.InitSimpleLogger(&log.Config{...})

or for production using a JSON log parser like FluentD

log.InitJSONlogger(&log.Config{...})

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Key logKey = struct{}{}

Functions

func Debug

func Debug(msg string)

func Error

func Error(msg string)

func Info

func Info(msg string)

func InitJSONLogger

func InitJSONLogger(conf *Config)

func InitSimpleLogger

func InitSimpleLogger(conf *Config)

func Warn

func Warn(msg string)

Types

type Config

type Config struct {
	ErrorPrefix string
	WarnPrefix  string
	InfoPrefix  string
	DebugPrefix string
	LogLevel    LogLevel
	Output      io.Writer
	// Will print error level to StdErr
	// UseStdErr is ignored if Output != os.Stdout
	UseStdErr bool
	// contains filtered or unexported fields
}

type Entry

type Entry struct {
	// contains filtered or unexported fields
}

func WithContext added in v1.1.0

func WithContext(ctx context.Context) *Entry

func WithError

func WithError(err error) *Entry

func WithFields

func WithFields(f Fields) *Entry

func (*Entry) Clone

func (e *Entry) Clone() *Entry

func (*Entry) Debug

func (e *Entry) Debug(msg string)

func (*Entry) Error

func (e *Entry) Error(msg string)

func (*Entry) Info

func (e *Entry) Info(msg string)

func (*Entry) Warn

func (e *Entry) Warn(msg string)

func (*Entry) WithContext added in v1.1.0

func (e *Entry) WithContext(ctx context.Context) *Entry

func (*Entry) WithError

func (e *Entry) WithError(err error) *Entry

func (*Entry) WithFields

func (e *Entry) WithFields(f Fields) *Entry

type Fields

type Fields map[string]interface{}

type LogLevel

type LogLevel uint8
const (
	LogDebug LogLevel = iota
	LogInformational
	LogWarning
	LogError
)

Error Levels that can be used to differentiate logged messages and also set the verbosity of logs to display.

Jump to

Keyboard shortcuts

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