https://github.com/tauqeernasir/gcl
A dead-simple go colorful logging library
https://github.com/tauqeernasir/gcl
golang-logger golang-logging logging logging-lib logging-library
Last synced: 6 months ago
JSON representation
A dead-simple go colorful logging library
- Host: GitHub
- URL: https://github.com/tauqeernasir/gcl
- Owner: tauqeernasir
- Created: 2021-10-13T21:15:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-15T17:38:16.000Z (over 4 years ago)
- Last Synced: 2024-06-20T17:43:03.990Z (about 2 years ago)
- Topics: golang-logger, golang-logging, logging, logging-lib, logging-library
- Language: Go
- Homepage:
- Size: 1.02 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go colorful logging
A dead simple go logging utility with or without colors.
### Usage
```go
package main
import (
"os"
"github.com/tauqeernasir/gcl/gcl"
)
var Logger *gcl.Logger
func init() {
Logger = gcl.NewLogger(os.Stdout)
}
func main() {
Logger.Info("I am an information message.")
Logger.Error("I am an error message.")
Logger.Success("I am a success message.")
Logger.Warn("I am a warning message.")
Logger.Fatal("I am a fatal message.")
}
```
Above code will generate the following output

> Every method supports formatted versions as well, such as `Logger.Infof(format string, args ...interface{})` and `Logger.Errorf(format string, args ...interface{})`.
### Configurations
You can turn on/off some features of the logger by calling following methods on `Logger`
- WithColor() or WithoutColor()
- WithTimestamp() or WithoutTimestamp
- WithFileInfo() or WithoutFileInfo()
All methods return reference to the `Logger`, so they can easily be chained. Like `Logger.WithColor().WithoutTimestamp().WithoutFileInfo()`
#### Logging to file
```go
package main
import (
"os"
"github.com/tauqeernasir/gcl/gcl"
)
var Logger *gcl.Logger
func init() {
// create a file
f, err := os.Create("log.txt")
if err != nil {
panic("couldn't create log.txt file")
}
// provide file to logger
Logger = gcl.NewLogger(f).WithoutColor()
}
func main() {
Logger.Info("I am an information message.")
Logger.Error("I am an error message.")
Logger.Success("I am a success message.")
Logger.Warn("I am a warning message.")
Logger.Fatal("I am a fatal message.")
}
```