Honor IncludeCategory in the JSON log format#2474
Open
TemRevil wants to merge 1 commit into
Open
Conversation
In text format the ILogger category is written on every line when LambdaLoggerOptions.IncludeCategory is true (the default), but the JSON branch of LambdaILogger.Log never emitted the category, so migrating a function from text to JSON logging silently lost it with no way to opt back in (aws#2469). When IncludeCategory is set, prepend a {Category} placeholder to the message template and supply the category value, so it surfaces as a queryable property in the JSON record instead of being dropped. Text format is unchanged, and JSON output is unchanged when IncludeCategory is false. Fixes aws#2469
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2469
Problem
With
Amazon.Lambda.Logging.AspNetCore, theILoggercategory is written on every line in text format whenLambdaLoggerOptions.IncludeCategoryis true (which is the default). The JSON branch ofLambdaILogger.Log, however, only forwards the message template and its arguments and never emits the category, soIncludeCategoryis silently ignored in JSON mode. Migrating a function from text to JSON logging drops the category entirely, with no way to opt back in.Change
When
IncludeCategoryis set, the JSON branch now prepends a{Category}placeholder to the message template and supplies the category as the matching argument. Because the JSON formatter turns named template parameters into top-level properties, the category surfaces as a queryable property (and in the rendered message), matching the parity the text format already provides.IncludeCategory = false: unchanged (no extra property, same parameter count).IncludeCategory = true: the category is included.This follows the reporter's suggested "at minimum honor IncludeCategory" approach and needs no runtime-side change. If the maintainers would rather expose it as a dedicated top-level
categoryfield emitted byJsonLogMessageFormatter(the issue's preferred option), I'm happy to take that direction instead.Testing
Amazon.Lambda.Logging.AspNetCore.Testson net10.0:Passed! Failed: 0, Passed: 16. AddedTestJSONParameterLoggingIncludesCategoryWhenEnabled(category present, parameter count goes 3 to 4) andTestJSONParameterLoggingOmitsCategoryWhenDisabled(no category, count stays 3); the existingTestJSONParameterLoggingstill passes since it usesIncludeCategory = false.