[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [exonerator/master] Simplify logging configuration.



commit 5a7c19700f740ff88c1a1ae05b2383851d8cf9c7
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Apr 8 08:52:45 2020 +0200

    Simplify logging configuration.
    
    Implements #33549.
---
 CHANGELOG.md                                       |  1 +
 build.xml                                          |  2 +-
 src/build                                          |  2 +-
 .../exonerator/ExoneraTorDatabaseImporter.java     |  2 +-
 .../metrics/exonerator/ExoneraTorServlet.java      |  4 +-
 .../metrics/exonerator/QueryResponse.java          |  3 +-
 .../metrics/exonerator/QueryServlet.java           | 17 +++----
 .../torproject/metrics/exonerator/ServerMain.java  |  7 +--
 src/main/resources/logback.xml                     | 57 ----------------------
 9 files changed, 20 insertions(+), 75 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca10ec2..d22bc6f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
 
  * Minor changes
    - Improve logging of the database importer.
+   - Simplify logging configuration.
 
 
 # Changes in version 4.3.0 - 2020-01-15
diff --git a/build.xml b/build.xml
index cdc919c..419e828 100644
--- a/build.xml
+++ b/build.xml
@@ -108,7 +108,7 @@
         </archives>
       </restrict>
       <exclude name="**/Test*.class" />
-      <zipfileset dir="${resources}"
+      <zipfileset dir="${buildresources}"
                   prefix=""
                   includes="logback.xml" />
       <zipfileset dir="${resources}/web"
diff --git a/src/build b/src/build
index 264e498..b5e1a2d 160000
--- a/src/build
+++ b/src/build
@@ -1 +1 @@
-Subproject commit 264e498f54a20f7d299daaf2533d043f880e6a8b
+Subproject commit b5e1a2d7b29e58cc0645f068a1ebf4377bf9d8b8
diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
index 53e58f7..b4d68e5 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorDatabaseImporter.java
@@ -47,7 +47,7 @@ import java.util.TreeMap;
 /* Import Tor descriptors into the ExoneraTor database. */
 public class ExoneraTorDatabaseImporter {
 
-  private static Logger logger
+  private static final Logger logger
       = LoggerFactory.getLogger(ExoneraTorDatabaseImporter.class);
 
   /** Main function controlling the parsing process. */
diff --git a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
index b3f5b59..59535ea 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ExoneraTorServlet.java
@@ -36,7 +36,8 @@ public class ExoneraTorServlet extends HttpServlet {
 
   private static final long serialVersionUID = 1370088989739567509L;
 
-  private Logger logger;
+  private static final Logger logger
+      = LoggerFactory.getLogger(ExoneraTorServlet.class);
 
   private String exoneraTorHost = System.getProperty("exonerator.url",
       "https://exonerator.torproject.org";);
@@ -49,7 +50,6 @@ public class ExoneraTorServlet extends HttpServlet {
   @Override
   public void init(ServletConfig config) throws ServletException {
     super.init(config);
-    this.logger = LoggerFactory.getLogger(ExoneraTorServlet.class);
     this.availableLanguageNames = new TreeMap<>();
     for (String locale : this.availableLanguages) {
       ResourceBundle rb = ResourceBundle.getBundle("ExoneraTor",
diff --git a/src/main/java/org/torproject/metrics/exonerator/QueryResponse.java b/src/main/java/org/torproject/metrics/exonerator/QueryResponse.java
index aee8dbf..14f2fa9 100644
--- a/src/main/java/org/torproject/metrics/exonerator/QueryResponse.java
+++ b/src/main/java/org/torproject/metrics/exonerator/QueryResponse.java
@@ -18,7 +18,8 @@ import java.util.SortedSet;
 /** Query response from the ExoneraTor database. */
 public class QueryResponse {
 
-  private static Logger logger = LoggerFactory.getLogger(QueryResponse.class);
+  private static final Logger logger
+      = LoggerFactory.getLogger(QueryResponse.class);
 
   /* Actual version implemented by this class. */
   private static final String VERSION = "1.0";
diff --git a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
index ee61e28..dda63da 100644
--- a/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
+++ b/src/main/java/org/torproject/metrics/exonerator/QueryServlet.java
@@ -46,7 +46,8 @@ public class QueryServlet extends HttpServlet {
 
   private static final long serialVersionUID = 7109011659099295183L;
 
-  private Logger logger;
+  private static final Logger logger
+      = LoggerFactory.getLogger(QueryServlet.class);
 
   private DataSource ds;
 
@@ -56,15 +57,13 @@ public class QueryServlet extends HttpServlet {
 
   @Override
   public void init() {
-    this.logger = LoggerFactory.getLogger(QueryServlet.class);
-
     /* Look up data source. */
     try {
       Context cxt = new InitialContext();
       this.ds = (DataSource) cxt.lookup("java:comp/env/jdbc/exonerator");
-      this.logger.info("Successfully looked up data source.");
+      logger.info("Successfully looked up data source.");
     } catch (NamingException e) {
-      this.logger.warn("Could not look up data source", e);
+      logger.warn("Could not look up data source", e);
     }
   }
 
@@ -341,17 +340,17 @@ public class QueryServlet extends HttpServlet {
             }
           }
         } catch (SQLException e) {
-          this.logger.warn("Result set error.  Returning 'null'.", e);
+          logger.warn("Result set error.  Returning 'null'.", e);
           return null;
         }
-        this.logger.info("Returned a database connection to the pool after {}.",
+        logger.info("Returned a database connection to the pool after {}.",
             Duration.between(requestedConnection, Instant.now()));
       } catch (SQLException e) {
-        this.logger.warn("Callable statement error.  Returning 'null'.", e);
+        logger.warn("Callable statement error.  Returning 'null'.", e);
         return null;
       }
     } catch (Throwable e) { // Catch all problems left.
-      this.logger.warn("Database error.  Returning 'null'.", e);
+      logger.warn("Database error.  Returning 'null'.", e);
       return null;
     }
 
diff --git a/src/main/java/org/torproject/metrics/exonerator/ServerMain.java b/src/main/java/org/torproject/metrics/exonerator/ServerMain.java
index 0663e0f..1819a3c 100644
--- a/src/main/java/org/torproject/metrics/exonerator/ServerMain.java
+++ b/src/main/java/org/torproject/metrics/exonerator/ServerMain.java
@@ -11,20 +11,21 @@ import org.slf4j.LoggerFactory;
 
 public class ServerMain {
 
-  private static final Logger log = LoggerFactory.getLogger(ServerMain.class);
+  private static final Logger logger
+      = LoggerFactory.getLogger(ServerMain.class);
 
   /** Starts the web server listening for incoming client connections. */
   public static void main(String[] args) {
     try {
       Resource jettyXml = Resource.newSystemResource("jetty.xml");
-      log.info("Reading configuration from '{}'.", jettyXml);
+      logger.info("Reading configuration from '{}'.", jettyXml);
       XmlConfiguration configuration
           = new XmlConfiguration(jettyXml.getInputStream());
       Server server = (Server) configuration.configure();
       server.start();
       server.join();
     } catch (Exception ex) {
-      log.error("Exiting, because of: {}.", ex.getMessage(), ex);
+      logger.error("Exiting, because of: {}.", ex.getMessage(), ex);
       System.exit(1);
     }
   }
diff --git a/src/main/resources/logback.xml b/src/main/resources/logback.xml
deleted file mode 100644
index c29c057..0000000
--- a/src/main/resources/logback.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-<configuration debug="false">
-
-  <!-- a path and a prefix -->
-  <property name="logfile-base" value="${LOGBASE}/exonerator-" />
-
-  <!-- log file names -->
-  <property name="fileall-logname" value="${logfile-base}all" />
-  <property name="fileerr-logname" value="${logfile-base}err" />
-  <property name="filestatistics-logname" value="${logfile-base}statistics" />
-
-  <!-- date pattern -->
-  <property name="utc-date-pattern" value="%date{ISO8601, UTC}" />
-
-  <!-- appender section -->
-  <appender name="FILEALL" class="ch.qos.logback.core.rolling.RollingFileAppender">
-    <file>${fileall-logname}.log</file>
-    <encoder>
-      <pattern>${utc-date-pattern} %level %logger{20}:%line %msg%n</pattern>
-    </encoder>
-    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
-      <!-- rollover daily -->
-      <FileNamePattern>${fileall-logname}.%d{yyyy-MM-dd}.%i.log</FileNamePattern>
-      <maxHistory>10</maxHistory>
-      <timeBasedFileNamingAndTriggeringPolicy
-            class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
-        <!-- or whenever the file size reaches 1MB -->
-        <maxFileSize>1MB</maxFileSize>
-      </timeBasedFileNamingAndTriggeringPolicy>
-    </rollingPolicy>
-  </appender>
-
-  <appender name="FILEERR" class="ch.qos.logback.core.FileAppender">
-    <file>${fileerr-logname}.log</file>
-    <encoder>
-      <pattern>${utc-date-pattern} %level %logger{20}:%line %msg%n</pattern>
-    </encoder>
-
-    <!-- ERROR or worse -->
-    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
-      <level>ERROR</level>
-    </filter>
-  </appender>
-
-  <!-- logger section -->
-  <logger name="org.torproject" >
-    <appender-ref ref="FILEERR" />
-  </logger>
-
-  <logger name="org.eclipse" level="INFO" />
-  <logger name="org.apache" level="INFO" />
-
-  <root level="INFO">
-    <appender-ref ref="FILEALL" />
-  </root>
-
-</configuration>
-

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits