diff --git a/TwitchDownloaderWPF/Models/LogLevel.cs b/TwitchDownloaderWPF/Models/LogLevel.cs new file mode 100644 index 000000000..e3138023c --- /dev/null +++ b/TwitchDownloaderWPF/Models/LogLevel.cs @@ -0,0 +1,15 @@ +using System; + +namespace TwitchDownloaderWPF.Models +{ + [Flags] + internal enum LogLevel + { + None = 0, + Verbose = 1 << 0, + Info = 1 << 1, + Warning = 1 << 2, + Error = 1 << 3, + Ffmpeg = 1 << 4, + } +} \ No newline at end of file diff --git a/TwitchDownloaderWPF/Utils/WpfTaskProgress.cs b/TwitchDownloaderWPF/Utils/WpfTaskProgress.cs index 294f3edf9..255a304fe 100644 --- a/TwitchDownloaderWPF/Utils/WpfTaskProgress.cs +++ b/TwitchDownloaderWPF/Utils/WpfTaskProgress.cs @@ -1,5 +1,6 @@ using System; using TwitchDownloaderCore.Interfaces; +using TwitchDownloaderWPF.Models; namespace TwitchDownloaderWPF.Utils { @@ -13,6 +14,8 @@ internal class WpfTaskProgress : ITaskProgress private TimeSpan _lastTime1 = new(-1); private TimeSpan _lastTime2 = new(-1); + private readonly LogLevel _logLevel; + private readonly Action _handlePercent; private readonly Action _handleStatus; private readonly Action _handleLog; @@ -24,6 +27,8 @@ public WpfTaskProgress(Action handlePercent) _handleStatus = null; _handleLog = null; _handleFfmpegLog = null; + + _logLevel = LogLevel.None; } public WpfTaskProgress(Action handlePercent, Action handleStatus, Action handleLog, Action handleFfmpegLog = null) @@ -32,6 +37,13 @@ public WpfTaskProgress(Action handlePercent, Action handleStatus, A _handleStatus = handleStatus; _handleLog = handleLog; _handleFfmpegLog = handleFfmpegLog; + + // TODO: Make this user configurable + _logLevel = LogLevel.Info | LogLevel.Warning | LogLevel.Error; + if (handleFfmpegLog is not null) + { + _logLevel |= LogLevel.Ffmpeg; + } } public void SetStatus(string status) @@ -117,27 +129,42 @@ public void ReportProgress(int percent, TimeSpan time1, TimeSpan time2) public void LogVerbose(string logMessage) { - //_handleLog?.Invoke(logMessage); + if ((_logLevel & LogLevel.Verbose) != 0) + { + _handleLog?.Invoke(logMessage); + } } public void LogInfo(string logMessage) { - _handleLog?.Invoke(logMessage); + if ((_logLevel & LogLevel.Info) != 0) + { + _handleLog.Invoke(logMessage); + } } public void LogWarning(string logMessage) { - _handleLog?.Invoke(logMessage); + if ((_logLevel & LogLevel.Warning) != 0) + { + _handleLog?.Invoke(logMessage); + } } public void LogError(string logMessage) { - _handleLog?.Invoke(Translations.Strings.ErrorLog + logMessage); + if ((_logLevel & LogLevel.Error) != 0) + { + _handleLog?.Invoke(Translations.Strings.ErrorLog + logMessage); + } } public void LogFfmpeg(string logMessage) { - _handleFfmpegLog?.Invoke(logMessage); + if ((_logLevel & LogLevel.Ffmpeg) != 0) + { + _handleFfmpegLog?.Invoke(logMessage); + } } } } \ No newline at end of file