encoredev / encore

Open Source Development Platform for building robust type-safe distributed systems with declarative infrastructure
https://encore.dev
Mozilla Public License 2.0
7.76k stars 330 forks source link

Defining multiple loggers from a single Rlog.With() with the same key leads to malformed log outputs on the CLI #1572

Closed HectorMalot closed 1 week ago

HectorMalot commented 1 week ago

Issue: When defining multiple loggers derived from the same rlog.With("key","value") with the same key having multiple values, the output on the CLI is malformed. A minimal working example based on the hello world template:

package hello

import (
    "context"
    "encore.dev/rlog"
)

//encore:api public path=/hello/:name
func World(ctx context.Context, name string) (*Response, error) {
    logger := rlog.With("service", "hello")
    logger.Info("Saying hello to " + name)

    sublog1 := logger.With("module", "longnamemodule")
    sublog2 := logger.With("module", "midnamemod")
    sublog3 := logger.With("module", "shortmod")

    sublog1.Info("This is a long module name")
    sublog2.Info("This is a mid module name")
    sublog3.Info("This is a short module name")

    msg := "Hello, " + name + "!"
    return &Response{Message: msg}, nil
}

type Response struct {
    Message string
}

This results in a garbled output for sublog1 and sublog2, as the initial parts "longnamemodule" will be overwritten with "shortmod"d"ule" and "shortmod"d"" respectively.

image