ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - mbndr/logo: Golang logger to different configurable writers.
Golang logger to different configurable writers. Contribute to mbndr/logo development by creating an account on GitHub.
Visit Site

GitHub - mbndr/logo: Golang logger to different configurable writers.

GitHub - mbndr/logo: Golang logger to different configurable writers.

Logo

A simple logging library for golang.

banner

I wanted to have a logger that is easy configurable with various io.Writers and a simple active and color on / off switch, so I created it.

Build Status Go Report Card Coverage cover.run go GoDoc MIT License

Explanation

A Logger object can hold multiple Receivers. Every Receiver holds an io.Writer object (f.e. os.File, os.Stderr), a Level which is minimal the log level that is logged, a boolean Active which says if the Receiver should log or not, and a boolean Color which prints output colored if turned on. Every Receiver has also its own log format.

Initilization

First you have to install the package.

go get -u github.com/mbndr/logo

After that you can import it.

import "github.com/mbndr/logo"

Simple

It's possible to create a simple logger with a io.Writer, the log level and a color boolean as parameter.

// Create a simple cli logger with activated colors which logs everything
log := logo.NewSimpleLogger(os.Stderr, logo.DEBUG, "prefix ", true)

Advanced

You can create multiple Receivers and add it to a new Logger.

// Receiver for the terminal which logs everything
cliRec := logo.NewReceiver(os.Stderr, "prefix ")
cliRec.Color = true
cliRec.Level = logo.DEBUG

// Helper function to get a os.File with the correct options
logFile, _ := logo.Open("./example/logo.log")

// Receiver for the log file
// This will log with level INFO (default) and have no colors activated
// Also the log format is simpler (f.e. ERRO: Message)
fileRec := logo.NewReceiver(logFile, "prefix ")
fileRec.Format = "%s: %s"

// Create the logger
log := logo.NewLogger(cliRec, fileRec)

Usage

If you created you logo.Logger object, there are a few methods you can use to log.

// Methods which write like log.Println()
log.Debug("First debug", " and another string to log")
log.Info("Information")
log.Warn("Warning", " message")
log.Error("Error message")
log.Fatal("Fatal error", " because of something")

// Methods which write like log.Printf()
log.Debugf("Debug value %d", 16)
log.Infof("Listening on port %d", 8080)
log.Warnf("Invalid user %s", user.Name)
log.Errorf("Couldn't load config file: %s", path)
log.Fatalf("Fatal error: %s", err.Error())

// Disable the logger
log.Active = false

Tests

There are a few unit tests written for this library. To run them cd into the project directory and run this.

go test -v

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