Skip to content

Commit

Permalink
add debug logging level (#1605)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored Oct 11, 2024
1 parent 6628a0a commit 3618dbb
Show file tree
Hide file tree
Showing 3 changed files with 250 additions and 131 deletions.
28 changes: 23 additions & 5 deletions OneMore/Commands/Settings/GeneralSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,19 @@ public GeneralSheet(SettingsProvider provider) : base(provider)
}

checkUpdatesBox.Checked = settings.Get("checkUpdates", false);
verboseBox.Checked = settings.Get("verbose", false);
experimentalBox.Checked = settings.Get("experimental", false);

// <logging>verbose|debug</logging> is the new way
// <verbose>true</verbose> was the old way
var loglevel = settings.Get("logging", string.Empty).ToLower();
verboseBox.Checked = loglevel.Length == 0
? settings.Get("verbose", false)
: loglevel.In("verbose", "debug");

if (loglevel == "debug")
{
verboseBox.Enabled = false;
}
}


Expand Down Expand Up @@ -125,11 +136,18 @@ public override bool CollectSettings()
? settings.Add("checkUpdates", true) || save
: settings.Remove("checkUpdates") || save;

// requires a restart
updated = verboseBox.Checked
? settings.Add("verbose", true) || updated
: settings.Remove("verbose") || updated;
// does not require a restart; only Enabled if !debug
if (verboseBox.Enabled)
{
save = verboseBox.Checked
? settings.Add("logging", "verbose") || save
: settings.Remove("logging") || save;

((Logger)logger).SetLoggingLevel(verboseBox.Checked, false);
save = settings.Remove("verbose") || save;
}

// requires a restart
updated = experimentalBox.Checked
? settings.Add("experimental", true) || updated
: settings.Remove("experimental") || updated;
Expand Down
96 changes: 63 additions & 33 deletions OneMore/Helpers/ILogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,43 @@ public interface ILogger : IDisposable
string LogPath { get; }


/// <summary>
/// If debug logging is enabled, writes a blank line to the log file
/// </summary>
void Debug();


/// <summary>
/// If debug logging is enabled, writes a text message along with a newline.
/// Could be a new entry or an entry started with a Write
/// </summary>
/// <param name="message"></param>
void Debug(string message);


/// <summary>
/// If debug logging is enabled, writes the XML of the given XElement
/// </summary>
/// <param name="element"></param>
void Debug(XElement element);


/// <summary>
/// If debug logging is enabled, stops the stopwatch and Writes a message along
/// with the mm.ss timespan since the stopwatch was started.
/// </summary>
/// <param name="message">The message to log</param>
/// <param name="keepRunning">True to keep the timer running</param>
void DebugTime(string message, bool keepRunning = false);


/// <summary>
/// Dumps all accessible properties of the given object to JSON
/// </summary>
/// <param name="obj"></param>
void Dump(object obj);


/// <summary>
/// Ends the current log section; clears the preamble
/// </summary>
Expand Down Expand Up @@ -53,10 +90,33 @@ public interface ILogger : IDisposable


/// <summary>
/// Dumps all accessible properties of the given object to JSON
/// If verbose logging is enabled, writes a blank line to the log file
/// </summary>
/// <param name="obj"></param>
void Dump(object obj);
void Verbose();


/// <summary>
/// If verbose logging is enabled, writes a text message along with a newline.
/// Could be a new entry or an entry started with a Write
/// </summary>
/// <param name="message"></param>
void Verbose(string message);


/// <summary>
/// If verbose logging is enabled, writes the XML of the given XElement
/// </summary>
/// <param name="element"></param>
void Verbose(XElement element);


/// <summary>
/// If verbose logging is enabled, stops the stopwatch and Writes a message along
/// with the mm.ss timespan since the stopwatch was started.
/// </summary>
/// <param name="message">The message to log</param>
/// <param name="keepRunning">True to keep the timer running</param>
void VerboseTime(string message, bool keepRunning = false);


/// <summary>
Expand Down Expand Up @@ -112,36 +172,6 @@ public interface ILogger : IDisposable
void WriteLine(XElement element);


/// <summary>
/// If verbose logging is enabled, writes a blank line to the log file
/// </summary>
void Verbose();


/// <summary>
/// If verbose logging is enabled, writes a text message along with a newline.
/// Could be a new entry or an entry started with a Write
/// </summary>
/// <param name="message"></param>
void Verbose(string message);


/// <summary>
/// If verbose logging is enabled, writes the XML of the given XElement
/// </summary>
/// <param name="element"></param>
void Verbose(XElement element);


/// <summary>
/// If verbose logging is enabled, stops the stopwatch and Writes a message along
/// with the mm.ss timespan since the stopwatch was started.
/// </summary>
/// <param name="message">The message to log</param>
/// <param name="keepRunning">True to keep the timer running</param>
void VerboseTime(string message, bool keepRunning = false);


/// <summary>
/// Stops the stopwatch and Writes a message along with the mm.ss timespan
/// since the stopwatch was started.
Expand Down
Loading

0 comments on commit 3618dbb

Please sign in to comment.