Commit 5d02c94a authored by Wai Yi Leung's avatar Wai Yi Leung
Browse files

Merge branch 'feature-force_logging' into 'develop'

Force logging to a file

see #158

See merge request !175
parents c67a1b6e 62ab9637
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
*/ */
package nl.lumc.sasc.biopet.core package nl.lumc.sasc.biopet.core
import org.apache.log4j.{ PatternLayout, Appender, WriterAppender, FileAppender }
import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging } import org.broadinstitute.gatk.queue.util.{ Logging => GatkLogging }
import java.io.File import java.io.{ PrintWriter, File }
import nl.lumc.sasc.biopet.core.config.Config import nl.lumc.sasc.biopet.core.config.Config
import nl.lumc.sasc.biopet.core.workaround.BiopetQCommandLine import nl.lumc.sasc.biopet.core.workaround.BiopetQCommandLine
import scala.collection.JavaConversions._
/** Wrapper around executable from Queue */ /** Wrapper around executable from Queue */
trait PipelineCommand extends MainCommand with GatkLogging { trait PipelineCommand extends MainCommand with GatkLogging {
...@@ -64,9 +66,18 @@ trait PipelineCommand extends MainCommand with GatkLogging { ...@@ -64,9 +66,18 @@ trait PipelineCommand extends MainCommand with GatkLogging {
} }
} }
val logDir: File = new File(Config.global.map.getOrElse("output_dir", "./").toString + File.separator + ".log")
logDir.mkdirs()
val logFile = new File(logDir, "biopet." + BiopetQCommandLine.timestamp + ".log")
val a = new WriterAppender(new PatternLayout("%-5p [%d] [%C{1}] - %m%n"), new PrintWriter(logFile))
logger.addAppender(a)
var argv: Array[String] = Array() var argv: Array[String] = Array()
argv ++= Array("-S", pipeline) argv ++= Array("-S", pipeline)
argv ++= args argv ++= args
if (!args.contains("--log_to_file") && !args.contains("-log")) {
argv ++= List("--log_to_file", logFile.getAbsolutePath.replace("biopet", "queue"))
}
BiopetQCommandLine.main(argv) BiopetQCommandLine.main(argv)
} }
} }
\ No newline at end of file
...@@ -94,6 +94,8 @@ object BiopetQCommandLine extends GatkLogging { ...@@ -94,6 +94,8 @@ object BiopetQCommandLine extends GatkLogging {
if (CommandLineProgram.result != 0) if (CommandLineProgram.result != 0)
System.exit(CommandLineProgram.result) System.exit(CommandLineProgram.result)
} }
val timestamp = System.currentTimeMillis
} }
/** /**
...@@ -124,7 +126,7 @@ class BiopetQCommandLine extends CommandLineProgram with Logging { ...@@ -124,7 +126,7 @@ class BiopetQCommandLine extends CommandLineProgram with Logging {
org.apache.commons.io.IOUtils.copy(is, os) org.apache.commons.io.IOUtils.copy(is, os)
os.close() os.close()
val s = if (t.getName.endsWith("/")) t.getName.substring(0, t.getName.length - 1) else t.getName val s = if (t.getName.endsWith("/")) t.getName.substring(0, t.getName.length - 1) else t.getName
pipelineName = s.substring(0, s.lastIndexOf(".")) + "." + System.currentTimeMillis pipelineName = s.substring(0, s.lastIndexOf(".")) + "." + BiopetQCommandLine.timestamp
} }
// override createByType to pass the correct exceptions // override createByType to pass the correct exceptions
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment