1. Ability to set the logging level dynamically at runtime without changing your scripts i.e. you can write debug logging into scripts then activate it when you need to, and only for selected scripts.
2. Ability to write to log files or the console or both.
3. Formatted log messages.
4. Multi-user access without file locking problems.
5. Once configured, it can be used by all scripts with the ability to control debugging messages by script, form, project etc.
6. The ability to wrap log files i.e. to stop them growing indefinitely.
7. It's pretty much a de facto standard and is used throughout the Java world.
See http://logging.apache.org/log4j for details.
Here are the steps to configure log4j for use by Ebase scripts:
Step 1: configure the log4j properties file
You only need to do this step once only, then it can be used by all scripts.
Edit file UfsServer/tomcat/webapps/xxx/WEB_INF/classes/log4j.xml on the server and add the following at the bottom, but before the ending </log4j:configuration> tag:
Code: Select all
<appender name="scriptsLog" class="org.apache.log4j.FileAppender">
<param name="file" value="../logs/ebasescripts.log" />
<param name="append" value="false" />
<param name="threshold" value="debug" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n"/>
</layout>
</appender>
<logger name="ebforms" additivity="false">
<level value="ALL" />
<appender-ref ref="scriptsLog"/>
</logger>
It also creates a logger, which is the component that actually does the logging - we will be using this logger from the scripts. The logger names are hierarchical: this one is named "ebforms" and it will be used by anything that requests a logger beginning with this name e.g. a request for a logger "ebforms.project1.script23" will also use this logger. This hierarchical behaviour is one of the features that makes log4j so flexible, hopefully it will become a bit clearer in a moment.
Step 2: restart the server
This is unfortunately necessary and activates the log4j configuration just created.
Step 3: add logging to your scripts
To do this, add the following two lines to each script where you want to use logging:
Code: Select all
importPackage(org.apache.log4j);
var logger = Logger.getLogger("ebforms.project1.js1c");
You can then create a log message with any of the following.
Code: Select all
logger.debug("A debug message");
logger.info("An info message");
logger.error("An error message");
logger.log(Level.INFO, "Another message");
<level value="INFO" />
That's all you need to start logging with log4j.