Skip to content
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

Context map feature #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Context map feature #65

wants to merge 3 commits into from

Conversation

ntvf
Copy link

@ntvf ntvf commented Feb 9, 2020

Inspired by Context Map feature from logstash-logback-encoder for adding event-specific custom fields to message.
Example:
Log line:
log.info("Service started in {} seconds", duration/1000, Collections.singletonMap("duration", duration));

Result:
{
"@timestamp": "2014-06-04T15:26:14.464+02:00",
"message": "Service started in 12 seconds",
"duration": 12368,
}

@knittl
Copy link

knittl commented Feb 9, 2020

Interesting take on this one. Does it support multiple "structured arguments" too or only a single map? I don't understand how the formatting of the map for the message itself works – wouldn't that be {duration=12} in the message?

@knittl
Copy link

knittl commented Feb 9, 2020

Nevermind, I saw only now that duration is passed once directly as argument and then as context map parameter.

@@ -23,6 +23,7 @@
private int maxQueueSize = 100 * 1024 * 1024;
private Authentication authentication;
private int maxMessageSize = -1;
private boolean enableContextMap;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your indentation in this MR seems to be off (inconsistent use of tabs and spaces)

if (arguments == null || arguments.length == 0) return;
Object lastElement = arguments[arguments.length - 1];
if (lastElement instanceof Map) {
Map<String, Object> indexes = traverseObject(new HashMap<String, Object>(), "context", lastElement);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to call traverseMap directly here. It took me a bit to figure out why traverseObject is performing instanceof checks again, when lastElement is already guaranteed to be a map here.

cgoIT added a commit to cgoIT/logback-elasticsearch-appender that referenced this pull request Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants