1/*  Title:      Pure/General/logger.scala
2    Author:     Makarius
3
4Minimal logging support.
5*/
6
7package isabelle
8
9
10object Logger
11{
12  def make(log_file: Option[Path]): Logger =
13    log_file match { case Some(file) => new File_Logger(file) case None => No_Logger }
14}
15
16trait Logger
17{
18  def apply(msg: => String): Unit
19
20  def timeit[A](message: String = "", enabled: Boolean = true)(e: => A): A =
21    Timing.timeit(message, enabled, apply(_))(e)
22}
23
24object No_Logger extends Logger
25{
26  def apply(msg: => String) { }
27}
28
29class File_Logger(path: Path) extends Logger
30{
31  def apply(msg: => String) { synchronized { File.append(path, msg + "\n") } }
32
33  override def toString: String = path.toString
34}
35