Log4j logs not getting entered

Hello,

Could you please assist me for the below query?

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.

Could anyone please assist me on this.

Many thanks in Advance.!

Abhiram.

Hey Abhiram,

It’s difficult to help without seeing the implementation.

  • I assume you’re confident the logj2.xml config is being loaded, as that driving the creation of the log files correctly?
  • Are the log entries going to the console?
  • Do you have appenders writing to you logs?

If none of that helps you move forward, could you:

  1. Paste the java service code in a reply (using preformatted text)?
  2. Let us know which version of IS it is?
  3. Paste your log xml config file?
1 Like

Hi Dave,

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)

log msg java service.txt (852 Bytes)

Thanks,
Abhiram.

Hi Dave,

Can you please have a look at it and let me know what’s going wrong?
Sorry to follow up on this. Its a bit a emergency thing for me to complete.

Many Thanks.

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.

Hello,

I had a similar problem and putting the following:

<value name="classloader">package</value>

in the manifest.v3 file did the trick.

You can try it and let us know.

1 Like

Hello,

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?

Many thanks for the responses .

Cheers!!
Abhiram.

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.

NSService parent = Service.getCallingService();
if (parent == null) {
     parent = Service.getServiceEntry();
}

String parentPackage = parent.getPackage().getName();
                
if (loggerName == null || loggerName.isEmpty()) {
     loggerName = parent.getPackage().getName() + "." + parent.toString().replace(':', '.');
}

Hi Dave/Vlad,

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.

Thanks for the support and quick responses.

Cheers!!
Abhiram.

1 Like

Hello Dave/Vlad,

Greetings!! Hope you are good.

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) .

Could you please assist me on this ?

Many Thanks,
Abhiram.

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?

Thanks,
Abhiram.