Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Process Logging with log4j

Avatar

Level 1

I'd like to use log4j to do some logging from processes. 

I've used the following executeScript to test this in a process:

import org.apache.log4j.*;

System.out.println("Log4jExecuteScriptTest: Start of log4j messages");

Logger logger = Logger.getLogger("com.fletch.Log4jTest");


logger.trace("Log4jExecuteScriptTest: This is a TRACE message");
logger.debug("Log4jExecuteScriptTest: This is a DEBUG message");
logger.info("Log4jExecuteScriptTest: This is an INFO log message");
logger.warn("Log4jExecuteScriptTest: This is a WARN log message");
logger.error("Log4jExecuteScriptTest: This is an ERROR log message");

System.out.println("Log4jExecuteScriptTest: End of log4j messages");

SInce I'm doing this with the JBoss LC ES2.5 Turnkey I modified C:\Adobe\Adobe LiveCycle ES2\jboss\server\lc_turnkey\conf\jboss-log4j.xml to add an appender and category for com.fletch.Log4jTest:

  <!-- A time/date based rolling appender for specifc log messages -->
   <appender name="Log4jTest_FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
      <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
      <param name="File" value="${jboss.server.log.dir}/Log4jTest.log"/>
      <param name="Threshold" value="TRACE"/>
      <param name="Append" value="false"/>

      <!-- Rollover at midnight each day -->
      <param name="DatePattern" value="'.'yyyy-MM-dd"/>

      <!-- Rollover at the top of each hour
      <param name="DatePattern" value="'.'yyyy-MM-dd-HH"/>
      -->

      <layout class="org.apache.log4j.PatternLayout">
         <!-- The default pattern: Date Priority [Category] Message\n -->
         <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>

         <!-- The full pattern: Date MS Priority [Category] (Thread:NDC) Message\n
         <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%x) %m%n"/>
          -->
      </layout>
     
   </appender>
<!-- Limit the com.fletch.Log4jTest category to TRACE for a test -->
   <category name="com.fletch.Log4jTest">
      <priority value="TRACE"/>
     <appender-ref ref="Log4jTest_FILE"/>
   </category>

This way my log4j entries for com.fletch.Log4jTest end up in C:\Adobe\Adobe LiveCycle ES2\jboss\server\lc_turnkey\log\Log4jTest.log:

2013-02-05 13:22:56,508 TRACE [com.fletch.Log4jTest] Log4jExecuteScriptTest: This is a TRACE message
2013-02-05 13:22:56,509 DEBUG [com.fletch.Log4jTest] Log4jExecuteScriptTest: This is a DEBUG message
2013-02-05 13:22:56,509 INFO  [com.fletch.Log4jTest] Log4jExecuteScriptTest: This is an INFO log message
2013-02-05 13:22:56,510 WARN  [com.fletch.Log4jTest] Log4jExecuteScriptTest: This is a WARN log message
2013-02-05 13:22:56,510 ERROR [com.fletch.Log4jTest] Log4jExecuteScriptTest: This is an ERROR log message

I'm thinking of building this as either a logging subprocess using executeScript or a Java component.  Which would be the preferred way to do this?

Any additional information on this would be appreciated.

Thanks,

Steve Fletcher

0 Replies