Categorygithub.com/mono83/slf
repositorypackage
0.0.0-20170919161409-79153e9636db
Repository: https://github.com/mono83/slf.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# README

Simple static logging facility for Golang

Build Status Go Report Card GoDoc

Brief

SLF provides easy and convenient way to organize logging and metrics reporting inside your application.

import (
    "github.com/mono83/slf/wd"
)

// Create logger with marker example
log := wd.NewLogger("example")
log.Info("Processing some staff")

Allowed logging levels are: Trace, Debug, Info, Warning, Error, Alert

Got logs but no output? Assign receivers!

By default, SLF will ignore any received. To manage output or forwarding to external logging facilities just add a receiver. Most common is stdout receiver, which can be assigned right in your func main()


import (
    "github.com/mono83/slf/wd"
    "github.com/mono83/slf/recievers/writer"
)

func main() {
        // Add ANSI standard output receiver 
        wd.AddReceiver(writer.Options{NoColor: false})
}

To remove debug and trace information, filtering may be applied

wd.AddReceiver(slf.Filter(
                ansi.New(true /*colors*/, true /*show marker*/, false /*async*/),
                writer.Options{NoColor: false},
))

More concision with placeholders

SLF supports additional parameters, that can be applied to log. These parameters can be used as placeholders values and some receiver can contain additional logic for it (for example, Logstash receiver can send placeholder values as separated columns):

log.Info("Processing user :id", params.Int{Key: "id", Value: 300})

Raw params aren't most convenient things in the world, so wd. package contains some builders for frequent params:

FuncArgsDescription
wd.IntParamstring, int
wd.Int64Paramstring, int
wd.CountParamintBuilds integer param with key count
wd.ID64ParamintBuilds 64-bit integer param with key id
wd.FloatParamstring, float64
wd.ErrParamerrorBuilds param containing Go errors with key err
wd.StringParamstring, string
wd.NameParamstring, stringsBuilds string param with key name
wd.DeltaParamtime.DurationBuilds duration param with key delta

spf13/cobra integration

There is wrapper for spf13/cobra. Just invoke slfcobra.Wrap over your main command and CLI arguments and logging will be added:

import (
        "github.com/mono83/slf/util/slfcobra"
)

var BookCmd = slfcobra.Wrap(&cobra.Command{...})