Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ravsii/loglevels
Tiny Go library for logging levels
https://github.com/ravsii/loglevels
levels log logger logging tiny
Last synced: 3 days ago
JSON representation
Tiny Go library for logging levels
- Host: GitHub
- URL: https://github.com/ravsii/loglevels
- Owner: ravsii
- License: mit
- Created: 2022-02-01T19:18:05.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-05T14:25:06.000Z (almost 3 years ago)
- Last Synced: 2024-11-08T08:27:13.773Z (about 2 months ago)
- Topics: levels, log, logger, logging, tiny
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# LogLevels
`LogLevels` is a simple package for implementing logging levels inspired by Python default logging package.
It's for those who think that using [Logrus]([https://github.com/sirupsen/logrus]) for their project just for splitting DEBUG/INFO logs is a bit of an overkill.
This package doesn't implement `Fatal` and `Panic` functions
## Installation```
go get github.com/Ravcii/LogLevels
```## Importing
```go
import log "github.com/Ravcii/LogLevels"
```## Logging levels
There are 4 logging levels
* `log.DEBUG` is the lowest logging level. Only devs should really care about it
* `log.INFO` is a logging level for what's outputting what's happening right now in your code, but not as detailed as DEBUG
* `log.WARNING` is a logging level at which your program still runs but you want to at least wanna check what happened
* `log.ERROR` is a logging level at which something would likely crash your program## Usage
### Levels
Use `SetLevel(level)` for settings a level.Use `Level()` for getting a current level.
### Log Functions
There are 8 functions, 2 per each level for normal string and formatted string:
* `Debug()`, `Debugf()`
* `Info()`, `Infof()`
* `Warning()`, `Warningf()`
* `Error()`, `Errorf()`### Changing default settings, changing writer, etc...
You can use `Logger()` to get default logger from the original go's `log` package.
Example:
```go
var buf bytes.Bufferlog.Logger().SetWriter(&buf)
```