-
Notifications
You must be signed in to change notification settings - Fork 90
feat: Json layout modern implementation #670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2150743
feat: Modern way of configuring json layout via JsonTemplateLayout
pankajagrawal16 d04932e
feat: Sample ECSLayout with powertools preconfigured
pankajagrawal16 01dbd30
docs: Modern way of configuring json layout via JsonTemplateLayout
pankajagrawal16 3063711
chore: Move modern plugins to internal package
pankajagrawal16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
51 changes: 51 additions & 0 deletions
51
.../src/main/java/software/amazon/lambda/powertools/logging/internal/PowertoolsResolver.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package software.amazon.lambda.powertools.logging.internal; | ||
|
||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.layout.template.json.resolver.EventResolver; | ||
import org.apache.logging.log4j.layout.template.json.util.JsonWriter; | ||
import org.apache.logging.log4j.util.ReadOnlyStringMap; | ||
|
||
final class PowertoolsResolver implements EventResolver { | ||
|
||
private final EventResolver internalResolver; | ||
|
||
PowertoolsResolver() { | ||
internalResolver = new EventResolver() { | ||
@Override | ||
public boolean isResolvable(LogEvent value) { | ||
ReadOnlyStringMap contextData = value.getContextData(); | ||
return null != contextData && !contextData.isEmpty(); | ||
} | ||
|
||
@Override | ||
public void resolve(LogEvent logEvent, JsonWriter jsonWriter) { | ||
StringBuilder stringBuilder = jsonWriter.getStringBuilder(); | ||
// remove dummy field to kick inn powertools resolver | ||
stringBuilder.setLength(stringBuilder.length() - 4); | ||
|
||
// Inject all the context information. | ||
ReadOnlyStringMap contextData = logEvent.getContextData(); | ||
contextData.forEach((key, value) -> { | ||
jsonWriter.writeSeparator(); | ||
jsonWriter.writeString(key); | ||
stringBuilder.append(':'); | ||
jsonWriter.writeValue(value); | ||
}); | ||
} | ||
}; | ||
} | ||
|
||
static String getName() { | ||
return "powertools"; | ||
} | ||
|
||
@Override | ||
public void resolve(LogEvent value, JsonWriter jsonWriter) { | ||
internalResolver.resolve(value, jsonWriter); | ||
} | ||
|
||
@Override | ||
public boolean isResolvable(LogEvent value) { | ||
return internalResolver.isResolvable(value); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...in/java/software/amazon/lambda/powertools/logging/internal/PowertoolsResolverFactory.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package software.amazon.lambda.powertools.logging.internal; | ||
|
||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
import org.apache.logging.log4j.layout.template.json.resolver.EventResolverContext; | ||
import org.apache.logging.log4j.layout.template.json.resolver.EventResolverFactory; | ||
import org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver; | ||
import org.apache.logging.log4j.layout.template.json.resolver.TemplateResolverConfig; | ||
import org.apache.logging.log4j.layout.template.json.resolver.TemplateResolverFactory; | ||
|
||
@Plugin(name = "PowertoolsResolverFactory", category = TemplateResolverFactory.CATEGORY) | ||
public final class PowertoolsResolverFactory implements EventResolverFactory { | ||
|
||
private static final PowertoolsResolverFactory INSTANCE = new PowertoolsResolverFactory(); | ||
|
||
private PowertoolsResolverFactory() {} | ||
|
||
@PluginFactory | ||
public static PowertoolsResolverFactory getInstance() { | ||
return INSTANCE; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return PowertoolsResolver.getName(); | ||
} | ||
|
||
@Override | ||
public TemplateResolver<LogEvent> create(EventResolverContext context, | ||
TemplateResolverConfig config) { | ||
return new PowertoolsResolver(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
powertools-logging/src/main/resources/LambdaEcsLayout.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"@timestamp": { | ||
"$resolver": "timestamp", | ||
"pattern": { | ||
"format": "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", | ||
"timeZone": "UTC" | ||
} | ||
}, | ||
"ecs.version": "1.2.0", | ||
"log.level": { | ||
"$resolver": "level", | ||
"field": "name" | ||
}, | ||
"message": { | ||
"$resolver": "message", | ||
"stringified": true | ||
}, | ||
"process.thread.name": { | ||
"$resolver": "thread", | ||
"field": "name" | ||
}, | ||
"log.logger": { | ||
"$resolver": "logger", | ||
"field": "name" | ||
}, | ||
"labels": { | ||
"$resolver": "mdc", | ||
"flatten": true, | ||
"stringified": true | ||
}, | ||
"tags": { | ||
"$resolver": "ndc" | ||
}, | ||
"error.type": { | ||
"$resolver": "exception", | ||
"field": "className" | ||
}, | ||
"error.message": { | ||
"$resolver": "exception", | ||
"field": "message" | ||
}, | ||
"error.stack_trace": { | ||
"$resolver": "exception", | ||
"field": "stackTrace", | ||
"stackTrace": { | ||
"stringified": true | ||
} | ||
}, | ||
"": { | ||
"$resolver": "powertools" | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to actually have that default to UTC unless overridden?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rite now the behaviour is consistent with existing implementation, meaning it will pick system default timezone. But with new approach, users have ability to customise timezone if need be, which was not possible before.