MCPcopy Index your code
hub / github.com/Trendyol/overlog

github.com/Trendyol/overlog @v0.1.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.1.2 ↗ · + Follow
93 symbols 616 edges 10 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Overlog

Golang Logging with Mapped Diagnostic Context

What is it?

This package is Zerolog wrapper with Mapped Diagnostic Context structure like Sl4j.

Installation

go get -u github.com/Trendyol/overlog

Getting Started

over.New() and over.NewDefault() initialize global log field. You can use over.Log() from anywhere after initialize.

Quick start:

package main

import (
    over "github.com/Trendyol/overlog"
)

func main() {
    over.NewDefault()
    over.MDC().Set("x-correlation-id", "1234")
    over.MDC().Set("x-agent-name", "trendyol.com")
    over.SetGlobalFields([]string{"x-correlation-id", "x-agent-name"})

    over.Log().Info("hello world")
}

// Output: {"level":"INFO","time":"2020-05-20 13:02:10,000","source":"overlog/overlogger.go:70","x-agent-name":"trendyol","x-correlation-id":"1234","message":"hello world"}

You can set your own zerolog settings.

package main

import (
    over "github.com/Trendyol/overlog"
    "github.com/rs/zerolog"
    "os"
)

func main() {
    zlogger := zerolog.New(os.Stderr).With().Str("foo", "bar").Logger()
    over.New(zlogger)
    over.MDC().Set("x-correlation-id", "1234")
    over.AddGlobalFields("x-correlation-id")

    over.Log().Info("hello world")
}

// Output: {"level":"info","foo":"bar","x-correlation-id":"1234","message":"hello world"}

Audition middleware example for echo

func main() {
    ...
    over.NewDefault()
    over.SetGlobalFields([]string{"x-agent-name", "x-correlation-id"})
    ...
}
func AuditionPreHandler(next echo.HandlerFunc) echo.HandlerFunc {
    return func(c echo.Context) error {
        var agentName = c.Request().Header.Get("x-agent-name")
        if agentName == "" {
            agentName = a.instance.Config().Host
        }
        over.MDC().Set("x-agent-name", agentName)

        var correlationId = c.Request().Header.Get("x-correlation-id")
        if correlationId == "" {
            correlationId = uuid.New().String()
        }
        over.MDC().Set("x-correlation-id", correlationId)

        return next(c)
    }
}
func (a *Application) AuditionAfterCompletion(next echo.HandlerFunc) echo.HandlerFunc {
    return func(c echo.Context) error {
        c.Response().After(func() {
            over.MDC().Remove("x-agent-name")
            over.MDC().Remove("x-correlation-id")
        })
        return next(c)
    }
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.

License

MIT

Core symbols most depended-on inside this repo

MDC
called by 55
mdc.go
New
called by 40
overlogger.go
Log
called by 39
overlogger.go
Set
called by 34
mdc.go
Run
called by 28
mdc_hook.go
SetGlobalFields
called by 16
fields.go
message
called by 16
overlogger.go
AddGlobalFields
called by 15
fields.go

Shape

Function 60
Method 30
Struct 3

Languages

Go100%

Modules by API surface

overlogger.go24 symbols
overlogger_example_test.go15 symbols
mdc.go15 symbols
overlogger_test.go13 symbols
mdc_test.go10 symbols
encoder.go5 symbols
fields_test.go4 symbols
fields.go4 symbols
mdc_hook.go2 symbols
goroutine.go1 symbols

For agents

$ claude mcp add overlog \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact