angelokh
angelokh

Reputation: 9428

play 2.0 application on heroku print application logs

When I deploy Play 2 application to Heroku, I can see the following logs from 'heroku logs'.

2012-07-05T10:13:08+00:00 app[web.1]: Play server process ID is 3
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Class path contains multiple SLF4J bindings.
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Found binding in [jar:file:/app/target/staged/slf4j-log4j12-1.6.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Found binding in [jar:file:/app/target/staged/logback-classic-1.0.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2012-07-05T10:13:09+00:00 app[web.1]: log4j:WARN No appenders could be found for logger (com.jolbox.bonecp.BoneCPDataSource).
2012-07-05T10:13:09+00:00 app[web.1]: log4j:WARN Please initialize the log4j system properly.
2012-07-05T10:13:09+00:00 app[web.1]: log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

When I tried to print logs from Play application, I was no able to get it from heroku log output. Here is my Play log config.

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

The log statement I used in Play 2 java classes:

play.Logger.debug("log output......");

UPDATE 1 This is what I did to resolve the multiple dependencies issues.

("com.jayway.facebooktestjavaapi" % "facebook-test-java-api" % "1.1.5" notTransitive()).exclude("org.slf4j", "slf4j-log4j12")

UPDATE 2 After I resolved above errors, the logs statements still NOT output to 'heroku logs'. So I follow here (https://github.com/playframework/Play20/wiki/SettingsLogger) to setup logger.xml. But it is still not output anything.

$ vi conf/application.conf
logger.resource=dev-logger.xml
db.default.logStatements=true

$ cat conf/dev-logger.xml 
<configuration>

  <conversionRule conversionWord="coloredLevel" converterClass="play.api.Logger$ColoredLevel" />

  <appender name="FILE" class="ch.qos.logback.core.FileAppender">
     <file>${application.home}/logs/application.log</file>
     <encoder>
       <pattern>%date - [%level] - from %logger in %thread %n%message%n%xException%n</pattern>
     </encoder>
   </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%coloredLevel %logger{15} - %message%n%xException{5}</pattern>
    </encoder>
  </appender>

  <logger name="play" level="TRACE" />
  <logger name="application" level="TRACE" />

  <root level="DEBUG">
    <appender-ref ref="STDOUT" />
    <appender-ref ref="FILE" />
  </root>

</configuration>

UPDATE 3 I revert everything back and use original application logs, but still not output.

# Root logger:
logger.root=DEBUG

# Logger used by the framework:
logger.play=DEBUG

# Logger provided to your application:
logger.application=DEBUG

# Logger ebean
logger.com.jolbox=DEBUG

Upvotes: 1

Views: 2058

Answers (1)

Pere Villega
Pere Villega

Reputation: 16439

If you read the Heroku logs, you'll notice that your log system is broken. First, you have multiple instances of SLF4J:

2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Class path contains multiple SLF4J bindings.
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Found binding in [jar:file:/app/target/staged/slf4j-log4j12-1.6.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
2012-07-05T10:13:08+00:00 app[web.1]: SLF4J: Found binding in [jar:file:/app/target/staged/logback-classic-1.0.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]

And second you don't have any appenders defined, which means your log messages won't be printed anywhere:

2012-07-05T10:13:09+00:00 app[web.1]: log4j:WARN No appenders could be found for logger (com.jolbox.bonecp.BoneCPDataSource).
2012-07-05T10:13:09+00:00 app[web.1]: log4j:WARN Please initialize the log4j system properly.

Fixing the first issue may solve also the second. Otherwise, fix the first issue (SLF4J) and then, if you are using custom logging configuration, verify that it's properly set up.

EDIT on update: Please remove your custom 'logger.xml' and reupload. It should work, which would point to your 'logger.xml' as culprit (if you have not changed any other log configuration). I'm using default logging of Play in Heroku and it works fine, so it should for you.

If it doesn't, then I'm positive you've done some other change to the log configuration, or there is some other log configuration in your app that is stopping the logs. You should find and revert that.

EDIT on request:

My config is the default one, as I mentioned:

# Root logger:
logger.root=ERROR

# Logger used by the framework:
logger.play=INFO

# Logger provided to your application:
logger.application=DEBUG

No logger.xml, nothing else. It works. If you are having problems, it may be that you are overriding the config somewhere else, check any jars you use or any other conflicts in the logs that are shown by Heroku that may hint to an error in the area.

Upvotes: 3

Related Questions