https://github.com/jesse-rb/slogger-go
A small and simple go package that provides a few logging functions to log info/errors to aid in development
https://github.com/jesse-rb/slogger-go
go logging pkg
Last synced: 6 months ago
JSON representation
A small and simple go package that provides a few logging functions to log info/errors to aid in development
- Host: GitHub
- URL: https://github.com/jesse-rb/slogger-go
- Owner: jesse-rb
- License: mit
- Created: 2023-01-28T05:00:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-08-07T12:06:28.000Z (11 months ago)
- Last Synced: 2025-08-07T13:14:41.479Z (11 months ago)
- Topics: go, logging, pkg
- Language: Go
- Homepage: https://pkg.go.dev/github.com/jesse-rb/slogger-go
- Size: 2.3 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slogger: simple go logger
This is a small go package that provides a few simple logging functions to aid in development.
This package allows you to register a new logger very similar to how you would a standard go `log.Logger`,
with the added ability to pass paremeters to configure a log color (using ANSI color codes) and some log prefixese.
[pkg.go.dev docs page](https://pkg.go.dev/github.com/jesse-rb/slogger-go/v2)
**install in project**
Using go modules, from your project directory you can run:
```
go get github.com/jesse-rb/slogger-go/v2
```
**example usage**
```
package main
import (
"log"
"os"
slogger "github.com/jesse-rb/slogger-go"
)
func main() {
slogger.GlobalPrefix = "[slogger-example]"
// Declare some loggers
infoLogger := slogger.New(os.Stdout, slogger.ANSIBlue, "INFO", log.Lshortfile+log.Ldate)
errorLogger := slogger.New(os.Stderr, slogger.ANSIRed, "ERROR", log.Lshortfile+log.Ldate)
// Log some things
infoLogger.Log("main()", "Something worth noting happened", 2+4)
errorLogger.Log("main()", "Some horrible error happened", []int{3, 5, 7})
}
```
**preview logs**

```
[slogger-example] -> INFO -> 2025/08/08 main.go:18: main() -> Something worth noting happened -> data:
6
[slogger-example] -> ERROR -> 2025/08/08 main.go:19: main() -> Some horrible error happened -> data:
[]int{3, 5, 7}
```
## References
Referenced [3 bit 8 colours from Haoyi's Programming Blog](https://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html#8-colors)
as most terminals should supprot this
```
const (
ANSIReset = "\u001b[0m"
ANSIRed = "\u001b[31m"
ANSIBlue = "\u001b[34m"
ANSIBlack = "\u001b[30m"
ANSIGreen = "\u001b[32m"
ANSIYellow = "\u001b[33m"
ANSIMagenta = "\u001b[35m"
ANSICyan = "\u001b[36m"
ANSIWhite = "\u001b[37m"
)
```