Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
xiaofang li
Logging Log4j2
Commits
3fb0a422
Commit
3fb0a422
authored
3 years ago
by
Volkan Yazici
Browse files
Options
Download
Email Patches
Plain Diff
LOG4J2-3116 Fix stack trace dumps.
parent
0448aa9b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
log4j-layout-template-json/src/main/resources/GcpLayout.json
+4
-6
log4j-layout-template-json/src/main/resources/GcpLayout.json
log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GcpLayoutTest.java
+16
-22
...che/logging/log4j/layout/template/json/GcpLayoutTest.java
src/changes/changes.xml
+1
-1
src/changes/changes.xml
with
21 additions
and
29 deletions
+21
-29
log4j-layout-template-json/src/main/resources/GcpLayout.json
+
4
-
6
View file @
3fb0a422
...
...
@@ -14,7 +14,8 @@
},
"message"
:
{
"$resolver"
:
"pattern"
,
"pattern"
:
"%m"
"pattern"
:
"%m"
,
"stackTraceEnabled"
:
true
},
"logging.googleapis.com/labels"
:
{
"$resolver"
:
"mdc"
,
...
...
@@ -49,11 +50,8 @@
"field"
:
"message"
},
"stackTrace"
:
{
"$resolver"
:
"exception"
,
"field"
:
"stackTrace"
,
"stackTrace"
:
{
"stringified"
:
true
}
"$resolver"
:
"pattern"
,
"pattern"
:
"%xEx"
}
},
"_thread"
:
{
...
...
This diff is collapsed.
Click to expand it.
log4j-layout-template-json/src/test/java/org/apache/logging/log4j/layout/template/json/GcpLayoutTest.java
+
16
-
22
View file @
3fb0a422
...
...
@@ -22,8 +22,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import
org.junit.jupiter.params.provider.Arguments
;
import
org.junit.jupiter.params.provider.MethodSource
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintWriter
;
import
java.time.Instant
;
import
java.time.ZoneId
;
import
java.time.ZonedDateTime
;
...
...
@@ -100,12 +98,18 @@ class GcpLayoutTest {
assertThat
(
accessor
.
getString
(
"severity"
)).
isEqualTo
(
expectedSeverity
);
// Verify message.
final
String
expectedMessage
=
logEvent
.
getMessage
().
getFormattedMessage
();
assertThat
(
accessor
.
getString
(
"message"
)).
contains
(
expectedMessage
);
final
String
expectedExceptionStackTrace
;
final
Throwable
exception
=
logEvent
.
getThrown
();
if
(
exception
!=
null
)
{
final
String
expectedExceptionMessage
=
exception
.
getLocalizedMessage
();
assertThat
(
accessor
.
getString
(
"message"
)).
contains
(
expectedExceptionMessage
);
final
String
actualMessage
=
accessor
.
getString
(
"message"
);
assertThat
(
actualMessage
)
.
contains
(
logEvent
.
getMessage
().
getFormattedMessage
())
.
contains
(
exception
.
getLocalizedMessage
())
.
contains
(
"at org.apache.logging.log4j.layout.template.json"
)
.
contains
(
"at java.util.stream.ForEachOps"
)
.
contains
(
"at org.junit.platform.engine"
);
}
else
{
expectedExceptionStackTrace
=
null
;
}
// Verify labels.
...
...
@@ -170,11 +174,12 @@ class GcpLayoutTest {
.
isEqualTo
(
exception
.
getMessage
());
// Verify exception stack trace.
final
String
expectedExceptionStackTrace
=
serializeThrowableStackTrace
(
exception
);
assertThat
(
accessor
.
getString
(
new
String
[]{
"_exception"
,
"stackTrace"
}))
.
isEqualTo
(
expectedExceptionStackTrace
);
.
contains
(
exception
.
getLocalizedMessage
())
.
contains
(
"at org.apache.logging.log4j.layout.template.json"
)
.
contains
(
"at java.util.stream.ForEachOps"
)
.
contains
(
"at org.junit.platform.engine"
);
}
else
{
assertThat
(
accessor
.
getObject
(
...
...
@@ -183,9 +188,9 @@ class GcpLayoutTest {
assertThat
(
accessor
.
getObject
(
new
String
[]{
"_exception"
,
"message"
}))
.
isNull
();
assertThat
(
accessor
.
get
Object
(
assertThat
(
accessor
.
get
String
(
new
String
[]{
"_exception"
,
"stackTrace"
}))
.
is
Null
();
.
is
Empty
();
}
// Verify thread name.
...
...
@@ -207,15 +212,4 @@ class GcpLayoutTest {
return
DATE_TIME_FORMATTER
.
format
(
dateTime
);
}
private
static
String
serializeThrowableStackTrace
(
final
Throwable
throwable
)
{
try
(
final
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
final
PrintWriter
writer
=
new
PrintWriter
(
outputStream
))
{
throwable
.
printStackTrace
(
writer
);
writer
.
flush
();
return
outputStream
.
toString
(
LAYOUT
.
getCharset
().
name
());
}
catch
(
final
Exception
error
)
{
throw
new
RuntimeException
(
error
);
}
}
}
This diff is collapsed.
Click to expand it.
src/changes/changes.xml
+
1
-
1
View file @
3fb0a422
...
...
@@ -31,7 +31,7 @@
-->
<release
version=
"2.15.0"
date=
"2021-MM-DD"
description=
"GA Release 2.15.0"
>
<!-- ADDS -->
<action
issue=
"LOG4J2-3116"
dev=
"rgupta"
>
<action
issue=
"LOG4J2-3116"
dev=
"rgupta"
type=
"add"
>
Add GCP logging layout.
</action>
<action
issue=
"LOG4J2-3067"
dev=
"vy"
type=
"add"
>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment