I\'m trying to get additional fields to log with log4j, and its working but only when I create an appender in code and not in the log4j.properties
I'm not sure that you will achieve this with properties configuration, but I think you can do this with XML, which gives you a lot of customization options:
You will need to define setters on AppServerLoggerFactory
for server, component and version. Also, read log4j.dtd
on general layout of xml configuration file.
Save this file as log4j.xml and define -Dlog4j.configuration=/path/to/log4j.xml in your startup script, or replace log4j.properties with log4j.xml in your web-app.
I've never tried a custom LoggerFactory before, but it may be that because it is installed by the configurator you can use standard getLogger
factory calls, e.g.
//Logger logger = AppServerLogger.getLogger("some.log");
Logger logger = Logger.getLogger("some.log");