aboutsummaryrefslogtreecommitdiff
path: root/src/main/scala/logger/LoggerAnnotations.scala
blob: f4dc6b38b8b47c57aefa404e2784303c47132508 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// See LICENSE for license details.

package logger

import firrtl.annotations.{Annotation, NoTargetAnnotation}
import firrtl.options.{HasShellOptions, ShellOption}


/** An annotation associated with a Logger command line option */
sealed trait LoggerOption { this: Annotation => }

/** Describes the verbosity of information to log
  *  - set with `-ll/--log-level`
  *  - if unset, a [[LogLevelAnnotation]] with the default log level will be emitted
  * @param level the level of logging
  */
case class LogLevelAnnotation(globalLogLevel: LogLevel.Value = LogLevel.Warn) extends NoTargetAnnotation with LoggerOption

object LogLevelAnnotation extends HasShellOptions {

  val options = Seq(
    new ShellOption[String](
      longOption = "log-level",
      toAnnotationSeq = (a: String) => Seq(LogLevelAnnotation(LogLevel(a))),
      helpText = s"Set global logging verbosity (default: ${new LoggerOptions().globalLogLevel}",
      shortOption = Some("ll"),
      helpValueName = Some("{error|warn|info|debug|trace}") ) )

}

/** Describes a mapping of a class to a specific log level
  *  - set with `-cll/--class-log-level`
  * @param name the class name to log
  * @param level the verbosity level
  */
case class ClassLogLevelAnnotation(className: String, level: LogLevel.Value) extends NoTargetAnnotation with LoggerOption

object ClassLogLevelAnnotation extends HasShellOptions {

  val options = Seq(
    new ShellOption[Seq[String]](
      longOption = "class-log-level",
      toAnnotationSeq = (a: Seq[String]) => a.map { aa =>
        val className :: levelName :: _ = aa.split(":").toList
        val level = LogLevel(levelName)
        ClassLogLevelAnnotation(className, level) },
      helpText = "Set per-class logging verbosity",
      shortOption = Some("cll"),
      helpValueName = Some("<FullClassName:{error|warn|info|debug|trace}>...") ) )

}

/** Enables logging to a file (as opposed to STDOUT)
  *  - maps to [[LoggerOptions.logFileName]]
  *  - enabled with `--log-file`
  */
case class LogFileAnnotation(file: Option[String]) extends NoTargetAnnotation with LoggerOption

object LogFileAnnotation extends HasShellOptions {

  val options = Seq(
    new ShellOption[String](
      longOption = "log-file",
      toAnnotationSeq = (a: String) => Seq(LogFileAnnotation(Some(a))),
      helpText = "Log to a file instead of STDOUT",
      helpValueName = Some("<file>") ) )

}

/** Enables class names in log output
  *  - enabled with `-lcn/--log-class-names`
  */
case object LogClassNamesAnnotation extends NoTargetAnnotation with LoggerOption with HasShellOptions {

  val options = Seq(
    new ShellOption[Unit](
      longOption = "log-class-names",
      toAnnotationSeq = (a: Unit) => Seq(LogClassNamesAnnotation),
      helpText = "Show class names and log level in logging output",
      shortOption = Some("lcn") ) )

}