Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonfisher/nested-logrus-formatter
Formatter for https://github.com/sirupsen/logrus
https://github.com/antonfisher/nested-logrus-formatter
formatter golang logging
Last synced: 3 days ago
JSON representation
Formatter for https://github.com/sirupsen/logrus
- Host: GitHub
- URL: https://github.com/antonfisher/nested-logrus-formatter
- Owner: antonfisher
- License: mit
- Created: 2018-10-16T06:47:11.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2022-10-13T11:12:56.000Z (over 2 years ago)
- Last Synced: 2024-12-14T16:11:11.651Z (about 1 month ago)
- Topics: formatter, golang, logging
- Language: Go
- Homepage:
- Size: 222 KB
- Stars: 161
- Watchers: 6
- Forks: 31
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nested-logrus-formatter
[![Build Status](https://travis-ci.org/antonfisher/nested-logrus-formatter.svg?branch=master)](https://travis-ci.org/antonfisher/nested-logrus-formatter)
[![Go Report Card](https://goreportcard.com/badge/github.com/antonfisher/nested-logrus-formatter)](https://goreportcard.com/report/github.com/antonfisher/nested-logrus-formatter)
[![GoDoc](https://godoc.org/github.com/antonfisher/nested-logrus-formatter?status.svg)](https://godoc.org/github.com/antonfisher/nested-logrus-formatter)Human-readable log formatter, converts _logrus_ fields to a nested structure:
![Screenshot](https://raw.githubusercontent.com/antonfisher/nested-logrus-formatter/docs/images/demo.png)
## Configuration:
```go
type Formatter struct {
// FieldsOrder - default: fields sorted alphabetically
FieldsOrder []string// TimestampFormat - default: time.StampMilli = "Jan _2 15:04:05.000"
TimestampFormat string// HideKeys - show [fieldValue] instead of [fieldKey:fieldValue]
HideKeys bool// NoColors - disable colors
NoColors bool// NoFieldsColors - apply colors only to the level, default is level + fields
NoFieldsColors bool// NoFieldsSpace - no space between fields
NoFieldsSpace bool// ShowFullLevel - show a full level [WARNING] instead of [WARN]
ShowFullLevel bool// NoUppercaseLevel - no upper case for level value
NoUppercaseLevel bool// TrimMessages - trim whitespaces on messages
TrimMessages bool// CallerFirst - print caller info first
CallerFirst bool// CustomCallerFormatter - set custom formatter for caller info
CustomCallerFormatter func(*runtime.Frame) string
}
```## Usage
```go
import (
nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/sirupsen/logrus"
)log := logrus.New()
log.SetFormatter(&nested.Formatter{
HideKeys: true,
FieldsOrder: []string{"component", "category"},
})log.Info("just info message")
// Output: Jan _2 15:04:05.000 [INFO] just info messagelog.WithField("component", "rest").Warn("warn message")
// Output: Jan _2 15:04:05.000 [WARN] [rest] warn message
```See more examples in the [tests](./tests/formatter_test.go) file.
## Development
```bash
# run tests:
make test# run demo:
make demo
```