ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - lajosbencz/glo: Logging library for Golang
Logging library for Golang. Contribute to lajosbencz/glo development by creating an account on GitHub.
Visit Site

GitHub - lajosbencz/glo: Logging library for Golang

GitHub - lajosbencz/glo: Logging library for Golang

GoDoc Go Report Card codecov Codacy Badge Build Status

GLO

Logging library for Golang

Inspired by Monolog for PHP, severity levels are identical

Install

go get github.com/lajosbencz/glo

Severity levels

Debug     = 100
Info      = 200
Notice    = 250
Warning   = 300
Error     = 400
Critical  = 500
Alert     = 550
Emergency = 600

Simple example

package main

import "github.com/lajosbencz/glo"

func main() {
	// Info - Warning will go to os.Stdout
	// Error - Emergency will go to os.Stderr
	log := glo.NewStdFacility()

	// goes to os.Stdout
	log.Debug("Detailed debug line: %#v", map[string]string{"x": "foo", "y": "bar"})

	// goes to os.Stderr
	log.Error("Oooof!")
}

Output:

2019-01-22T15:16:08+01:00 [DEBUG] Detailed debug line [map[x:foo y:bar]]
2019-01-22T15:16:08+01:00 [ERROR] Oooof! []

Customized example

package main

import (
	"bytes"
	"fmt"
	"os"
	"strings"

	"github.com/lajosbencz/glo"
)

func main() {
	log := glo.NewFacility()

	// write everything to a buffer
	bfr := bytes.NewBufferString("")
	handlerBfr := glo.NewHandler(bfr)
	log.PushHandler(handlerBfr)

	// write only errors and above using a short format
	handlerStd := glo.NewHandler(os.Stdout)
	formatter := glo.NewFormatter("{L}: {M}")
	filter := glo.NewFilterLevel(glo.Error)
	handlerStd.SetFormatter(formatter)
	handlerStd.PushFilter(filter)
	log.PushHandler(handlerStd)

	fmt.Println("Log output:")
	fmt.Println(strings.Repeat("=", 70))
	log.Info("Only written to the buffer")
	log.Alert("Written to both buffer and stdout")

	fmt.Println("")
	fmt.Println("Buffer contents:")
	fmt.Println(strings.Repeat("=", 70))
	fmt.Println(bfr.String())
}

Output:

Log output:
======================================================================
ALERT: Written to both buffer and stdout []

Buffer contents:
======================================================================
2019-01-22T15:14:16+01:00 [INFO] Only written to the buffer []
2019-01-22T15:14:16+01:00 [ALERT] Written to both buffer and stdout []

Custom filter

package main

import (
	"os"
	"regexp"

	"github.com/lajosbencz/glo"
)

func main() {
	handler := glo.NewHandler(os.Stdout)
	filterEmptyLines := &filterRgx{regexp.MustCompile(`^.+$`)}
	handler.PushFilter(filterEmptyLines)

	log := glo.NewFacility()
	log.PushHandler(handler)

	log.Debug("", "format is empty, should be ignored")
	log.Debug("only this should appear at the output")
}

type filterRgx struct {
	rgx *regexp.Regexp
}

func (f *filterRgx) Check(level glo.Level, line string, params ...interface{}) bool {
	return f.rgx.MatchString(line)
}

Output:

2019-01-22T15:30:23+01:00 [DEBUG] only this should appear at the output

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory