From d31113255e883631c5eb746eb9aa61acff3d7b80 Mon Sep 17 00:00:00 2001
From: zzz
Date: Mon, 29 Nov 2010 13:13:02 +0000
Subject: [PATCH] * Logging: - Use System locale and time zone for
default date/time format, so it matches the wrapper log time (we
can't set the wrapper log time zone). (existing installs must remove
logger.dateFormat line in logger.config to get system default
format) - Force RuntimeExceptions to CRIT level - Don't have
log() count buffer size
---
apps/routerconsole/jsp/logs.jsp | 3 ++-
core/java/src/net/i2p/util/Log.java | 3 +++
core/java/src/net/i2p/util/LogManager.java | 26 +++++++++++++++++-----
core/java/src/net/i2p/util/LogWriter.java | 15 +++++++------
router/java/src/net/i2p/router/Router.java | 5 +++++
5 files changed, 39 insertions(+), 13 deletions(-)
diff --git a/apps/routerconsole/jsp/logs.jsp b/apps/routerconsole/jsp/logs.jsp
index 019564bbe..ed3b7ebc9 100644
--- a/apps/routerconsole/jsp/logs.jsp
+++ b/apps/routerconsole/jsp/logs.jsp
@@ -24,11 +24,12 @@
Processor: <%=net.i2p.util.NativeBigInteger.cpuModel()%> (<%=net.i2p.util.NativeBigInteger.cpuType()%>)
Jbigi: <%=net.i2p.util.NativeBigInteger.loadStatus()%>
Encoding: <%=System.getProperty("file.encoding")%>
+<%=intl._("Note that system information, log timestamps, and log messages may provide clues to your location; please review everything you include in a bug report.")%>:
" />
<%=intl._("Critical Logs")%>
-
+
<%=intl._("Service (Wrapper) Logs")%>
diff --git a/core/java/src/net/i2p/util/Log.java b/core/java/src/net/i2p/util/Log.java
index 63d44cb13..922df7885 100644
--- a/core/java/src/net/i2p/util/Log.java
+++ b/core/java/src/net/i2p/util/Log.java
@@ -107,6 +107,9 @@ public class Log {
}
public void log(int priority, String msg, Throwable t) {
+ // Boost the priority of NPE and friends so they get seen and reported
+ if (t != null && t instanceof RuntimeException && !(t instanceof IllegalArgumentException))
+ priority = CRIT;
if (priority >= _minPriority) {
_manager.addRecord(new LogRecord(_class, _name,
Thread.currentThread().getName(), priority,
diff --git a/core/java/src/net/i2p/util/LogManager.java b/core/java/src/net/i2p/util/LogManager.java
index 6c9a062e4..54a3b9e13 100644
--- a/core/java/src/net/i2p/util/LogManager.java
+++ b/core/java/src/net/i2p/util/LogManager.java
@@ -13,6 +13,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
+import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -23,6 +24,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
+import java.util.TimeZone;
import java.util.TreeMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.LinkedBlockingQueue;
@@ -57,7 +59,9 @@ public class LogManager {
public final static String PROP_RECORD_PREFIX = "logger.record.";
public final static String DEFAULT_FORMAT = DATE + " " + PRIORITY + " [" + THREAD + "] " + CLASS + ": " + MESSAGE;
- public final static String DEFAULT_DATEFORMAT = "HH:mm:ss.SSS";
+ //public final static String DEFAULT_DATEFORMAT = "HH:mm:ss.SSS";
+ /** blank means default short date and medium time for the locale - see DateFormat */
+ public final static String DEFAULT_DATEFORMAT = "";
public final static String DEFAULT_FILENAME = "logs/log-#.txt";
public final static String DEFAULT_FILESIZE = "10m";
public final static boolean DEFAULT_DISPLAYONSCREEN = true;
@@ -225,6 +229,7 @@ public class LogManager {
startLogWriter();
_records.offer(record);
+ /**** don't burden the logging thread with counting
int numRecords = _records.size();
if (numRecords > 100) {
@@ -234,6 +239,7 @@ public class LogManager {
_writer.notifyAll();
}
}
+ ****/
}
/**
@@ -292,8 +298,7 @@ public class LogManager {
_format = fmt.toCharArray();
String df = config.getProperty(PROP_DATEFORMAT, DEFAULT_DATEFORMAT);
- _dateFormatPattern = df;
- _dateFormat = new SimpleDateFormat(df);
+ setDateFormat(df);
String disp = config.getProperty(PROP_DISPLAYONSCREEN);
if (disp == null)
@@ -386,13 +391,24 @@ public class LogManager {
/**
* Update the date format
*
+ * @param format null or empty string means use default format for the locale
+ * (with a SHORT date and a MEDIUM time - see DateFormat)
* @return true if the format was updated, false if it was invalid
*/
public boolean setDateFormat(String format) {
- if (format == null) return false;
+ if (format == null)
+ format = "";
+ if (format.equals(_dateFormatPattern) && _dateFormat != null)
+ return true;
try {
- SimpleDateFormat fmt = new SimpleDateFormat(format);
+ SimpleDateFormat fmt = (SimpleDateFormat) DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+ if (!format.equals(""))
+ fmt.applyPattern(format);
+ // the router sets the JVM time zone to UTC but saves the original here so we can get it
+ String systemTimeZone = _context.getProperty("i2p.systemTimeZone");
+ if (systemTimeZone != null)
+ fmt.setTimeZone(TimeZone.getTimeZone(systemTimeZone));
_dateFormatPattern = format;
_dateFormat = fmt;
return true;
diff --git a/core/java/src/net/i2p/util/LogWriter.java b/core/java/src/net/i2p/util/LogWriter.java
index 7dca7ba96..b4d6e4395 100644
--- a/core/java/src/net/i2p/util/LogWriter.java
+++ b/core/java/src/net/i2p/util/LogWriter.java
@@ -27,7 +27,8 @@ import net.i2p.I2PAppContext;
*/
class LogWriter implements Runnable {
/** every 10 seconds? why? Just have the gui force a reread after a change?? */
- private final static long CONFIG_READ_ITERVAL = 10 * 1000;
+ private final static long CONFIG_READ_INTERVAL = 50 * 1000;
+ private final static long FLUSH_INTERVAL = 11 * 1000;
private long _lastReadConfig = 0;
private long _numBytesInCurrentFile = 0;
private Writer _currentOut;
@@ -71,14 +72,14 @@ class LogWriter implements Runnable {
try {
List records = _manager._removeAll();
if (records == null) return;
- for (LogRecord rec : records) {
- writeRecord(rec);
- }
if (!records.isEmpty()) {
+ for (LogRecord rec : records) {
+ writeRecord(rec);
+ }
try {
_currentOut.flush();
} catch (IOException ioe) {
- System.err.println("Error flushing the records");
+ System.err.println("Error writing the router log");
}
}
} catch (Throwable t) {
@@ -87,7 +88,7 @@ class LogWriter implements Runnable {
if (shouldWait) {
try {
synchronized (this) {
- this.wait(10*1000);
+ this.wait(FLUSH_INTERVAL);
}
} catch (InterruptedException ie) { // nop
}
@@ -101,7 +102,7 @@ class LogWriter implements Runnable {
private void rereadConfig() {
long now = Clock.getInstance().now();
- if (now - _lastReadConfig > CONFIG_READ_ITERVAL) {
+ if (now - _lastReadConfig > CONFIG_READ_INTERVAL) {
_manager.rereadConfig();
_lastReadConfig = now;
}
diff --git a/router/java/src/net/i2p/router/Router.java b/router/java/src/net/i2p/router/Router.java
index 459be0ec7..7f8b2788e 100644
--- a/router/java/src/net/i2p/router/Router.java
+++ b/router/java/src/net/i2p/router/Router.java
@@ -96,6 +96,7 @@ public class Router {
public final static String PROP_SHUTDOWN_IN_PROGRESS = "__shutdownInProgress";
public final static String DNS_CACHE_TIME = "" + (5*60);
+ private static final String originalTimeZoneID;
static {
// grumble about sun's java caching DNS entries *forever* by default
// so lets just keep 'em for a short time
@@ -106,6 +107,8 @@ public class Router {
System.setProperty("http.agent", "I2P");
// (no need for keepalive)
System.setProperty("http.keepAlive", "false");
+ // Save it for LogManager
+ originalTimeZoneID = TimeZone.getDefault().getID();
System.setProperty("user.timezone", "GMT");
// just in case, lets make it explicit...
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
@@ -180,6 +183,8 @@ public class Router {
if (envProps.getProperty("i2p.dir.config") == null)
envProps.setProperty("i2p.dir.config", userDir);
+ // Save this in the context for the logger and apps that need it
+ envProps.setProperty("i2p.systemTimeZone", originalTimeZoneID);
// The important thing that happens here is the directory paths are set and created
// i2p.dir.router defaults to i2p.dir.config