Methods Summary |
---|
public void | addListener(FileLoggingAdapter listener)
if (!listeners.contains(listener))
listeners.add(listener);
|
private void | checkLoggingConfig()
try {
// Shorten from COConfigurationManager To make code more readable
final ConfigurationManager config = ConfigurationManager.getInstance();
boolean overrideLog = System.getProperty("azureus.overridelog") != null;
if (overrideLog) {
bLogToFile = true;
sLogDir = ".";
iLogFileMaxMB = 2;
for (int i = 0; i < ignoredComponents.length; i++) {
ignoredComponents[i].clear();
}
} else {
reloadLogToFileParam();
sLogDir = config.getStringParameter("Logging Dir", "");
iLogFileMaxMB = config.getIntParameter("Logging Max Size");
for (int i = 0; i < ignoredComponents.length; i++) {
ignoredComponents[i].clear();
int logType = indexToLogType(i);
for (int j = 0; j < configurableLOGIDs.length; j++) {
if (!config.getBooleanParameter("bLog." + logType + "."
+ configurableLOGIDs[j], true))
ignoredComponents[i].add(configurableLOGIDs[j]);
}
}
}
} catch (Throwable t) {
Debug.printStackTrace(t);
}
|
public java.util.List | getListeners()
return listeners;
|
private int | indexToLogType(int index)
switch (index) {
case 0:
return LogEvent.LT_INFORMATION;
case 1:
return LogEvent.LT_WARNING;
case 2:
return LogEvent.LT_ERROR;
}
return LogEvent.LT_INFORMATION;
|
public void | initialize()
// Shorten from COConfigurationManager To make code more readable
final ConfigurationManager config = ConfigurationManager.getInstance();
boolean overrideLog = System.getProperty("azureus.overridelog") != null;
for (int i = 0; i < ignoredComponents.length; i++) {
ignoredComponents[i] = new ArrayList();
}
if (!overrideLog) {
config.addListener(new COConfigurationListener() {
public void configurationSaved() {
checkLoggingConfig();
}
});
}
checkLoggingConfig();
config.addParameterListener(CFG_ENABLELOGTOFILE, new ParameterListener() {
public void parameterChanged(String parameterName) {
FileLogging.this.reloadLogToFileParam();
}
});
|
public void | log(LogEvent event)
if (ignoredComponents[logTypeToIndex(event.entryType)]
.contains(event.logID))
return;
StringBuffer text = new StringBuffer();
text.append(event.entryType).append(" ");
padAndAppend(text, event.logID.toString(), 8, 1);
//text.append("|");
if (event.relatedTo != null) {
lastWidth = padAndAppend(text, event.text, lastWidth, 1);
if (lastWidth > 200)
lastWidth = 200;
for (int i = 0; i < event.relatedTo.length; i++) {
Object obj = event.relatedTo[i];
if (obj == null)
continue;
if (i > 0)
text.append("; ");
if (obj instanceof LogRelation) {
text.append(((LogRelation) obj).getRelationText());
} else {
text.append("RelatedTo[")
.append(obj.toString())
.append("]");
}
}
} else {
text.append(event.text);
lastWidth = DEFPADDING;
}
//text.append(event.text);
if (event.text == null || !event.text.endsWith("\n"))
text.append("\r\n");
boolean okToLog = true;
for (Iterator iter = listeners.iterator(); iter.hasNext() && okToLog;) {
FileLoggingAdapter listener = (FileLoggingAdapter) iter.next();
okToLog = listener.logToFile(event, text);
}
logToFile(text.toString());
|
private void | logToFile(java.lang.String str)
if (!bLogToFile)
return;
synchronized (Logger.class) {
SimpleDateFormat format;
format = new SimpleDateFormat(sTimeStampFormat);
str = format.format(new Date()) + str;
PrintWriter pw = null;
File file_name = new File(sLogDir + File.separator + LOG_FILE_NAME);
try {
pw = new PrintWriter(new FileWriter(file_name, true));
if (pw != null)
pw.print(str);
} catch (Throwable e) {
// can't log this as go recursive!!!!
} finally {
if (pw != null) {
try {
pw.close();
} catch (Throwable e) {
// can't log as go recursive!!!!
}
// two files so half
long lMaxBytes = (iLogFileMaxMB * 1024 * 1024) / 2;
if (file_name.length() > lMaxBytes) {
File back_name = new File(sLogDir + File.separator + BAK_FILE_NAME);
if ((!back_name.exists()) || back_name.delete()) {
if (!file_name.renameTo(back_name))
file_name.delete();
} else {
file_name.delete();
}
}
}
} // finally
} // sync
|
private int | logTypeToIndex(int entryType)
switch (entryType) {
case LogEvent.LT_INFORMATION:
return 0;
case LogEvent.LT_WARNING:
return 1;
case LogEvent.LT_ERROR:
return 2;
}
return 0;
|
private int | padAndAppend(java.lang.StringBuffer appendTo, java.lang.String s, int width, int growBy)
if (s == null)
s = "null";
appendTo.append(s);
int sLen = s.length();
int len = width - sLen;
while (len <= 0)
len += growBy;
char[] padding = new char[len];
if (len > 5) {
for (int i = 0; i < len; i += 2)
padding[i] = ' ";
for (int i = 1; i < len; i += 2)
padding[i] = '.";
} else {
for (int i = 0; i < len; i++)
padding[i] = ' ";
}
appendTo.append(padding);
return len + sLen;
|
protected void | reloadLogToFileParam()
final ConfigurationManager config = ConfigurationManager.getInstance();
boolean bNewLogToFile = config.getBooleanParameter(CFG_ENABLELOGTOFILE);
if (bNewLogToFile != bLogToFile) {
bLogToFile = bNewLogToFile;
if (bLogToFile)
Logger.addListener(this);
else
Logger.removeListener(this);
}
|
public void | removeListener(FileLoggingAdapter listener)
listeners.remove(listener);
|