author | wenzelm |
Tue, 21 Jun 2022 14:51:17 +0200 | |
changeset 75571 | ac5e633ad9b3 |
parent 75393 | 87ebf5a50283 |
child 76592 | ec8bf1268f45 |
permissions | -rw-r--r-- |
64606 | 1 |
/* Title: Pure/General/logger.scala |
64605 | 2 |
Author: Makarius |
3 |
||
4 |
Minimal logging support. |
|
5 |
*/ |
|
6 |
||
64606 | 7 |
package isabelle |
64605 | 8 |
|
9 |
||
75393 | 10 |
object Logger { |
64605 | 11 |
def make(log_file: Option[Path]): Logger = |
12 |
log_file match { case Some(file) => new File_Logger(file) case None => No_Logger } |
|
73777
52e43a93d51f
clarified system_log: make this work independently of the particular "isabelle build" command-line (e.g. "isabelle mirabelle");
wenzelm
parents:
73340
diff
changeset
|
13 |
|
52e43a93d51f
clarified system_log: make this work independently of the particular "isabelle build" command-line (e.g. "isabelle mirabelle");
wenzelm
parents:
73340
diff
changeset
|
14 |
def make(progress: Progress): Logger = |
52e43a93d51f
clarified system_log: make this work independently of the particular "isabelle build" command-line (e.g. "isabelle mirabelle");
wenzelm
parents:
73340
diff
changeset
|
15 |
new Logger { def apply(msg: => String): Unit = progress.echo(msg) } |
64605 | 16 |
} |
17 |
||
75393 | 18 |
trait Logger { |
64605 | 19 |
def apply(msg: => String): Unit |
65921 | 20 |
|
21 |
def timeit[A](message: String = "", enabled: Boolean = true)(e: => A): A = |
|
22 |
Timing.timeit(message, enabled, apply(_))(e) |
|
64605 | 23 |
} |
24 |
||
75393 | 25 |
object No_Logger extends Logger { |
73340 | 26 |
def apply(msg: => String): Unit = {} |
64605 | 27 |
} |
28 |
||
75393 | 29 |
class File_Logger(path: Path) extends Logger { |
73340 | 30 |
def apply(msg: => String): Unit = synchronized { File.append(path, msg + "\n") } |
64605 | 31 |
|
32 |
override def toString: String = path.toString |
|
33 |
} |