8000 Using AddSource option displays wrapping function · Issue #1 · go-swiss/slog-strict · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Using AddSource option displays wrapping function #1
Open
@travbale

Description

@travbale

When using a slog-strict logger with a slog.Handler that sets AddSource in slog.HandlerOptions the added source block displays the slog-strict wrapping function as the source as opposed to the caller.

Example:

package main

import (
	"context"
	"log/slog"
	"os"

	slogstrict "github.com/go-swiss/slog-strict"
)

func main() {
	logger := slogstrict.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{AddSource: true}))
	logger.Info(context.Background(), "test")
}

Outputs:

{
    "time": "2023-11-22T13:03:55.879954-05:00",
    "level": "INFO",
    "source": {
        "function": "github.com/go-swiss/slog-strict.logger.Info",
        "file": "/Users/travbale/go/pkg/mod/github.com/go-swiss/slog-strict@v0.0.0-20231026122839-ccffde83385b/slogstrict.go",
        "line": 56
    },
    "msg": "test"
}

The function indicated as the source of the call is slog-strict.logger.Info rather than main.

The slog documentation calls out how wrappers should properly handle this logic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0