Skip to content

Commit

Permalink
Merge pull request #474 from agateau/fix-duplicated-log-messages
Browse files Browse the repository at this point in the history
fix duplicated log messages
  • Loading branch information
agateau authored Dec 11, 2024
2 parents 27dd0fe + 6957b4d commit bb43832
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ public void onWindowFocusChanged(boolean hasFocus) {
}

private void setupLogging(PwGame game) {
// Some log files end up with duplicated messages: looks like onCreate() can be called more
// than once. To avoid this, remove any existing printers.
NLog.clearPrinters();

AndroidLogFileOpener opener = new AndroidLogFileOpener(this);
LogFilePrinter printer =
new LogFilePrinter(Constants.LOG_FILENAME, Constants.LOG_MAX_SIZE, opener);
NLog.addPrinter(printer);

NLog.addPrinter(new AndroidNLogPrinter());

AndroidLogExporter exporter = new AndroidLogExporter(this, printer);
Expand Down
4 changes: 4 additions & 0 deletions core/src/com/agateau/utils/log/NLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static void backtrace() {
}
}

public static void clearPrinters() {
sPrinters.clear();
}

public static void addPrinter(Printer printer) {
sPrinters.add(printer);
}
Expand Down

0 comments on commit bb43832

Please sign in to comment.