[tor-commits] [collector/master] implements task-18922, make logging configurable.
karsten at torproject.org
karsten at torproject.org
Thu May 12 19:36:48 UTC 2016
commit f85683536bb0918f449387bf73f02385a3495bb5
Author: iwakeh <iwakeh at torproject.org>
Date: Mon May 9 22:00:26 2016 +0000
implements task-18922, make logging configurable.
---
bin/logging.properties | 20 +++++
bin/run-all | 16 ++++
bin/run-bridgedescs | 2 +-
bin/run-bridgepools | 2 +-
bin/run-exitlists | 2 +-
bin/run-relaydescs | 2 +-
bin/run-torperf | 2 +-
bin/update-index | 2 +-
.../bridgedescs/SanitizedBridgesWriter.java | 3 -
.../BridgePoolAssignmentsProcessor.java | 3 -
.../collector/exitlists/ExitListDownloader.java | 3 -
.../collector/main/LoggingConfiguration.java | 96 ----------------------
.../collector/relaydescs/ArchiveWriter.java | 3 -
.../collector/torperf/TorperfDownloader.java | 3 -
14 files changed, 42 insertions(+), 117 deletions(-)
diff --git a/bin/logging.properties b/bin/logging.properties
new file mode 100644
index 0000000..5aae3cb
--- /dev/null
+++ b/bin/logging.properties
@@ -0,0 +1,20 @@
+handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler
+
+.level = FINER
+
+# if the following dir pattern is changed, LOGGINGPATH='log' in run-all
+# needs to be adapted.
+java.util.logging.FileHandler.pattern = ./log/collector-%g.log
+java.util.logging.FileHandler.limit = 5000000
+java.util.logging.FileHandler.count = 9
+java.util.logging.FileHandler.append = true
+java.util.logging.FileHandler.level = FINER
+java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
+
+java.util.logging.ConsoleHandler.level = WARNING
+java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
+
+java.util.logging.SimpleFormatter.format = %1$tF %1$tT %4$s %2$s %5$s%n
+
+sun.net.www.level = SEVERE
+sun.level = SEVERE
diff --git a/bin/run-all b/bin/run-all
new file mode 100755
index 0000000..469aced
--- /dev/null
+++ b/bin/run-all
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+TOKEN=`expr substr $1 5 20`
+
+# if the path is changed in properties, this needs to be adapted.
+LOGGINGPATH='log'
+
+if ! test -d $LOGGINGPATH
+then mkdir $LOGGINGPATH
+fi
+
+# the following uses one logging configuration for all modules
+java -Xmx2g -Djava.util.logging.config.file=./bin/logging.properties -jar collector-0.9.0-dev.jar $TOKEN
+
+# this would use a special log config for each module
+# java -Xmx2g -Djava.util.logging.config.file=./bin/logging.$TOKEN.properties -jar collector-0.9.0-dev.jar $TOKEN
diff --git a/bin/run-bridgedescs b/bin/run-bridgedescs
index 37eeea5..62d71f7 100755
--- a/bin/run-bridgedescs
+++ b/bin/run-bridgedescs
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar bridgedescs
+`dirname $0`/run-all `basename $0`
diff --git a/bin/run-bridgepools b/bin/run-bridgepools
index 9c5c53a..62d71f7 100755
--- a/bin/run-bridgepools
+++ b/bin/run-bridgepools
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar bridgepools
+`dirname $0`/run-all `basename $0`
diff --git a/bin/run-exitlists b/bin/run-exitlists
index 3bdef11..62d71f7 100755
--- a/bin/run-exitlists
+++ b/bin/run-exitlists
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar exitlists
+`dirname $0`/run-all `basename $0`
diff --git a/bin/run-relaydescs b/bin/run-relaydescs
index 8ad7506..62d71f7 100755
--- a/bin/run-relaydescs
+++ b/bin/run-relaydescs
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar relaydescs
+`dirname $0`/run-all `basename $0`
diff --git a/bin/run-torperf b/bin/run-torperf
index 267df58..62d71f7 100755
--- a/bin/run-torperf
+++ b/bin/run-torperf
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar torperf
+`dirname $0`/run-all `basename $0`
diff --git a/bin/update-index b/bin/update-index
index 70b0067..6e6c488 100755
--- a/bin/update-index
+++ b/bin/update-index
@@ -1,3 +1,3 @@
#!/bin/sh
-java -Xmx2g -jar collector-0.9.0-dev.jar updateindex
+`dirname $0`/run-all run-updateindex
diff --git a/src/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
index f8d61c0..3214715 100644
--- a/src/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -5,7 +5,6 @@ package org.torproject.collector.bridgedescs;
import org.torproject.collector.main.Configuration;
import org.torproject.collector.main.LockFile;
-import org.torproject.collector.main.LoggingConfiguration;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
@@ -52,8 +51,6 @@ public class SanitizedBridgesWriter extends Thread {
public static void main(String[] args) {
- /* Initialize logging configuration. */
- new LoggingConfiguration("bridge-descriptors");
Logger logger = Logger.getLogger(
SanitizedBridgesWriter.class.getName());
logger.info("Starting bridge-descriptors module of CollecTor.");
diff --git a/src/org/torproject/collector/bridgepools/BridgePoolAssignmentsProcessor.java b/src/org/torproject/collector/bridgepools/BridgePoolAssignmentsProcessor.java
index 8afaa43..2b6c262 100644
--- a/src/org/torproject/collector/bridgepools/BridgePoolAssignmentsProcessor.java
+++ b/src/org/torproject/collector/bridgepools/BridgePoolAssignmentsProcessor.java
@@ -5,7 +5,6 @@ package org.torproject.collector.bridgepools;
import org.torproject.collector.main.Configuration;
import org.torproject.collector.main.LockFile;
-import org.torproject.collector.main.LoggingConfiguration;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Hex;
@@ -38,8 +37,6 @@ public class BridgePoolAssignmentsProcessor extends Thread {
public static void main(String[] args) {
- /* Initialize logging configuration. */
- new LoggingConfiguration("bridge-pool-assignments");
Logger logger = Logger.getLogger(
BridgePoolAssignmentsProcessor.class.getName());
logger.info("Starting bridge-pool-assignments module of CollecTor.");
diff --git a/src/org/torproject/collector/exitlists/ExitListDownloader.java b/src/org/torproject/collector/exitlists/ExitListDownloader.java
index d328850..54fd50f 100644
--- a/src/org/torproject/collector/exitlists/ExitListDownloader.java
+++ b/src/org/torproject/collector/exitlists/ExitListDownloader.java
@@ -5,7 +5,6 @@ package org.torproject.collector.exitlists;
import org.torproject.collector.main.Configuration;
import org.torproject.collector.main.LockFile;
-import org.torproject.collector.main.LoggingConfiguration;
import org.torproject.descriptor.Descriptor;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.DescriptorParser;
@@ -34,8 +33,6 @@ public class ExitListDownloader extends Thread {
public static void main(String[] args) {
- /* Initialize logging configuration. */
- new LoggingConfiguration("exit-lists");
Logger logger = Logger.getLogger(ExitListDownloader.class.getName());
logger.info("Starting exit-lists module of CollecTor.");
diff --git a/src/org/torproject/collector/main/LoggingConfiguration.java b/src/org/torproject/collector/main/LoggingConfiguration.java
deleted file mode 100644
index b8a91c7..0000000
--- a/src/org/torproject/collector/main/LoggingConfiguration.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/* Copyright 2010--2016 The Tor Project
- * See LICENSE for licensing information */
-
-package org.torproject.collector.main;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.TimeZone;
-import java.util.logging.ConsoleHandler;
-import java.util.logging.FileHandler;
-import java.util.logging.Formatter;
-import java.util.logging.Handler;
-import java.util.logging.Level;
-import java.util.logging.LogRecord;
-import java.util.logging.Logger;
-
-/**
- * Initialize logging configuration.
- *
- * Log levels used by CollecTor:
- *
- * - SEVERE: An event made it impossible to continue program execution.
- * - WARNING: A potential problem occurred that requires the operator to
- * look after the otherwise unattended setup
- * - INFO: Messages on INFO level are meant to help the operator in making
- * sure that operation works as expected.
- * - FINE: Debug messages that are used to identify problems and which are
- * turned on by default.
- * - FINER: More detailed debug messages to investigate problems in more
- * detail. Not turned on by default. Increase log file limit when using
- * FINER.
- * - FINEST: Most detailed debug messages. Not used.
- */
-public class LoggingConfiguration {
- public LoggingConfiguration(String moduleName) {
-
- /* Remove default console handler. */
- for (Handler h : Logger.getLogger("").getHandlers()) {
- Logger.getLogger("").removeHandler(h);
- }
-
- /* Disable logging of internal Sun classes. */
- Logger.getLogger("sun").setLevel(Level.OFF);
-
- /* Set minimum log level we care about from INFO to FINER. */
- Logger.getLogger("").setLevel(Level.FINER);
-
- /* Create log handler that writes messages on WARNING or higher to the
- * console. */
- final SimpleDateFormat dateTimeFormat =
- new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
- Formatter cf = new Formatter() {
- public String format(LogRecord record) {
- return dateTimeFormat.format(new Date(record.getMillis())) + " "
- + record.getMessage() + "\n";
- }
- };
- Handler ch = new ConsoleHandler();
- ch.setFormatter(cf);
- ch.setLevel(Level.WARNING);
- Logger.getLogger("").addHandler(ch);
-
- /* Initialize own logger for this class. */
- Logger logger = Logger.getLogger(
- LoggingConfiguration.class.getName());
-
- /* Create log handler that writes all messages on FINE or higher to a
- * local file. */
- Formatter ff = new Formatter() {
- public String format(LogRecord record) {
- return dateTimeFormat.format(new Date(record.getMillis())) + " "
- + record.getLevel() + " " + record.getSourceClassName() + " "
- + record.getSourceMethodName() + " " + record.getMessage()
- + (record.getThrown() != null ? " " + record.getThrown() : "")
- + "\n";
- }
- };
- try {
- new File("log").mkdirs();
- FileHandler fh = new FileHandler("log/" + moduleName, 5000000, 5,
- true);
- fh.setFormatter(ff);
- fh.setLevel(Level.FINE);
- Logger.getLogger("").addHandler(fh);
- } catch (SecurityException e) {
- logger.log(Level.WARNING, "No permission to create log file. "
- + "Logging to file is disabled.", e);
- } catch (IOException e) {
- logger.log(Level.WARNING, "Could not write to log file. Logging to "
- + "file is disabled.", e);
- }
- }
-}
diff --git a/src/org/torproject/collector/relaydescs/ArchiveWriter.java b/src/org/torproject/collector/relaydescs/ArchiveWriter.java
index 370b5ea..ee87b12 100644
--- a/src/org/torproject/collector/relaydescs/ArchiveWriter.java
+++ b/src/org/torproject/collector/relaydescs/ArchiveWriter.java
@@ -5,7 +5,6 @@ package org.torproject.collector.relaydescs;
import org.torproject.collector.main.Configuration;
import org.torproject.collector.main.LockFile;
-import org.torproject.collector.main.LoggingConfiguration;
import org.torproject.descriptor.DescriptorParseException;
import org.torproject.descriptor.DescriptorParser;
import org.torproject.descriptor.DescriptorSourceFactory;
@@ -39,8 +38,6 @@ public class ArchiveWriter extends Thread {
public static void main(String[] args) {
- /* Initialize logging configuration. */
- new LoggingConfiguration("relay-descriptors");
Logger logger = Logger.getLogger(ArchiveWriter.class.getName());
logger.info("Starting relay-descriptors module of CollecTor.");
diff --git a/src/org/torproject/collector/torperf/TorperfDownloader.java b/src/org/torproject/collector/torperf/TorperfDownloader.java
index a2c94ef..7bcfbf3 100644
--- a/src/org/torproject/collector/torperf/TorperfDownloader.java
+++ b/src/org/torproject/collector/torperf/TorperfDownloader.java
@@ -5,7 +5,6 @@ package org.torproject.collector.torperf;
import org.torproject.collector.main.Configuration;
import org.torproject.collector.main.LockFile;
-import org.torproject.collector.main.LoggingConfiguration;
import java.io.BufferedReader;
import java.io.BufferedWriter;
@@ -34,8 +33,6 @@ public class TorperfDownloader extends Thread {
public static void main(String[] args) {
- /* Initialize logging configuration. */
- new LoggingConfiguration("torperf");
Logger logger = Logger.getLogger(TorperfDownloader.class.getName());
logger.info("Starting torperf module of CollecTor.");
More information about the tor-commits
mailing list