Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

JSON Output

For DCAE components using log4j as the logger, update the log4j.xml file CONSOLE appender layout accordingly:

<JsonLayout eventEOL="true" compact="true" stacktraceAsString="true" properties="true" propertiesAsList="true">
        <KeyValuePair key="logTimeStamp" value="$${date:yyyy-MM-dd HH:mm:ss:-null}" />
        <KeyValuePair key="logTypeName" value="$${event:Logger:-null}" />
        <KeyValuePair key="logLevel" value="$${event:Level:-null}" />
        <KeyValuePair key="traceId" value="${:-null}" />
        <KeyValuePair key="statusCode" value="${:-null}" />
        <KeyValuePair key="principalId" value="${:-vescollector}" />
        <KeyValuePair key="serviceName" value="${k8s:containerName:-vescollector}" />
        <KeyValuePair key="exception" value="$${event:Exception:-None}" />
        <KeyValuePair key="PID" value="$${sys:pid:-null}" />
 </JsonLayout>


The final block should look like:


The runtime dependencies needed in pom.xml should already be there if the project has log4j, but they can be found here – https://logging.apache.org/log4j/2.x/runtime-dependencies.html


Once the XML files are updated, you should be able to rebuild the application and see the logs reflected in STDOUT. 


A POC with VES Collector can be found here: https://gerrit.onap.org/r/c/dcaegen2/collectors/ves/+/132585


String Output

Log4j has the capability of providing these fields in the normal output of just a string too. Here is some documentation on the tags that are available out of the box with log4j: https://logging.apache.org/log4j/2.x/manual/lookups.html https://www.tutorialspoint.com/log4j/log4j_patternlayout.htm

  • No labels