Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Languages/lang_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"{0} is now {1}": "{0} is now {1}",
"Enabled": "Enabled",
"Disabled": "Disabled",
"Privacy": "Privacy",
"Hide my username from the logs": "Hide my username from the logs",
"Replaces your username with **** in the logs. Restart UniGetUI to also hide it from already-recorded entries.": "Replaces your username with **** in the logs. Restart UniGetUI to also hide it from already-recorded entries.",
"Your last update attempt did not complete.": "Your last update attempt did not complete.",
"UniGetUI could not confirm whether the update succeeded. Open the log to see what happened.": "UniGetUI could not confirm whether the update succeeded. Open the log to see what happened.",
"View log": "View log",
Expand Down
3 changes: 3 additions & 0 deletions src/UniGetUI.Avalonia/CrashHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Versioning;
using System.Text;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;

namespace UniGetUI.Avalonia;
Expand Down Expand Up @@ -215,6 +216,8 @@ Inner exception details (depth level: {{i}})
// ignore
}

Error_String = Logger.Redact(Error_String);

Console.WriteLine(Error_String);

// Persist crash data so the next normal app launch can show the report.
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI.Avalonia/Infrastructure/AvaloniaAppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ __ __ _ ______ __ __ ______
Welcome to UniGetUI Version {CoreData.VersionName}
""";

Logger.RedactUsername = Core.SettingsEngine.Settings.Get(Core.SettingsEngine.Settings.K.RedactUsernameInLog);

Logger.ImportantInfo(textart);
Logger.ImportantInfo(" ");
Logger.ImportantInfo($"Build {CoreData.BuildNumber}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static void AppendToUpdateLog(string severity, string message)
lock (_updateLogLock)
{
if (_updateLogBuilder is null) return;
_updateLogBuilder.AppendLine($"[{DateTime.Now:HH:mm:ss}] [{severity}] {message}");
_updateLogBuilder.AppendLine($"[{DateTime.Now:HH:mm:ss}] [{severity}] {Logger.Redact(message)}");
FlushUpdateLogToDiskNoLock();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ private void ResetSettings(Visual? _)
[RelayCommand]
private void ShowRestartRequired() => RestartRequired?.Invoke(this, EventArgs.Empty);

[RelayCommand]
private void ToggleRedactUsername()
{
Logger.RedactUsername = CoreSettings.Get(CoreSettings.K.RedactUsernameInLog);
OnRestartRequired();
}

[RelayCommand]
private void NavigateToInterface() => NavigationRequested?.Invoke(this, typeof(Interface_P));
}
11 changes: 11 additions & 0 deletions src/UniGetUI.Avalonia/Views/Pages/SettingsPages/General.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
Command="{Binding ShowTelemetryDialogCommand}"
CommandParameter="{Binding $self}"/>

<settings:TranslatedTextBlock Text="Privacy"
FontWeight="SemiBold"
Margin="44,32,4,8"
automation:AutomationProperties.HeadingLevel="2"/>

<settings:CheckboxCard SettingName="RedactUsernameInLog"
CornerRadius="8"
Text="{t:Translate Hide my username from the logs}"
WarningText="{t:Translate Text='Replaces your username with **** in the logs. Restart UniGetUI to also hide it from already-recorded entries.'}"
StateChangedCommand="{Binding ToggleRedactUsernameCommand}"/>

<settings:TranslatedTextBlock Text="Manage UniGetUI settings"
FontWeight="SemiBold"
Margin="44,32,4,8"
Expand Down
97 changes: 37 additions & 60 deletions src/UniGetUI.Core.Logger/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,35 @@ public static class Logger
"session.log"
);

private static readonly string UserName = Environment.UserName;

// When enabled, the current user's name is replaced by **** in every logged line (privacy).
public static bool RedactUsername { get; set; }

public static string GetSessionLogPath() => SessionLogPath;

// Replaces the current user's name with **** when redaction is enabled (privacy).
// Public so other diagnostic surfaces (operation output, crash reports, update logs)
// can apply the same redaction before persisting or displaying their own content.
public static string Redact(string text)
{
if (!RedactUsername || UserName.Length == 0)
return text;
return text.Replace(UserName, "****", StringComparison.OrdinalIgnoreCase);
}

private static void Add(
string content,
LogEntry.SeverityLevel severity,
string caller
)
{
content = Redact(content);
Diagnostics.Debug.WriteLine($"[{caller}] " + content);
AppendToSessionLog(content);
LogContents.Add(new LogEntry(content, severity));
}

private static void AppendToSessionLog(string text)
{
try
Expand All @@ -34,103 +61,53 @@ private static void AppendToSessionLog(string text)
public static void ImportantInfo(
string s,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
AppendToSessionLog(s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Success));
}
) => Add(s, LogEntry.SeverityLevel.Success, caller);

public static void Debug(
string s,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
AppendToSessionLog(s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Debug));
}
) => Add(s, LogEntry.SeverityLevel.Debug, caller);

public static void Info(
string s,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
AppendToSessionLog(s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Info));
}
) => Add(s, LogEntry.SeverityLevel.Info, caller);

public static void Warn(
string s,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
AppendToSessionLog(s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Warning));
}
) => Add(s, LogEntry.SeverityLevel.Warning, caller);

public static void Error(
string s,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + s);
AppendToSessionLog(s);
LogContents.Add(new LogEntry(s, LogEntry.SeverityLevel.Error));
}
) => Add(s, LogEntry.SeverityLevel.Error, caller);

// Exception parameter log functions
public static void ImportantInfo(
Exception e,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
AppendToSessionLog(e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Success));
}
) => Add(e.ToString(), LogEntry.SeverityLevel.Success, caller);

public static void Debug(
Exception e,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
AppendToSessionLog(e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Debug));
}
) => Add(e.ToString(), LogEntry.SeverityLevel.Debug, caller);

public static void Info(
Exception e,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
AppendToSessionLog(e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Info));
}
) => Add(e.ToString(), LogEntry.SeverityLevel.Info, caller);

public static void Warn(
Exception e,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
AppendToSessionLog(e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Warning));
}
) => Add(e.ToString(), LogEntry.SeverityLevel.Warning, caller);

public static void Error(
Exception e,
[System.Runtime.CompilerServices.CallerMemberName] string caller = ""
)
{
Diagnostics.Debug.WriteLine($"[{caller}] " + e.ToString());
AppendToSessionLog(e.ToString());
LogContents.Add(new LogEntry(e.ToString(), LogEntry.SeverityLevel.Error));
}
) => Add(e.ToString(), LogEntry.SeverityLevel.Error, caller);

public static LogEntry[] GetLogs()
{
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI.Core.Settings/SettingsEngine_Names.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public enum K
DisableInstallerHostChangeWarning,
BunPreferLatestVersions,
TrayIconStyle,
RedactUsernameInLog,

Test1,
Test2,
Expand Down Expand Up @@ -199,6 +200,7 @@ public static string ResolveKey(K key)
K.DisableInstallerHostChangeWarning => "DisableInstallerHostChangeWarning",
K.BunPreferLatestVersions => "BunPreferLatestVersions",
K.TrayIconStyle => "TrayIconStyle",
K.RedactUsernameInLog => "RedactUsernameInLog",

K.Test1 => "TestSetting1",
K.Test2 => "TestSetting2",
Expand Down
1 change: 1 addition & 0 deletions src/UniGetUI.PackageEngine.Operations/AbstractOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public void Cancel()

protected void Line(string line, LineType type)
{
line = Logger.Redact(line);
if (type != LineType.ProgressIndicator)
LogList.Add((line, type));
LogLineAdded?.Invoke(this, (line, type));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using UniGetUI.Core.Logging;
using UniGetUI.PackageEngine.Enums;
using UniGetUI.PackageEngine.Interfaces;

Expand Down Expand Up @@ -285,6 +286,9 @@ EndTime is null
result.Add("0——————————————————————————————————————————");
result.Add("0");

for (int i = 0; i < result.Count; i++)
result[i] = Logger.Redact(result[i]);

if (verbose)
{
return CachedVerboseMessage = result;
Expand Down Expand Up @@ -438,6 +442,9 @@ EndTime is null
result.Add("0——————————————————————————————————————————");
result.Add("0");

for (int i = 0; i < result.Count; i++)
result[i] = Logger.Redact(result[i]);

if (verbose)
{
return CachedVerboseMessage = result;
Expand Down
2 changes: 1 addition & 1 deletion src/UniGetUI/AutoUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private static void AppendToUpdateLog(string severity, string message)
lock (_updateLogLock)
{
if (_updateLogBuilder is null) return;
_updateLogBuilder.AppendLine($"[{DateTime.Now:HH:mm:ss}] [{severity}] {message}");
_updateLogBuilder.AppendLine($"[{DateTime.Now:HH:mm:ss}] [{severity}] {Logger.Redact(message)}");
FlushUpdateLogToDiskNoLock();
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/UniGetUI/CrashHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Runtime.InteropServices;
using System.Text;
using UniGetUI.Core.Data;
using UniGetUI.Core.Logging;
using UniGetUI.Core.Tools;

namespace UniGetUI;
Expand Down Expand Up @@ -215,6 +216,8 @@ Inner exception details (depth level: {{i}})
// ignore
}

Error_String = Logger.Redact(Error_String);

Console.WriteLine(Error_String);

// Persist crash data so the next normal app launch can show the report.
Expand Down
2 changes: 2 additions & 0 deletions src/UniGetUI/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ __ __ _ ______ __ __ ______
Welcome to UniGetUI Version {CoreData.VersionName}
""";

Logger.RedactUsername = Core.SettingsEngine.Settings.Get(Core.SettingsEngine.Settings.K.RedactUsernameInLog);

Logger.ImportantInfo(textart);
Logger.ImportantInfo(" ");
Logger.ImportantInfo($"Build {CoreData.BuildNumber}");
Expand Down
11 changes: 11 additions & 0 deletions src/UniGetUI/Pages/SettingsPages/GeneralPages/General.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
Text="Manage telemetry settings"
/>

<widgets:TranslatedTextBlock Margin="4,32,4,8" FontWeight="SemiBold" Text="Privacy" />

<widgets:CheckboxCard
x:Name="RedactUsernameCheckbox"
CornerRadius="8"
SettingName="RedactUsernameInLog"
StateChanged="RedactUsername_StateChanged"
Text="Hide my username from the logs"
WarningText="Replaces your username with **** in the logs. Restart UniGetUI to also hide it from already-recorded entries."
/>

<widgets:TranslatedTextBlock
Margin="4,32,4,8"
FontWeight="SemiBold"
Expand Down
6 changes: 6 additions & 0 deletions src/UniGetUI/Pages/SettingsPages/GeneralPages/General.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ private void ForceUpdateUniGetUI_OnClick(object sender, RoutedEventArgs e)
private void ManageTelemetrySettings_Click(object sender, EventArgs e) =>
_ = DialogHelper.ShowTelemetryDialog();

private void RedactUsername_StateChanged(object sender, EventArgs e)
{
Logger.RedactUsername = RedactUsernameCheckbox.Checked;
ShowRestartBanner(this, e);
}

private void ImportSettings_Click(object sender, EventArgs e) => _ = _importSettings();

private async Task _importSettings()
Expand Down
Loading