2

In a Maven project I've put the log4j.properties file in src\main\resources catalog which seems to be the usual place to put it in. However it does not appear to read it or there is a mistake I can't see as my logger doesn't print DEBUG level messages (it does print INFO level messages though) and doesn't create the logs.log file either. Here's the log4j.properties file I'm using:

# Root logger option
log4j.rootLogger=DEBUG, file, stdout

# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=D:/.../src/main/resources/META-INF/logs.log
log4j.appender.file.MaxFileSize=10MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

I've also tried to pass the path to the log4j.properties file in my run configuration but it didn't work either: -Dlog4j.configuration=file:D:/.../src/main/resources/log4j.properties This project is launched through a different bound project so I used the entire file path which might be incorrect as none of the examples I've seen had full paths provided.

The server we're using to run the app is Wildfly 8.1.0 which has it's own log4j logger so maybe that's interfering somehow?

Here's the part of my interceptor which should create logs:

final static Logger logger = Logger.getLogger(RestInterceptor.class);
...    
if(e instanceof ApplicationException) {
        logger.debug(e.getMessage(), e);
        //TODO remove these when done testing
        logger.debug("debug is working");
        logger.info("info is working");
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }

However only "info is working" is being printed.

Arqan
  • 376
  • 1
  • 3
  • 14
  • This is how I pass it in when I launch my client: -Dlog4j.configuration=file:///D:/dev/settings/log4j.agility.properties You're missing the '///' after the 'file:' in your example. Maybe that's it? – Craig Aug 13 '15 at 14:35
  • Also, make sure that the correct log provider is loaded in your maven dependency tree. I used to experience conflicts with that and I had to include for the dependencies which included a log provider. – Craig Aug 13 '15 at 14:38
  • I've added the '///' but unfortunately it didn't solve the problem. – Arqan Aug 13 '15 at 14:47

3 Answers3

0

Are you sure src\main\resources is on your buildpath?

Right-click on your project -> Java Build path [Source Tab]

Make sure the resource folder is on the buildpath. Also make sure the Excluded pattern = '**'

pmartin8
  • 1,545
  • 1
  • 20
  • 36
  • @Arquan, if your folder in on the buildpath, than you should add the information in your question. I don't like to see my answer voted down when I'm trying to help. – pmartin8 Aug 13 '15 at 17:21
  • I don't believe I can vote down with 1 reputation mate. Either way it wasn't me. – Arqan Aug 13 '15 at 18:12
  • 1
    @pmartin8 The reason you're downwoted (not by me, either) is that your post doesn't provide an answer, but requests for clarifications from the original poster. It should have been a comment. – gvlasov Aug 14 '15 at 10:35
  • 2
    I think this is a valid answer. "Check your build path" is a valid answer. It may be wrong but perfectly valid. – JCasso Aug 14 '15 at 12:26
  • My post was a possible answer, not a critique or a request. Chances are good that fixing the build path will solve the problem. Thanks. – pmartin8 Aug 14 '15 at 14:57
0

Alright so I managed to kind of fix the problem. It was caused by Wildfly's logger interfering with mine. I've added <use-deployment-logging-config value="false"/> line in standalone.xml But it was not enough. After digging some more I've also found and added the following line <add-logging-api-dependencies value="false"/> and it finally started working. While I'm not fully satisfied with this solution I guess it's still better than nothing and maybe it's worth sharing.

So in short, add this in your standalone.xml and it should resolve logging conflicts if you're using Wildfly 8:

<subsystem xmlns="urn:jboss:domain:logging:2.0"> <add-logging-api-dependencies value="false"/> <use-deployment-logging-config value="false"/> ... </subsystem>

Arqan
  • 376
  • 1
  • 3
  • 14
-1

update spring version. it works for me.

amal
  • 1