slog

package module
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2020 License: MIT Imports: 5 Imported by: 4

README

SLOG - Simple Log for GO

Slog uses logrus and lumberjack to provide a simple logging interface with two main funcs: Infof(string, ...interface{}) and Errorf(string, ...interface{}) for logging to stdout and logfile at the same time. It also supports executing hooks. Log messages are auto-truncated in case of big data structures accidentally filling up logs.

Features

  • Output to file and stdout at the same time
  • Truncate long error messages
  • Levels (Info, Error, Fatal)
  • Hooks (to send incoming messages to any other system)

Usage

package main
import "github.com/shoobyban/slog"
func main() {
    a := map[string]string{"A":"b"}
    slog.RegisterHook(func(message string) error{
        // Send to Grafana
    },slog.ErrorLog)
    slog.Errorf("%v",a)
}

Documentation

Index

Constants

View Source
const (
	// InfoLog is Info level (lowest) for SetMinLevel
	InfoLog = iota + 1
	// ErrorLog is Error level for SetMinLevel, between WarningLog and FatalLog
	ErrorLog
	// FatalLog is highest log level for SetMinLevel (logging into Fatalf will also throw panic())
	FatalLog
)
View Source
const LogFilePath = "logs/misc.log"

Variables

This section is empty.

Functions

func Close added in v0.4.2

func Close()

Close will close the logfile

func Errorf

func Errorf(message string, args ...interface{})

Errorf logs to dashboard (sends message through log channel) plus echoes to standard output

func Fatalf

func Fatalf(message string, args ...interface{})

Fatalf logs to dashboard (sends message through log channel) plus echoes to standard output

func Infof

func Infof(message string, args ...interface{})

Infof logs to dashboard (sends message through log channel) plus echoes to standard output

func RegisterHook

func RegisterHook(h HookFunc, minlevel int)

RegisterHook will execute given hook function on every message

func RegisterLevelHook

func RegisterLevelHook(h LevelHookFunc, minlevel int)

RegisterLevelHook will execute given hook function on every message (message and level)

func SetFilename

func SetFilename(filename string)

SetFilename modifies the output file path

func SetOutput

func SetOutput(w io.Writer)

SetOutput sets the standard logger output to a writer

Types

type HookFunc

type HookFunc func(message string) error

HookFunc is a callback function type, getting message as argument

type LevelHookFunc

type LevelHookFunc func(message string, level int) error

LevelHookFunc is hook func with log level input attribute

Jump to

Keyboard shortcuts

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