bragi

package module
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2024 License: Apache-2.0 Imports: 9 Imported by: 26

README

Bragi

GoDoc Go Report Card

Bragi is a simple log lib that is designed to be a dropin repleasement for go's std log lib. But with log output that reflect the output given with java logback. This lib is also going to rotate log files and remove old logs.

Contents

How to use

This is a dropin replace ment, so just add the dependencie and use it as you would do go log. To log to file add the following

log.SetPrefix("vili")
cloaser := log.SetOutputFolder(logDir)
if cloaser == nil {
	log.Fatal("Unable to sett logdir")
}
defer cloaser()

SetPrefix sets the prefix name of the logs. When they rotate the one without any time data in the name is the current and the rest will have the date appended.

SetOutputFolder creates and sets the output folder for bouth human and json logs and returns a function to cloase the files if the process was successfull.

To use the rotating feature add a call to log.StartRotate(done chan func()) after the code example above. Full example below

log.SetPrefix("vili")
cloaser := log.SetOutputFolder(logDir)
if cloaser == nil {
	log.Fatal("Unable to sett logdir")
}
defer cloaser()
log.StartRoute(nil)

Extra functions

If you want to add an error to debug, info, notice, error, crit, fatal with the following pattern

 log.AddError(err).Debug("Information about the error") 

With that pattern you will get bouth the error and the information text in the same log object

Documentation

Index

Constants

View Source
const (
	B int64 = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
	EB
)

Variables

This section is empty.

Functions

func AddError

func AddError(e error) logData

func Closer added in v0.2.0

func Closer()

func Crit

func Crit(a ...interface{})

func Debug

func Debug(a ...interface{})

func Error

func Error(a ...interface{})

func Fatal

func Fatal(a ...interface{})

func Fatalf added in v0.1.6

func Fatalf(format string, a ...interface{})

func FileExists added in v0.6.4

func FileExists(path string) bool

func Info

func Info(a ...interface{})

func NewLogFiles added in v0.6.4

func NewLogFiles(path, jsonPath string) (hf *os.File, jf *os.File, err error)

func Notice

func Notice(a ...interface{})

func Printf added in v0.1.7

func Printf(format string, a ...interface{})

func Println added in v0.1.6

func Println(a ...interface{})

func Rotate added in v0.6.4

func Rotate(path, jsonPath string) (hf *os.File, jf *os.File, err error)

func SetLevel added in v0.5.5

func SetLevel(l Level)

func SetOutputFolder

func SetOutputFolder(path string) func()

func SetPrefix

func SetPrefix(p string)

func StartRotate added in v0.2.0

func StartRotate(done <-chan func())

func TruncateTale added in v0.6.4

func TruncateTale(path string)

func Warning

func Warning(a ...interface{})

Types

type Level

type Level int
const (
	DEBUG Level = iota
	INFO
	NOTICE
	WARNING
	ERROR
	CRIT
)

func (Level) String

func (l Level) String() string

type Stringer added in v0.1.3

type Stringer interface {
	String() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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