Commit 5a7c1970 authored by Karsten Loesing's avatar Karsten Loesing
Browse files

Simplify logging configuration.

Implements #33549.
parent 54ad2882
......@@ -2,6 +2,7 @@
* Minor changes
- Improve logging of the database importer.
- Simplify logging configuration.
# Changes in version 4.3.0 - 2020-01-15
......
......@@ -108,7 +108,7 @@
</archives>
</restrict>
<exclude name="**/Test*.class" />
<zipfileset dir="${resources}"
<zipfileset dir="${buildresources}"
prefix=""
includes="logback.xml" />
<zipfileset dir="${resources}/web"
......
build @ b5e1a2d7
Subproject commit 264e498f54a20f7d299daaf2533d043f880e6a8b
Subproject commit b5e1a2d7b29e58cc0645f068a1ebf4377bf9d8b8
......@@ -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. */
......
......@@ -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",
......
......@@ -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";
......
......@@ -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;
}
......
......@@ -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);
}
}
......
<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>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment