-
Notifications
You must be signed in to change notification settings - Fork 76
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
Add support for service.environment #184
Conversation
💚 CLA has been signed |
@odin568 thanks for your contribution! This makes a lot of sense to me. |
Hi, |
Please make sure that the email address you're using to sign the CLA is also registered in your GitHub settings (https://github.com/settings/emails). |
Valid Point. I re-signed it, no Mail so far. |
I can see you in the system with two different email addresses now. However, the mail used in your git config (see https://github.com/elastic/ecs-logging-java/pull/184.patch) is a different one. |
Allright, now you should have three :) |
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.
Looks great, thanks!
A couple of minor space removals, plus one request to make sure we do not add platform-specific assertion to tests
jul-ecs-formatter/src/main/java/co/elastic/logging/jul/EcsFormatter.java
Outdated
Show resolved
Hide resolved
log4j-ecs-layout/src/main/java/co/elastic/logging/log4j/EcsLayout.java
Outdated
Show resolved
Hide resolved
log4j2-ecs-layout/src/main/java/co/elastic/logging/log4j2/EcsLayout.java
Outdated
Show resolved
Hide resolved
@@ -50,7 +50,7 @@ void testLogException() throws Exception { | |||
assertThat(log.get("error.stack_trace").isArray()).isTrue(); | |||
ArrayNode arrayNode = (ArrayNode) log.get("error.stack_trace"); | |||
assertThat(arrayNode.size()).isEqualTo(4); | |||
assertThat(arrayNode.get(0).textValue()).isEqualTo("java.lang.NumberFormatException: For input string: \"NOT_AN_INT\""); | |||
assertThat(arrayNode.get(0).textValue()).isEqualTo("java.lang.NumberFormatException: For input string: \"NOT_AN_INT\"\r"); |
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.
Looks platform-specific. Does this fail for you without that?
If so, better to change to use startsWith
or regex comparison instead
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.
Test on CI (Ubuntu 18) fails with:
[2022-05-01T12:33:28.698Z] Failed tests:
[2022-05-01T12:33:28.698Z] EcsLayoutWithStackTraceAsArrayTest.testLogException:53
[2022-05-01T12:33:28.698Z] Expecting:
[2022-05-01T12:33:28.698Z] <"java.lang.NumberFormatException: For input string: "NOT_AN_INT"">
[2022-05-01T12:33:28.698Z] to be equal to:
[2022-05-01T12:33:28.698Z] <"java.lang.NumberFormatException: For input string: "NOT_AN_INT"
">
[2022-05-01T12:33:28.698Z] but was not.
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.
Yes, it fails on Windows otherwise. Added a trim before, should be platform-independent then.
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.
I don't think this is an issue in the tests but a bug here:
ecs-logging-java/ecs-logging-core/src/main/java/co/elastic/logging/EcsJsonSerializer.java
Line 39 in b09574f
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\n"); |
It always splits on \n
instead of depending on the platform.
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.
You are right. That's why I got \r at the end. Wondered about mac style... but is clear if it splitted by \n.
Generalized it in latest commit and removed the .trim() again.
...2-ecs-layout/src/test/java/co/elastic/logging/log4j2/EcsLayoutWithStackTraceAsArrayTest.java
Outdated
Show resolved
Hide resolved
logback-ecs-encoder/src/main/java/co/elastic/logging/logback/EcsEncoder.java
Outdated
Show resolved
Hide resolved
/test |
I applied changes you mentioned. Thanks for feedback! |
\r\n was splitted only by \n which is problematic on windows. Generalized to use \R which matches all combinations of line breaks.
@@ -36,7 +36,7 @@ public class EcsJsonSerializer { | |||
private static final TimestampSerializer TIMESTAMP_SERIALIZER = new TimestampSerializer(); | |||
private static final ThreadLocal<StringBuilder> messageStringBuilder = new ThreadLocal<StringBuilder>(); | |||
private static final String NEW_LINE = System.getProperty("line.separator"); | |||
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\n"); | |||
private static final Pattern NEW_LINE_PATTERN = Pattern.compile("\\R"); |
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.
\R
has been introduced in Java 8 so this won't work with older Java versions which this library is compatible with.
You could either use the equivalent of \R
(\u000D\u000A|[\u000A\u000B\u000C\u000D\u0085\u2028\u2029]
) or the more simple alternative "\\r?\\n"
which should cover most relevant cases (ignores Mac OS 9 style \r
, though).
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.
ah okay, was not aware that < Java 8 is supported still. Yes then let's make it right. The pattern I like as it is simple to read is \r\n|\n|\r - covers all cases for a single newline. Will update
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.
LGTM, thanks!
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.
Thanks!
As an extension of #168
We are hosting different environments of our applications, i.e. dev, test and of course prod.
In order to distinguish logs, we set the service.environment field. With this change it is easier to achieve.
Please review and feel free to merge.