Proposal: Logs rotation for DueControlServer and DuetWebServer
-
Have you guys ever considered the possibility of adding file logs rotation to the DuetControlServer and the DuetWebServer ?
For the DuetControlServer is pretty straight forward adding another rule in the config with a FileTarget
using NLog; using NLog.Config; using NLog.Targets; var config = new LoggingConfiguration(); // Define file target with log rotation var fileTarget = new FileTarget("logfile") { FileName = "/opt/dsf/sd/sys/log-${shortdate}.log", ArchiveFileName = ""/opt/dsf/sd/sys/archive/log-{#}.log", // Archived files pattern ArchiveNumbering = ArchiveNumberingMode.Rolling, ArchiveAboveSize = 10 * 1024 * 1024, // 10 MB size limit MaxArchiveFiles = 5, // Keep max 5 archive files ConcurrentWrites = true, KeepFileOpen = false, Encoding = System.Text.Encoding.UTF8, Layout = "${longdate} [thread-${threadname:whenEmpty=${threadid}}] ${uppercase:${level}} - ${message}" }; // Add the target to configuration config.AddTarget(fileTarget); // Define a rule to log everything from Debug level and higher var rule = new LoggingRule("*", LogLevel.Debug, fileTarget); config.LoggingRules.Add(rule); // Apply configuration LogManager.Configuration = config;
Notice how, in the code snippet above, the pattern layout that includes the current thread that is running, it might be very handy since DCS is a multi-threaded program.
For the DuetWebServer it could get very complex since Microsoft default logger for ASP.NET does not have file logs rotation options; there are some workaround using Serilog but maybe it would be easier to just use NLog as well, or Log4net even better
-
@fragrama17 wouldnt setting up logrotate on raspbian be more straightforward?
-
@fragrama17 The current NLog/Microsoft.Logging configurations just print to the console, although there's a new logging mode in 3.6 to log directly to the web interface on demand.
journald
collects those console outputs and AFAIK it already rotates the logs automatically once they exceed a certain threshold. Hence I don't see why DCS and DWS need to do it, too.In previous image versions
rsyslog
captured DCS/DWS output as well and it did not rotate any logs, which unfortunately could lead to the SD card getting filled up, especially if DCS was left indebug
logging mode. That's why I added an item to the release notes stating that this service should be uninstalled if possible. It isn't an issue any more in the latest Debian Bookworm-based images. -
@oliof NLog is already being configured for ConsoleTarget, I think it's way easier to just add another target (FileTarget for rotation) in the source code (this way it will work on every os), instead of using something like logrotate that is specific to linux machines
-
@chrishamm would it be possible to add at least the thread-name/id in the pattern layout for debug purposes ?
using something like the following:"${longdate} [thread-${threadname:whenEmpty=${threadid}}] ${uppercase:${level}} - ${message}"
I am aware that DSF is based on LinuxAPI (especially for SPI and GPIO tasks) but, since .NET is cross-platform, I think it's best practice to configure a proper logger for DCS and DWS that will work potentially on every platform supported by .NET; this way we won't need to worry about logs rotation anymore.
There's a library provided by Microsoft https://github.com/dotnet/iot that provides abstractions for any sort of GPIO driver (I2C, SPI, PWM ecc..) using System call APIs based on where we run the programs (Linux or Windows); this way DSF could be potentially extended to other platforms