Playframework: No Way to Disable File Logging

Created on 27 Jul 2016  路  4Comments  路  Source: playframework/playframework

Play 2.5.4

Expected Behavior

Please describe the expected behavior of the issue, starting from the first action.

  1. By creating a conf/logback.xml file that does not have a File logger I expect to be able to turn off file logging.

Actual Behavior

When the server is started with only a STDOUT appender in conf/logback.xml a logs/application.log file is still created containing:

2016-07-27 12:54:50,108 [INFO] from play.core.server.NettyServer in pool-6-thread-1 - Listening for HTTP on /0:0:0:0:0:0:0:0:9000

Most helpful comment

I think I'd rather see the default configs not do file logging. The file logger could be added to the template rather than logback-play-dev.xml and logback-play-default.xml.

All 4 comments

So, LoggerConfigurator is run initially. If there's no Application, it has to pick something.

        LoggerConfigurator(this.getClass.getClassLoader) match {
          case Some(loggerConfigurator) =>
            loggerConfigurator.init(path, Mode.Dev)
          case None =>
            System.out.println("No play.logger.configurator found: logging must be configured entirely by the application.")
        }

https://github.com/playframework/playframework/blob/2.5.x/framework/src/play-server/src/main/scala/play/core/server/DevServerStart.scala#L84

loggerConfigurator runs init, because there is no application classloader available yet:

  /**
   * Initialize the Logger when there's no application ClassLoader available.
   */
  def init(rootPath: java.io.File, mode: Mode.Mode): Unit = {
    val properties = Map("application.home" -> rootPath.getAbsolutePath)
    val resourceName = if (mode == Mode.Dev) "logback-play-dev.xml" else "logback-play-default.xml"
    val resourceUrl = Option(this.getClass.getClassLoader.getResource(resourceName))
    configure(properties, resourceUrl)
  }

Which then picks up logback-play-dev.xml from the play-logback module.

Some(jar:file:/Users/wsargent/.ivy2/cache/com.typesafe.play/play-logback_2.11/jars/play-logback_2.11-2.5.4.jar!/logback-play-dev.xml)

So the solution here is to remove the PlayLogback plugin:

lazy val root = (project in file(".")).enablePlugins(PlayScala).disablePlugins(PlayLogback)

https://www.playframework.com/documentation/2.5.x/SettingsLogger#using-a-custom-logging-framework

and then PlayLogback won't do anything.

I think I'd rather see the default configs not do file logging. The file logger could be added to the template rather than logback-play-dev.xml and logback-play-default.xml.

@jamesward if you submit a PR to edit logback-play-dev.xml and logback-play-default.xml I'll review it :-)

Was this page helpful?
0 / 5 - 0 ratings