forked from I2P_Developers/i2p.i2p
* Logs:
- Flush buffers in logs.jsp - Add dup message to buffers, was in file only
This commit is contained in:
@ -24,12 +24,19 @@ public class LogsHelper extends HelperBase {
|
|||||||
return Server.getVersion();
|
return Server.getVersion();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does not call logManager.flush(); call getCriticalLogs() first to flush
|
||||||
|
*/
|
||||||
public String getLogs() {
|
public String getLogs() {
|
||||||
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
|
String str = formatMessages(_context.logManager().getBuffer().getMostRecentMessages());
|
||||||
return _("File location") + ": <b><code>" + _context.logManager().currentFile() + "</code></b><br><br>" + str;
|
return _("File location") + ": <b><code>" + _context.logManager().currentFile() + "</code></b><br><br>" + str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Side effect - calls logManager.flush()
|
||||||
|
*/
|
||||||
public String getCriticalLogs() {
|
public String getCriticalLogs() {
|
||||||
|
_context.logManager().flush();
|
||||||
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
|
return formatMessages(_context.logManager().getBuffer().getMostRecentCriticalMessages());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,6 +98,7 @@ public class LogsHelper extends HelperBase {
|
|||||||
for (int i = msgs.size() - 1; i >= 0; i--) {
|
for (int i = msgs.size() - 1; i >= 0; i--) {
|
||||||
String msg = msgs.get(i);
|
String msg = msgs.get(i);
|
||||||
msg = msg.replace("&", "&").replace("<", "<").replace(">", ">");
|
msg = msg.replace("&", "&").replace("<", "<").replace(">", ">");
|
||||||
|
msg = msg.replace("&darr;", "↓"); // hack - undo the damage (LogWriter)
|
||||||
// remove last \n that LogRecordFormatter added
|
// remove last \n that LogRecordFormatter added
|
||||||
if (msg.endsWith(NL))
|
if (msg.endsWith(NL))
|
||||||
msg = msg.substring(0, msg.length() - NL.length());
|
msg = msg.substring(0, msg.length() - NL.length());
|
||||||
|
@ -693,18 +693,30 @@ public class LogManager {
|
|||||||
}
|
}
|
||||||
*****/
|
*****/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Flush any pending records to disk.
|
||||||
|
* Blocking up to 250 ms.
|
||||||
|
* @since 0.9.3
|
||||||
|
*/
|
||||||
|
public void flush() {
|
||||||
|
if (_writer != null) {
|
||||||
|
int i = 50;
|
||||||
|
while ((!_records.isEmpty()) && i-- > 0) {
|
||||||
|
synchronized (_writer) {
|
||||||
|
_writer.notifyAll();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(5);
|
||||||
|
} catch (InterruptedException ie) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void shutdown() {
|
public void shutdown() {
|
||||||
if (_writer != null) {
|
if (_writer != null) {
|
||||||
//_log.log(Log.WARN, "Shutting down logger");
|
//_log.log(Log.WARN, "Shutting down logger");
|
||||||
// try to prevent out-of-order logging at shutdown
|
// try to prevent out-of-order logging at shutdown
|
||||||
synchronized (_writer) {
|
flush();
|
||||||
_writer.notifyAll();
|
|
||||||
}
|
|
||||||
if (!_records.isEmpty()) {
|
|
||||||
try {
|
|
||||||
Thread.sleep(250);
|
|
||||||
} catch (InterruptedException ie) {}
|
|
||||||
}
|
|
||||||
// this could generate out-of-order messages
|
// this could generate out-of-order messages
|
||||||
_writer.flushRecords(false);
|
_writer.flushRecords(false);
|
||||||
_writer.stopWriting();
|
_writer.stopWriting();
|
||||||
|
@ -81,15 +81,18 @@ class LogWriter implements Runnable {
|
|||||||
dupCount++;
|
dupCount++;
|
||||||
} else {
|
} else {
|
||||||
if (dupCount > 0) {
|
if (dupCount > 0) {
|
||||||
writeRecord(dupMessage(dupCount, last));
|
writeRecord(dupMessage(dupCount, last, false));
|
||||||
|
_manager.getBuffer().add(dupMessage(dupCount, last, true));
|
||||||
dupCount = 0;
|
dupCount = 0;
|
||||||
}
|
}
|
||||||
writeRecord(rec);
|
writeRecord(rec);
|
||||||
}
|
}
|
||||||
last = rec;
|
last = rec;
|
||||||
}
|
}
|
||||||
if (dupCount > 0)
|
if (dupCount > 0) {
|
||||||
writeRecord(dupMessage(dupCount, last));
|
writeRecord(dupMessage(dupCount, last, false));
|
||||||
|
_manager.getBuffer().add(dupMessage(dupCount, last, true));
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
if (_currentOut != null)
|
if (_currentOut != null)
|
||||||
_currentOut.flush();
|
_currentOut.flush();
|
||||||
@ -113,12 +116,13 @@ class LogWriter implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a msg with the date stamp of the last duplicate
|
* Return a msg with the date stamp of the last duplicate
|
||||||
* @since 0.9.3
|
* @since 0.9.3
|
||||||
*/
|
*/
|
||||||
private String dupMessage(int dupCount, LogRecord lastRecord) {
|
private String dupMessage(int dupCount, LogRecord lastRecord, boolean reverse) {
|
||||||
return LogRecordFormatter.getWhen(_manager, lastRecord) + " ^^^ " +
|
String arrows = reverse ? "↓↓↓" : "^^^";
|
||||||
_(dupCount, "1 similar message omitted", "{0} similar messages omitted") + " ^^^\n";
|
return LogRecordFormatter.getWhen(_manager, lastRecord) + ' ' + arrows + ' ' +
|
||||||
|
_(dupCount, "1 similar message omitted", "{0} similar messages omitted") + ' ' + arrows + '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
|
private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
|
||||||
|
Reference in New Issue
Block a user