Skip to content

Log data overriding/merging #101

Description

@zlondrej

I would expect a key included in localData to override a key that was added higher in the call stack.
I think in the ideal scenario, the objects would be deep merged and only non-object values would replace the previous values.

Program:

{- stack script
  --resolver lts-23.25
  --package log-base
-}

{-# LANGUAGE OverloadedStrings #-}

import Log
import Log.Backend.StandardOutput

main :: IO ()
main =
  withJsonStdOutLogger $ \logger ->
    runLogT "sandbox" logger LogTrace $
      localData ["object" .= object ["property1" .= (1 :: Int)]] $
        localData ["object" .= object ["property2" .= (2 :: Int)]] $ do
          logMessage LogInfo "Log entry 1" (object [])
          logMessage LogInfo "Log entry 2" (object ["object" .= object ["property3" .= (3 :: Int)]])

Output:

As you can see below, the first log message only includes property1, but not property2, which comes from localData deeper in the call stack.
But in the second log message, you can see that value passed to logMessage does override values provided by localData as it now has property3, but not property1 nor property2.

{"component":"sandbox","domain":[],"time":"2026-08-07T11:01:08.053971809Z","level":"info","message":"Log entry 1","data":{"object":{"property1":1}}}
{"component":"sandbox","domain":[],"time":"2026-08-07T11:01:08.05401287Z","level":"info","message":"Log entry 2","data":{"object":{"property3":3}}}

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