I have created java service to log use Log4j2 logging. I’ve placed the required JAR files and Logj2.xml files in the specific location.
I’m able to create log files by running the service but I’m not able not able to send/pass data into the log file. Even if I’m running the service for multiple times, logs are not being entered into the log file.
Thanks for the response.
I have attached both the files. Please have a look at it.
I’m able to run the service and then both the files are being created in the specified path given the Log4j2.XML file (given as IS path in the file). But the logs are not being entered in the created files.
I’m using 10.5.
Yes, I have appenders in the file.
I’m sry I don’t know whether logs are going to the console.
Please check and let me know if there is something wrong in the code or config file. Log4j2.xml (1.1 KB)
Apologies on the delay. Just looking now.
It’s writing to the console, but not to the log file for some reason thats not apparent.
I suspect this might be a clash with LOG4J v1.2 / sfl4j which is used by Integration Server/webMethods but would need time to dig further, and depends on what version of IS you’re running with.
Are you wedded to Log4J2 or could you consider some other logging framework?
I’ve seen a number of implementations use slf4j/logback for example.
I’ve got the cause for the issue. I’ve declared variable to initialize configurator differently in log message and get loggers services. Now I have corrected those and it seems to be working for me.
Files are getting created and logs are being entered.
But one thing is bothering me, Can we give the logger name dynamically rather than defining in the properties file? Cuz I’ve been trying giving the logger name dynamically which seems to be not working. Any suggestions for this?
You mean something like this, to dynamically set the logger name based on the service using it, where loggerName comes from the pipeline so you can override if needed, otherwise it’ll work it out it automatically.
I’ve tried something like this and it worked. Seems to be I’m with bit of luck.
I’m able to print the logger name dynamically by passing it in the service and then printing it in the log file.
Another requirement came up. We need to delete older log files to get deleted automatically (lets say more than 14 days) from the directory.
I’ve tried doing it using
< DefaultRolloverStrategy max=“< specify maximum archive count>”/>
and also
< DefaultRolloverStrategy>
< Delete basePath=“${baseDir}” maxDepth=“2”>
< IfFileName glob=“/app-.log” />
< IfLastModified age=“14d” />
< /Delete>
< /DefaultRolloverStrategy>
in the config file. But files are not getting deleted. I’ve attached the config file for your reference. Please go through it.log4j2 config file.txt (818 Bytes) .
I’m using the below xml file for deleting old files using defaultrolloverstrategy but unable to conquer it. I’m using glob to find the file and using lastmodified parameter to do this.
I’m attaching the file here. Please have a look.log4j2 config file.txt (846 Bytes)
Am I missing something here or doing it wrong?
Any advises?