Domanda

I am using sbt-native-packager with the experimental Java Server archetype. I am trying to identify a conventional way to access my log files, and I'm wondering if anyone knows of a common approach here. Since I am using the Java Server archetype, I am getting a symlink /var/log/$app -> install_dir/$app/log, but it feels a little dirty and less portable to just have log4j open /var/log/$app/error.log directly.

[Update]

I ended up creating an object with run time path information:

object MakaraPaths {
  def getLogPath = new File(getJarPath, "../logs").getPath
  def getConfigPath = new File(getJarPath, "../conf").getPath

  def getJarPath = { 
    val regex = new Regex("(/.+/)*")
    val jarPath = Makara.getClass.getProtectionDomain.getCodeSource.getLocation.getPath

    (regex findAllIn jarPath).mkString("")
  }
}

In my main method, I established a system property based on the new MakaraPaths object:

System.setProperty("logPath", MakaraPaths.getLogPath)

I also used this for my config file:

val config = ConfigFactory.parseFile(new File(MakaraPaths.getConfigPath, "application.conf"))

Ultimately, to load the log file, I used a System Property lookup:

<RollingFile name="fileAppender" fileName="${sys:logPath}/server.log" filePattern="${sys:logPath}/server_%d{yyMMdd}.log">

This gets me most of the way where I needed to be. It's not completely portable, but it does technically support my use case. (Deploying to Ubuntu)

È stato utile?

Soluzione

You could use relative path in log4j configuration. Just write logs in logs/filename.log. During installation symlink install_dir/$app/logs -> /var/log/$app will be created, and all logs will be written in /var/log/$app/filename.log

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top