[tor-commits] [metrics-base/master] Simplify logging configuration across code bases.

karsten at torproject.org karsten at torproject.org
Tue Mar 31 06:58:53 UTC 2020


commit fd856466bcb260f53ef69a24c102d0e49d171cc3
Author: Karsten Loesing <karsten.loesing at gmx.net>
Date:   Sun Mar 8 08:58:37 2020 +0100

    Simplify logging configuration across code bases.
---
 java/base.xml    |  2 ++
 java/logback.xml | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)

diff --git a/java/base.xml b/java/base.xml
index 6eb3f63..f28062a 100644
--- a/java/base.xml
+++ b/java/base.xml
@@ -185,6 +185,7 @@
            haltonfailure="true"
            printsummary="on">
       <jvmarg value="-DLOGBASE=${generated}/test-logs"/>
+      <jvmarg value="-Dlogback.configurationFile=${buildresources}/logback.xml" />
       <classpath refid="test.classpath"/>
       <formatter type="plain" usefile="false"/>
       <batchtest>
@@ -295,6 +296,7 @@
          basedir="${usebase}"
          manifest="${manifestfile}" >
       <fileset dir="${resources}" includes="${resourceincludes}" />
+      <fileset dir="${buildresources}" includes="logback.xml" />
       <restrict>
         <not>
           <and>
diff --git a/java/logback.xml b/java/logback.xml
new file mode 100644
index 0000000..b788c0a
--- /dev/null
+++ b/java/logback.xml
@@ -0,0 +1,59 @@
+<!-- Default Logback configuration for production and unit tests.
+
+     By default, WARN and ERROR messages are printed out on the console and INFO
+     messages or higher are appended to `logs/metrics.log` or
+     `generated/test-logs/metrics.log`, respectively.
+
+     Configurable options are:
+      - `-DLOGBASE=path/for/logs/` for using a different log directory,
+      - `-DLOGLEVEL=DEBUG` for using a different log level for the log file, and
+      - `-Dlogback.configurationFile=./logback.xml` for using the custom logging
+        configuration file in the current working directory rather than this
+        file.
+-->
+<configuration>
+
+  <!-- Log WARN and ERROR messages to the console. -->
+  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+    <encoder>
+      <pattern>%date{ISO8601, UTC} %level %logger{20}:%line %msg%n</pattern>
+    </encoder>
+    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
+      <level>WARN</level>
+    </filter>
+  </appender>
+
+  <!-- Log to local log file `logs/metrics.log`, with `logs/` being configurable
+       via `-DLOGBASE=path/for/logs/`. Roll over daily, retaining no more than
+       10 days or 1 GiB of total log files. -->
+  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
+    <file>${LOGBASE:-logs}/metrics.log</file>
+    <encoder>
+      <pattern>%date{ISO8601, UTC} %level %logger{20}:%line %msg%n</pattern>
+    </encoder>
+    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+      <fileNamePattern>${LOGBASE:-logs}/metrics.%d.log</fileNamePattern>
+      <maxHistory>10</maxHistory>
+      <totalSizeCap>1GB</totalSizeCap>
+    </rollingPolicy>
+  </appender>
+
+  <!-- Only print out our own log messages to the console, not those coming from
+       third-party libraries. -->
+  <logger name="org.torproject" >
+    <appender-ref ref="STDOUT" />
+  </logger>
+
+  <!-- Never log anything lower than INFO from known third-party libraries. -->
+  <logger name="org.apache" level="INFO" />
+  <logger name="org.eclipse" level="INFO" />
+
+  <!-- Only log messages on INFO level or higher. This level can be configured
+       via `-DLOGLEVEL=DEBUG`, if DEBUG logs are required. This only affects the
+       log file, not the console which only logs warnings and errors. -->
+  <root level="${LOGLEVEL:-INFO}">
+    <appender-ref ref="FILE" />
+  </root>
+
+</configuration>
+



More information about the tor-commits mailing list