https://github.com/brenekh/logange
Another Go logger library, tailored for my use case 🤷♀️
https://github.com/brenekh/logange
go golang golang-library logger logging
Last synced: about 1 year ago
JSON representation
Another Go logger library, tailored for my use case 🤷♀️
- Host: GitHub
- URL: https://github.com/brenekh/logange
- Owner: BrenekH
- License: mit
- Created: 2021-02-04T20:29:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-12-26T02:38:20.000Z (over 3 years ago)
- Last Synced: 2024-12-25T07:18:23.767Z (over 1 year ago)
- Topics: go, golang, golang-library, logger, logging
- Language: Go
- Homepage:
- Size: 31.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Logange
[](https://pkg.go.dev/github.com/BrenekH/logange)
Logging library which mimics Python's native `logging` library.
> :warning: Logange is an experimental and non-production ready library. Use at your own risk.
## Installation
Logange can be installed using the `go get -u github.com/BrenekH/logange` command.
## Concepts
Logange uses loggers, formatters, and handlers.
Loggers are part of a family tree with `logange.RootLogger` as the base node.
Logs will traverse the tree calling any attached handlers on the way to the root logger.
Handlers take log messages and send them to defined sources.
There are two handlers already available as part of Logange, `StdoutHandler` and `FileHandler` which are instantiated using `NewStdoutHandler` and `NewFileHandler` respectively.
Formatters are used by handlers to add additional information to the logs.
## Usage
### Basic Setup
The following code creates a logger called `main`, defines how the message should be formatted, and uses the `logange.StdoutHandler` to output messages to the console.
```go
package main
import "github.com/BrenekH/logange"
func main() {
logger := logange.NewLogger("main")
formatter := logange.StandardFormatter{FormatString: "${datetime}|${name}|${lineno}|${levelname}|${message}\n"}
stdoutHandler := logange.NewStdoutHandler()
stdoutHandler.SetFormatter(formatter)
stdoutHandler.SetLevel(logange.LevelInfo)
logger.AddHandler(&stdoutHandler)
logger.Info("Hello, World!")
}
```