* 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
This commit is contained in:
zzz
2010-11-29 13:13:02 +00:00
parent a86fef2a21
commit d31113255e
5 changed files with 39 additions and 13 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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<LogRecord> 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;
}