Skip to content

Conversation

dcog989
Copy link
Contributor

@dcog989 dcog989 commented Sep 13, 2025

Enhance logging

  • User can now choose None, Error, Info, or Debug.
  • Use Flow.Launcher.${date:format=yyyy-MM-dd}.log as log file format.

Fixes #3812

User can now choose None, Error, Info, or Debug.
@prlabeler prlabeler bot added the bug Something isn't working label Sep 13, 2025
@github-actions github-actions bot added this to the 2.1.0 milestone Sep 13, 2025
Copy link

gitstream-cm bot commented Sep 13, 2025

🥷 Code experts: Jack251970, onesounds

Jack251970 has most 👩‍💻 activity in the files.
onesounds, Jack251970 have most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/Logger/Log.cs

Activity based on git-commit:

Jack251970
SEP
AUG
JUL
JUN
MAY
APR 12 additions & 80 deletions

Knowledge based on git-blame:
Jack251970: 19%

Flow.Launcher.Infrastructure/UserSettings/Settings.cs

Activity based on git-commit:

Jack251970
SEP
AUG
JUL 45 additions & 4 deletions
JUN 4 additions & 2 deletions
MAY 86 additions & 30 deletions
APR 34 additions & 83 deletions

Knowledge based on git-blame:
Jack251970: 32%
onesounds: 16%

Flow.Launcher/Languages/en.xaml

Activity based on git-commit:

Jack251970
SEP 1 additions & 0 deletions
AUG 4 additions & 0 deletions
JUL 48 additions & 13 deletions
JUN 21 additions & 0 deletions
MAY 33 additions & 4 deletions
APR 22 additions & 21 deletions

Knowledge based on git-blame:
onesounds: 36%
Jack251970: 21%

✨ Comment /gs review for LinearB AI review. Learn how to automate it here.

Copy link

gitstream-cm bot commented Sep 13, 2025

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

@coderabbitai coderabbitai bot added the enhancement New feature or request label Sep 13, 2025
Copy link
Contributor

coderabbitai bot commented Sep 13, 2025

📝 Walkthrough

Walkthrough

Expand log-level enum, change SetLogLevel to map public levels to NLog via the file rule and reconfigure existing loggers, rename log file pattern to include date with .log extension, add localization keys for NONE and ERROR, and insert a BOM in Settings.cs.

Changes

Cohort / File(s) Summary
Logging infrastructure
Flow.Launcher.Infrastructure/Logger/Log.cs
Expanded LOGLEVEL from {DEBUG, INFO} to {NONE, ERROR, INFO, DEBUG}; replaced previous switch+helper flow with direct mapping to NLog via LogManager.Configuration.FindRuleByName("file"), rule.SetLoggingLevels(...), and LogManager.ReconfigExistingLoggers(); changed log filename pattern to Flow.Launcher.${date:format=yyyy-MM-dd}.log; removed private helper methods; changed level-selection message to Debug.
User settings
Flow.Launcher.Infrastructure/UserSettings/Settings.cs
BOM (byte order mark) inserted at file start; no API or control-flow changes.
Localization
Flow.Launcher/Languages/en.xaml
Added LogLevelNONE ("Silent") and LogLevelERROR ("Error"); reordered existing LogLevel entries (INFO before DEBUG); no logic changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant UI as Settings UI
  participant Settings as UserSettings
  participant Log as Log.SetLogLevel
  participant NLog as NLog Config

  User->>UI: select log level (NONE/ERROR/INFO/DEBUG)
  UI->>Settings: persist selected level
  Settings->>Log: SetLogLevel(selected)
  Log->>NLog: FindRuleByName("file")
  Log->>NLog: Map public LOGLEVEL -> NLog level (Off/Error/Info/Debug)
  Log->>NLog: rule.SetLoggingLevels(mappedLevel, LogLevel.Fatal)
  Log->>NLog: LogManager.ReconfigExistingLoggers()
  Note right of Log: Emit Debug message about the selected level
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Pre-merge checks

❌ Failed checks (3 warnings)
Check name Status Explanation Resolution
Linked Issues Check ⚠️ Warning The changes do not implement the coding fixes requested in the linked issue [#3812]; that issue specifically requires changes to ShellLinkHelper.cs (wrap IShellLinkW calls in try/catch and log GetPath/GetArguments, suppress E_FAIL for GetDescription, use SLR_NO_UI when resolving, and release COM objects via Marshal.ReleaseComObject), whereas this PR only updates logging infrastructure (LOGLEVEL enum, SetLogLevel behavior, log filename, and language keys) and does not modify ShellLinkHelper.cs to stop the COMException spam. Implement the ShellLinkHelper.cs changes described in [#3812] (try/catch around IShellLinkW calls, special-case E_FAIL for GetDescription, use SLR_NO_UI, and ensure Marshal.ReleaseComObject), or remove the "Fixes #3812" claim and document how the logging changes alone resolve the reported spam.
Out of Scope Changes Check ⚠️ Warning The PR contains several changes that are outside the specific objectives of the linked issue: insertion of a BOM in Settings.cs, renaming the log file format, and adding/moving localization keys are not part of the ShellLinkHelper exception-handling objectives; adding selectable log levels is related to reducing visible spam but does not substitute for the targeted ShellLinkHelper fixes requested in [#3812]. Move unrelated housekeeping or localization edits into a separate PR or justify them in the description, and refocus this PR on the minimal ShellLinkHelper code changes needed to address the COMException log spam.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title "Enhanced logging" is concise and accurately reflects the primary intent of the changeset (adding selectable log levels and updating log-file naming), so it summarizes the main change for reviewers.
Description Check ✅ Passed The PR description clearly states the primary change (adding user-selectable log levels: None, Error, Info, Debug) and links the related issue, which aligns with the changes shown in the diff (enum expansion, language keys, and SetLogLevel adjustments); it is on-topic and adequate for this lenient check. Although concise, the description correctly summarizes the intent of the changeset.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)

70-86: Harden SetLogLevel: null-check rule, align DEBUG target, fix logger name

  • Add a null-check for the "file" rule to avoid NRE if config changes.
  • In DEBUG builds, mirror the same level onto the debug target rule so developer output respects the selected level.
  • Use nameof(Log) instead of nameof(Logger) to log the correct class name.

Apply:

         public static void SetLogLevel(LOGLEVEL level)
         {
-            var rule = LogManager.Configuration.FindRuleByName("file");
+            var rule = LogManager.Configuration.FindRuleByName("file");
+            if (rule is null)
+            {
+                Warn(nameof(Log), "NLog rule 'file' not found. Skipping log-level change.");
+                return;
+            }
 
             var nlogLevel = level switch
             {
                 LOGLEVEL.None => LogLevel.Off,
                 LOGLEVEL.Error => LogLevel.Error,
                 LOGLEVEL.Debug => LogLevel.Debug,
                 _ => LogLevel.Info
             };
 
             rule.SetLoggingLevels(nlogLevel, LogLevel.Fatal);
 
-            LogManager.ReconfigExistingLoggers();
+            #if DEBUG
+            var debugRule = LogManager.Configuration.FindRuleByName("debug");
+            debugRule?.SetLoggingLevels(nlogLevel, LogLevel.Fatal);
+            #endif
+
+            LogManager.ReconfigExistingLoggers();
 
-            // We can't log Info when level is set to Error or None, so we use Debug
-            Debug(nameof(Logger), $"Using log level: {level}.");
+            // Keep noise low at Error/None; this will only emit when allowed by current level.
+            Debug(nameof(Log), $"Using log level: {level}.");
         }
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)

343-343: Default log level → Info — confirm backwards compatibility with old saved values

LGTM. Please confirm existing user settings containing "DEBUG"/"INFO" (old enum names) deserialize to the new values (usually case-insensitive with JsonStringEnumConverter). If not, we’ll need a one-time migration or a tolerant converter.

You can validate with a quick unit test or by loading a settings JSON containing "LogLevel": "DEBUG" and "LogLevel": "INFO".

I can add a small deserialization test or a migration shim if desired.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eaa90b3 and d4a757b.

📒 Files selected for processing (3)
  • Flow.Launcher.Infrastructure/Logger/Log.cs (5 hunks)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-05T11:56:27.267Z
Learnt from: Jack251970
PR: Flow-Launcher/Flow.Launcher#3593
File: Flow.Launcher/HotkeyControlDialog.xaml:6-6
Timestamp: 2025-09-05T11:56:27.267Z
Learning: In Flow.Launcher's migration to iNKORE.UI.WPF.Modern UI framework, dialog resource keys like PopuBGColor, PopupButtonAreaBGColor, PopupButtonAreaBorderColor, and PopupTextColor are provided by the iNKORE.UI.WPF.Modern framework itself, not defined locally in the codebase theme files.

Applied to files:

  • Flow.Launcher/Languages/en.xaml
🧬 Code graph analysis (2)
Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)
  • Info (157-160)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)
Flow.Launcher.Infrastructure/Stopwatch.cs (2)
  • Debug (13-22)
  • Info (38-47)
🪛 GitHub Check: Check Spelling
Flow.Launcher.Infrastructure/Logger/Log.cs

[warning] 37-37:
MMdd is not a recognized word. (unrecognized-spelling)


[warning] 80-80:
nlog is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (3)
Flow.Launcher/Languages/en.xaml (1)

462-462: Whitespace-only change — OK

No functional change.

Flow.Launcher.Infrastructure/Logger/Log.cs (2)

170-174: Approve — enum expansion OK

rg search of C# files for '\b(DEBUG|INFO)\b' found only preprocessor #if DEBUG occurrences (no INFO matches or runtime "DEBUG"/"INFO" string checks).


35-39: Log filename changed — confirm cleanup/rotation still matches

Repo search shows only the new FileTarget in Flow.Launcher.Infrastructure/Logger/Log.cs:
FileName = CurrentLogDirectory.Replace(@"", "/") + "/Flow.Launcher.${date:format=yyyyMMdd}.log"
No other .log or ${shortdate} occurrences were found; .txt hits are NativeMethods.txt and NeedDelete.txt (unrelated). Verify any external packaging/installer/CI or Clear Logs code references .log (not .txt) and adjust/add rotation/archival (e.g., MaxArchiveFiles / ArchiveEvery) as needed.

Jack251970
Jack251970 previously approved these changes Sep 14, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
Flow.Launcher.Infrastructure/Logger/Log.cs (2)

37-39: Prefer Path.Combine and verify consumers of new .log extension

Use Path.Combine instead of Replace + string concat. Also verify any tooling/docs expecting .txt now handle .log.

-                FileName = CurrentLogDirectory.Replace(@"\", "/") + "/Flow.Launcher.${date:format=yyyyMMdd}.log",
+                FileName = Path.Combine(CurrentLogDirectory, "Flow.Launcher.${date:format=yyyyMMdd}.log"),

68-84: Make SetLogLevel null/compat‑safe and explicit about INFO; fix logger name

  • Adds fallback if FindRuleByName is unavailable/returns null.
  • Maps INFO explicitly.
  • Uses nameof(Log) to avoid confusion with NLog.Logger.
-            var rule = LogManager.Configuration.FindRuleByName("file");
-
-            var nlogLevel = level switch
-            {
-                LOGLEVEL.NONE => LogLevel.Off,
-                LOGLEVEL.ERROR => LogLevel.Error,
-                LOGLEVEL.DEBUG => LogLevel.Debug,
-                _ => LogLevel.Info
-            };
-
-            rule.SetLoggingLevels(nlogLevel, LogLevel.Fatal);
-
-            LogManager.ReconfigExistingLoggers();
-
-            // We can't log Info when level is set to Error or None, so we use Debug
-            Debug(nameof(Logger), $"Using log level: {level}.");
+            var nlogLevel = level switch
+            {
+                LOGLEVEL.NONE  => LogLevel.Off,
+                LOGLEVEL.ERROR => LogLevel.Error,
+                LOGLEVEL.INFO  => LogLevel.Info,
+                LOGLEVEL.DEBUG => LogLevel.Debug,
+                _              => LogLevel.Info
+            };
+
+            var config = LogManager.Configuration;
+            if (config is null)
+                return;
+
+            var rule = config.FindRuleByName("file");
+            if (rule is null)
+            {
+                // Fallback for older NLog or missing RuleName
+                foreach (var r in config.LoggingRules)
+                {
+                    if (r.RuleName == "file") { rule = r; break; }
+                }
+            }
+            if (rule is null)
+                return;
+
+            rule.SetLoggingLevels(nlogLevel, LogLevel.Fatal);
+            LogManager.ReconfigExistingLoggers();
+
+            // We can't log Info when level is set to Error or None, so we use Debug
+            Debug(nameof(Log), $"Using log level: {level}.");
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d4a757b and 2ae57ae.

📒 Files selected for processing (3)
  • Flow.Launcher.Infrastructure/Logger/Log.cs (3 hunks)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs (1 hunks)
  • Flow.Launcher/Languages/en.xaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • Flow.Launcher.Infrastructure/UserSettings/Settings.cs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/Languages/en.xaml
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)
Flow.Launcher.Infrastructure/Stopwatch.cs (2)
  • Debug (13-22)
  • Info (38-47)
🪛 GitHub Check: Check Spelling
Flow.Launcher.Infrastructure/Logger/Log.cs

[warning] 37-37:
MMdd is not a recognized word. (unrecognized-spelling)


[warning] 78-78:
nlog is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (3)
Flow.Launcher.Infrastructure/Logger/Log.cs (3)

68-84: Confirm intent: user level only applies to file target

In DEBUG builds the OutputDebugString target remains at Debug; user setting won’t affect it. Confirm this is desired UX.


70-76: Double‑check NONE→Off behavior with SetLoggingLevels

NLog should produce no output when min=Off and max=Fatal, but please verify at runtime that NONE truly silences the file logs.


168-171: Enum expansion impact check

Ensure settings persistence, defaults, and localization bindings handle NONE/ERROR correctly (migrations, UI selection, CLI/env if any).

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
Flow.Launcher.Infrastructure/Logger/Log.cs (2)

37-37: Prefer Path.Combine; consider retention policy.

  • Build the path without manual slash replacement.
  • With per-day filenames, old logs will accumulate indefinitely. Consider NLog retention (ArchiveEvery/MaxArchiveFiles) or a pruning job.
-                FileName = CurrentLogDirectory.Replace(@"\", "/") + "/Flow.Launcher.${date:format=yyyy-MM-dd}.log",
+                FileName = Path.Combine(CurrentLogDirectory, "Flow.Launcher.${date:format=yyyy-MM-dd}.log"),

Alternative (keeps a constant file and lets NLog archive daily, auto-cleaning):

-                FileName = Path.Combine(CurrentLogDirectory, "Flow.Launcher.${date:format=yyyy-MM-dd}.log"),
+                FileName = Path.Combine(CurrentLogDirectory, "Flow.Launcher.log"),
+                ArchiveEvery = FileArchivePeriod.Day,
+                ArchiveNumbering = ArchiveNumberingMode.Date,
+                ArchiveDateFormat = "yyyy-MM-dd",
+                MaxArchiveFiles = 30,

70-70: Nit: variable name trips spelling checks.

Rename nlogLevel → nLogLevel or selectedNLogLevel.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ae57ae and c2fcf64.

📒 Files selected for processing (1)
  • Flow.Launcher.Infrastructure/Logger/Log.cs (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)
Flow.Launcher.Infrastructure/Stopwatch.cs (2)
  • Debug (13-22)
  • Info (38-47)
🪛 GitHub Check: Check Spelling
Flow.Launcher.Infrastructure/Logger/Log.cs

[warning] 70-70:
nlog is not a recognized word. (unrecognized-spelling)


[warning] 78-78:
nlog is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (1)
Flow.Launcher.Infrastructure/Logger/Log.cs (1)

168-171: No migration risk — LogLevel persisted as string

Settings.LogLevel is annotated with [JsonConverter(typeof(JsonStringEnumConverter))], so stored values are enum names (strings) and reordering the enum will not remap persisted settings. (Flow.Launcher.Infrastructure/UserSettings/Settings.cs:343)

@Jack251970 Jack251970 merged commit 51df66e into Flow-Launcher:dev Sep 14, 2025
8 checks passed
@Jack251970
Copy link
Member

@dcog989 Thanks for your contribution!

@dcog989
Copy link
Contributor Author

dcog989 commented Sep 14, 2025

@Jack251970 - my pleasure. Thanks for your tidy / enhancements to the PR. :)

@dcog989 dcog989 deleted the logging-enhanced branch September 14, 2025 13:03
TBM13 pushed a commit to TBM13/Flow.Launcher that referenced this pull request Sep 17, 2025
@jjw24 jjw24 removed the bug Something isn't working label Sep 18, 2025
@jjw24 jjw24 changed the title Enhanced logging Enhanced logging with additional levels and distinct log file format Sep 18, 2025
@prlabeler prlabeler bot added the bug Something isn't working label Sep 18, 2025
@jjw24 jjw24 removed the bug Something isn't working label Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: log spam from COM exception
3 participants