dosbox-staging icon indicating copy to clipboard operation
dosbox-staging copied to clipboard

Add option to write logs to a file

Open johnnovak opened this issue 2 years ago • 5 comments

Currently, the logs are only printed to stdout. Linux users can more easily redirect this to a file, but this is more problematic on Windows and macOS. Especially if DOSBox is launched from the GUI, then it might be impossible to inspect the logs.

Also, the ability to inspect logs after the game has exited (or crashed) could be very useful for troubleshooting issues. Regular users could attach the log file from the last run to help us investigate problems.

Therefore, introducing a simple config option and corresponding command line switch override to write logs also to a file would be a very useful addition.

We should implement a rolling scheme that keeps the logs from the last N number of runs and renames them to dosbox-staging.log.001, dosbox-staging.log.002, etc.

johnnovak avatar Jan 01 '23 23:01 johnnovak

Loguru has out-of-the-box support for writing to file:

https://github.com/emilk/loguru#usage

Initial thoughts on a conf setting (please slice and dice!):

[dosbox]
log_type = console / file / both / none
# Where:
#  console: writes to console-only (not to file)
#  file:    writes to file-only, specified in the log_file setting
#  both:    writes to both the console and to file.
#  none:    disables all logging

log_file = (empty) or custom path 
# Where:
# <custom> : When log_type is 'both' or 'file', writes to the
#            given path. If the filename ends in one or more 
#            digits, then that many logs will be rotated.
#            Examples:
#            log.10: would rotate 10 files, log.01 through log.10
#            game-3: would rotate 3 files: game-1 through game-3.
#
#  <empty> : defaults to primary conf ./log/dosbox-staging.log.4
#            Where the 4 indicates that four logs with be rotated.

kcgen avatar Jan 01 '23 23:01 kcgen

Initial thoughts on a conf setting (please slice and dice!):

That looks great @kcgen, I like the flexibility of the log_file param and the defaults.

johnnovak avatar Jan 02 '23 00:01 johnnovak

Related: going forward, there will be a way to display the logs on macOS when using DOSBox from the Finder, after all 🚀 https://github.com/dosbox-staging/dosbox-staging/pull/2352

johnnovak avatar Mar 22 '23 02:03 johnnovak

Tagging w/ help wanted - this might be a fun/smallish ticket for anyone out there interested in helping out!

Loguru is a great 3rd party logging system (and very nice to work with in C++), and DOSBox's conf system is relatively straight forward (to add the above string options).

kcgen avatar Mar 22 '23 04:03 kcgen

Related:

  • #4032

Torinde avatar Aug 07 '25 08:08 Torinde