apache / logging-log4j2

Apache Log4j 2 is a versatile, feature-rich, efficient logging API and backend for Java.
https://logging.apache.org/log4j/2.x/
Apache License 2.0
3.28k stars 1.55k forks source link

JsonTemplateLayout: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space #2516

Open PassiveIncomeMachine opened 3 weeks ago

PassiveIncomeMachine commented 3 weeks ago

Constructor ERROR Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLayout for element JsonTemplateLayout: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space

Here is what I have configured.

<Console name="CONSOLE-OUTPUT" target="SYSTEM_OUT">
    <JsonTemplateLayout eventTemplateUri="classpath:Layout.json" maxStringLength="10000000">
        <EventTemplateAdditionalField key="appName" value="AA" />
        <EventTemplateAdditionalField key="appenderName" value="OUTPUT" />
        <EventTemplateAdditionalField key="consoleLogIdentifier" value="LOG-IDENTIFIER"/>
    </JsonTemplateLayout>
    <Filters>
        <RegexFilter regex="(?s).*AvailabilityReport.*"
            useRawMsg="true" onMatch="ACCEPT" onMismatch="NEUTRAL" />
        <RegexFilter regex="(?s).*OccupancyReport.*"
            useRawMsg="true" onMatch="ACCEPT" onMismatch="DENY" />
    </Filters>
</Console>

Configuration

Version: 2.23.1

Operating system: Red Hat Enterprise Linux release 8.4 (Ootpa)

JDK: openjdk version "11.0.13" 2021-10-19 LTS

Logs

2024-04-23 12:00:26,623 Constructor ERROR Could not create plugin of type class org.apache.logging.log4j.layout.template.json.JsonTemplateLayout for element JsonTemplateLayout: java.lang.OutOfMemoryError: Java heap space java.lang.OutOfMemoryError: Java heap space
vy commented 3 weeks ago

@PassiveIncomeMachine, could you share the following information too, please?

  1. A complete stack trace (pointing to some line numbers in the org.apache.logging.log4j package, etc.)
  2. Layout.json file

For the record, maxStringLength="10000000" looks dangerous to me. Note that it doesn't limit the total JSON document length, but the maximum length of a String-typed field in the JSON document. I would try to keep it way lower.

PassiveIncomeMachine commented 12 hours ago

Thanks VY please check my TPLayout.json file TPLayout.json

and also attach my send message `<?xml version="1.0" encoding="utf-8" ?>

true 2023-03-29T03:16:30.000Z RTP29031616 1274612422 0 0 0 NAL 80 Coding AA90 521 0 0 4 RULE-1000000001-01 RULE-1000000113-01 932942 Route 99 1 91000 10120 `