A simple and colourful logger interface wrapper on-top of the standard library Log for printing formatted lines to the console.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
This project was made to address the need for myself in having a colourful, standardised output similar to LoggerInterface
solutions available in other languages.
In short, this module is a wrapper on top of the standard library Log
to output formatted logs to the terminal for a given service in the following format:
It is assumed that you already have Go installed on your machine.
- go
https://go.dev/doc/install # Follow the instructions to install Go
- Import the module to your project.
go get github.com/jamestkelly/go-logger-interface
To utilise the package after installing the module, simply create a logger interface at the top of your given file and use it like so:
// example.go
import (
github.com/jamestkelly/go-logger-interface
)
var (
exampleLogger = logger.LoggerInterface{Prefix: "ExampleLoggerInterface"}
)
// main
// Example main function to log a bunch of statements using LoggerInterface
func main() {
exampleLogger.LogMessage(
"This is a 'DEBUG' message.",
"DEBUG",
)
exampleLogger.LogMessage(
"This is an 'INFO' message.",
"INFO",
)
exampleLogger.LogMessage(
fmt.Sprintf("This is a %s 'INFO' message.", "formatted"),
"INFO",
)
exampleLogger.LogMessage(
"This is a 'WARN' message.",
"WARN",
)
exampleLogger.LogMessage(
"This is an 'ERROR' message.",
"ERROR",
)
exampleLogger.LogMessage(
"This is a 'FATAL' message.",
"FATAL",
)
}
For more examples, please refer to the Examples
- Create the package and make it available publically.
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Jim Kelly - [email protected]
Project Link: https://github.com/jamestkelly/go-logger-interface