DTG: Show all CRIT messages on DTG.

Experimental, may add a separate config or disable later.
Show I2P starting message in DTG
This commit is contained in:
zzz
2021-12-04 09:50:08 -05:00
parent 87362fd68b
commit 962cc31f31
2 changed files with 42 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
package net.i2p.desktopgui;
import java.awt.AWTException;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.awt.MenuItem;
@@ -44,6 +45,14 @@ class InternalTrayManager extends TrayManager {
log = ctx.logManager().getLog(InternalTrayManager.class);
}
/**
* @since 0.9.53
*/
public void startManager() throws AWTException {
super.startManager();
displayMessage(Log.INFO, _t("Starting"), _t("I2P is starting!"), null);
}
public synchronized PopupMenu getMainMenu() {
PopupMenu popup = new PopupMenu();

View File

@@ -11,6 +11,9 @@ package net.i2p.util;
import java.util.Queue;
import net.i2p.app.ClientAppManager;
import net.i2p.app.NotificationService;
/**
* Log writer thread that pulls log records from the LogManager and writes them to
* the log. This also periodically instructs the LogManager to reread its config
@@ -186,15 +189,43 @@ abstract class LogWriter implements Runnable {
// we always add to the console buffer, but only sometimes write to stdout
_manager.getBuffer().add(val);
if (rec.getPriority() >= Log.CRIT)
int priority = rec.getPriority();
if (priority >= Log.CRIT)
_manager.getBuffer().addCritical(val);
if (_manager.getDisplayOnScreenLevel() <= rec.getPriority()) {
// Default is CRIT
if (_manager.getDisplayOnScreenLevel() <= priority) {
if (_manager.displayOnScreen()) {
// wrapper and android logs already do time stamps, so reformat without the date
if (_manager.getContext().hasWrapper() || SystemVersion.isAndroid())
System.out.print(LogRecordFormatter.formatRecord(_manager, rec, false));
else
System.out.print(val);
//
// Display a popup on DTG
// Experimental, may disable or add a separate config after testing
// These also aren't translated.
// May be appropriate for advanced users only.
//
String msg = rec.getMessage();
if (priority >= Log.ERROR && msg != null && !SystemVersion.isAndroid()) {
ClientAppManager cmgr = _manager.getContext().clientAppManager();
if (cmgr != null) {
NotificationService ns = (NotificationService) cmgr.getRegisteredApp("desktopgui");
if (ns != null) {
String name;
Class cls = rec.getSource();
if (cls != null) {
name = cls.getSimpleName();
} else {
name = rec.getSourceName();
if (name == null)
name = "I2P";
}
ns.notify(name, null, priority, name, msg, null);
}
}
}
}
}
}