MCPcopy Index your code
hub / github.com/antonfisher/nested-logrus-formatter

github.com/antonfisher/nested-logrus-formatter @v1.3.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.3.1 ↗ · + Follow
21 symbols 33 edges 3 files 2 documented · 10% 2 cross-repo links updated 3y agov1.3.1 · 2021-03-09★ 1671 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

nested-logrus-formatter

Build Status Go Report Card GoDoc

Human-readable log formatter, converts logrus fields to a nested structure:

Screenshot

Configuration:

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

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 message

log.WithField("component", "rest").Warn("warn message")
// Output: Jan _2 15:04:05.000 [WARN] [rest] warn message

See more examples in the tests file.

Development

# run tests:
make test

# run demo:
make demo

Core symbols most depended-on inside this repo

writeField
called by 3
formatter.go
writeCaller
called by 2
formatter.go
printDemo
called by 2
example/main.go
writeFields
called by 1
formatter.go
writeOrderedFields
called by 1
formatter.go
getColorByLevel
called by 1
formatter.go
Format
called by 0
formatter.go
main
called by 0
example/main.go

Shape

Function 15
Method 5
Struct 1

Languages

Go100%

Modules by API surface

tests/formatter_test.go12 symbols
formatter.go7 symbols
example/main.go2 symbols

Used by 2 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add nested-logrus-formatter \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page