Skip to content

Commit

Permalink
Added settings to handle logging customization
Browse files Browse the repository at this point in the history
- At first start logging is always Debug, only after that the user settings will be read and override the default.
- Logging levels: Debug > Fatal > Error > Warn > Info
   - this means that selecting Debug will show also every other logged message, while selecting info will show only the green messages
  • Loading branch information
easly1989 committed Nov 11, 2019
1 parent f8d40f7 commit 993725b
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 6 deletions.
10 changes: 9 additions & 1 deletion DFAssist/DFAssistPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ public void InitPlugin(MainControl mainControl)
_mainControl.LanguageComboBox.ValueMember = "Code";

_mainControl.TtsVoicesComboBox.DataSource = TTSHelper.Instance.AvailableVoices.Select(x => x.VoiceInfo.Name).ToArray();

_mainControl.LogLevelComboBox.DataSource = new []
{
"Debug",
"Info",
"Warn",
"Error",
"Fatal",
};

_pluginData.tpPluginSpace.Controls.Add(_mainControl);

ACTPluginSettingsHelper.Instance.LoadSettings();
Expand Down
4 changes: 3 additions & 1 deletion DFAssist/Helpers/ACTPluginSettingsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public void LoadSettings()
_xmlSettingsSerializer.AddControlSetting(_mainControl.TtsVoicesComboBox.Name, _mainControl.TtsVoicesComboBox);
_xmlSettingsSerializer.AddControlSetting(_mainControl.PersistToasts.Name, _mainControl.PersistToasts);
_xmlSettingsSerializer.AddControlSetting(_mainControl.EnableTestEnvironment.Name, _mainControl.EnableTestEnvironment);
_xmlSettingsSerializer.AddControlSetting(_mainControl.LogLevelComboBox.Name, _mainControl.LogLevelComboBox);
_xmlSettingsSerializer.AddControlSetting(_mainControl.EnableActToast.Name, _mainControl.EnableActToast);
_xmlSettingsSerializer.AddControlSetting(_mainControl.TelegramCheckBox.Name, _mainControl.TelegramCheckBox);
_xmlSettingsSerializer.AddControlSetting(_mainControl.TelegramTokenTextBox.Name, _mainControl.TelegramTokenTextBox);
Expand Down Expand Up @@ -104,7 +105,6 @@ public void LoadSettings()
{
_logger.Write($"Selected TTS Voice: {_mainControl.TtsVoicesComboBox.SelectedValue}", LogLevel.Debug);
}
_logger.Write($"Enable Test Environment: {_mainControl.EnableTestEnvironment.Checked}", LogLevel.Debug);
_logger.Write($"Enable Discord Notifications: {_mainControl.DiscordCheckBox.Checked}", LogLevel.Debug);
if(_mainControl.DiscordCheckBox.Checked)
{
Expand All @@ -123,6 +123,8 @@ public void LoadSettings()
_logger.Write($"Pushbullet Token: {_mainControl.PushBulletTokenTextBox.Text}", LogLevel.Debug);
_logger.Write($"Pushbullet ChatId: {_mainControl.PushBulletDeviceIdTextBox.Text}", LogLevel.Debug);
}
_logger.Write($"Enable Test Environment: {_mainControl.EnableTestEnvironment.Checked}", LogLevel.Debug);
_logger.Write($"Log Level Selected: {_mainControl.LogLevelComboBox.SelectedValue}", LogLevel.Debug);
_logger.Write("Settings Loaded!", LogLevel.Debug);
}

Expand Down
1 change: 1 addition & 0 deletions DFAssist/Helpers/DFAssistRepositoriesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ private void UpdateTranslations()
_mainControl.DiscordUsernameLabel.Text = _localizationRepository.GetText("ui-discord-username-display-text");
_mainControl.DiscordWebhookLabel.Text = _localizationRepository.GetText("ui-discord-webhook-display-text");
_mainControl.TestSettings.Text = _localizationRepository.GetText("ui-test-settings-group");
_mainControl.LogLevelSelectionLabel.Text = _localizationRepository.GetText("ui-test-log-level-selction-label");

_logger.Write("UI Updated!", LogLevel.Debug);
}
Expand Down
25 changes: 21 additions & 4 deletions DFAssist/Helpers/DFAssistUIInteractionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public DFAssistUIInteractionHelper()
_mainControl.PushBulletDeviceIdTextBox.Enabled = _mainControl.PushBulletCheckbox.Checked;
_mainControl.DiscordWebhookTextBox.Enabled = _mainControl.DiscordCheckBox.Checked;
_mainControl.DiscordUsernameTextBox.Enabled = _mainControl.DiscordCheckBox.Checked;

// force initialization of combobox values, not related a subvalue (like the language)
LogLevelComboBoxOnSelectedValueChanged(this, new EventArgs());
TtsVoicesComboBoxOnSelectedValueChanged(this, new EventArgs());
}

public void Subscribe()
Expand All @@ -56,10 +60,9 @@ public void Subscribe()
_mainControl.PushBulletCheckbox.CheckStateChanged += EnablePushBulletOnCheckedChanged;
_mainControl.ClearLogButton.Click += ClearLogsButton_Click;
_mainControl.TestConfigurationButton.Click += TestConfigurationButton_Click;

_mainControl.LogLevelComboBox.SelectedValueChanged += LogLevelComboBoxOnSelectedValueChanged;
}


public void UnSubscribe()
{
if (!_subscribed)
Expand All @@ -79,6 +82,20 @@ public void UnSubscribe()
_mainControl.PushBulletCheckbox.CheckStateChanged -= EnablePushBulletOnCheckedChanged;
_mainControl.ClearLogButton.Click -= ClearLogsButton_Click;
_mainControl.TestConfigurationButton.Click -= TestConfigurationButton_Click;
_mainControl.LogLevelComboBox.SelectedValueChanged += LogLevelComboBoxOnSelectedValueChanged;
}

private void LogLevelComboBoxOnSelectedValueChanged(object sender, EventArgs e)
{
var selectedValue = _mainControl.LogLevelComboBox.SelectedValue as string;
if(string.IsNullOrWhiteSpace(selectedValue) || !Enum.TryParse(selectedValue, out LogLevel logLevel))
{
_logger.Write($"UI: [LogLevel] Unable to change log level", LogLevel.Error);
return;
}

_logger.SetLoggingLevel(logLevel);
_logger.Write($"UI: [LogLevel] Desired Value: {_mainControl.LogLevelComboBox.SelectedValue}", LogLevel.Debug);
}

private void TtsVoicesComboBoxOnSelectedValueChanged(object sender, EventArgs e)
Expand Down Expand Up @@ -155,14 +172,14 @@ private void PersistToastsOnCheckedChanged(object sender, EventArgs e)
return;
}

_logger.Write($"UI: [PersistentToasts] Key found in the registry, Removing value!", LogLevel.Debug);
_logger.Write("UI: [PersistentToasts] Key found in the registry, Removing value!", LogLevel.Debug);
key.DeleteValue("ShowInActionCenter");
}
}
}
catch (Exception ex)
{
_logger.Write(ex, $"UI: Unable to remove/add the registry key to make Toasts persistent!", LogLevel.Error);
_logger.Write(ex, "UI: Unable to remove/add the registry key to make Toasts persistent!", LogLevel.Error);
}
}

Expand Down
23 changes: 23 additions & 0 deletions DFAssist/MainControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class MainControl : UserControl
public Label PushBulletDeviceIdlabel;
public Label PushBulletTokenLabel;
public Label TtsVoiceSelectionLabel;
public Label LogLevelSelectionLabel;

public TextBox LanguageValue;
public TextBox TelegramChatIdTextBox;
Expand All @@ -60,6 +61,7 @@ public class MainControl : UserControl

public ComboBox LanguageComboBox;
public ComboBox TtsVoicesComboBox;
public ComboBox LogLevelComboBox;

public RichTextBox LoggingRichTextBox;

Expand All @@ -78,6 +80,8 @@ private void InitializeComponent()
LanguageValue = new TextBox();
LanguageComboBox = new ComboBox();
TtsVoicesComboBox = new ComboBox();
LogLevelSelectionLabel = new Label();
LogLevelComboBox = new ComboBox();
EnableTestEnvironment = new CheckBox();
TtsVoiceSelectionLabel = new Label();
TtsCheckBox = new CheckBox();
Expand Down Expand Up @@ -365,6 +369,23 @@ private void InitializeComponent()
EnableTestEnvironment.Text = "Enable Test Environment";
EnableTestEnvironment.UseVisualStyleBackColor = true;
//
// _logLevelSelectionLabel
//
LogLevelSelectionLabel.AutoSize = true;
LogLevelSelectionLabel.Location = new Point(3, 45);
LogLevelSelectionLabel.Name = "LogLevelSelectionLabel";
LogLevelSelectionLabel.TabStop = false;
LogLevelSelectionLabel.Text = "Selected Voice";
//
// _logLevelComboBox
//
LogLevelComboBox.DropDownStyle = ComboBoxStyle.DropDownList;
LogLevelComboBox.FormattingEnabled = true;
LogLevelComboBox.Location = new Point(90, 45);
LogLevelComboBox.Name = "LogLevelComboBox";
LogLevelComboBox.Size = new Size(390, 25);
LogLevelComboBox.TabIndex = 18;
//
// _appTabControl
//
_appTabControl.Dock = DockStyle.Fill;
Expand Down Expand Up @@ -592,6 +613,8 @@ private void InitializeComponent()
Dock = DockStyle.Top;
TestSettings.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
TestSettings.Controls.Add(EnableTestEnvironment);
TestSettings.Controls.Add(LogLevelSelectionLabel);
TestSettings.Controls.Add(LogLevelComboBox);
TestSettings.Name = "TestSettings";
TestSettings.TabStop = false;
TestSettings.Text = "Test Settings";
Expand Down
2 changes: 2 additions & 0 deletions DFAssist/Resources/localization/de-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"ui-disable-toasts": "Toasts deaktivieren",
"ui-flash-taskbar": "Flash-Taskleiste, wenn eine Benachrichtigung empfangen wird",

"ui-test-log-level-selction-label": "Protokollstufe",

"ui-general-settings-group": "Allgemeine Einstellungen",
"ui-toast-settings-group": "Toast-Einstellungen",
"ui-tts-settings-group": "Einstellungen für Text zu Sprache",
Expand Down
2 changes: 2 additions & 0 deletions DFAssist/Resources/localization/en-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

"ui-disable-toasts": "Disable Toasts",
"ui-flash-taskbar": "Flash Taskbar when a Notification is received",

"ui-test-log-level-selction-label": "Log Level",

"ui-general-settings-group": "General Settings",
"ui-toast-settings-group": "Toasts Settings",
Expand Down
2 changes: 2 additions & 0 deletions DFAssist/Resources/localization/fr-fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"ui-disable-toasts": "Désactiver les notifications",
"ui-flash-taskbar": "La barre de tâches clignote quand une notification est reçue",

"ui-test-log-level-selction-label": "Niveau de journalisation",

"ui-general-settings-group": "Paramètres généraux",
"ui-toast-settings-group": "Paramètres des notifications",
"ui-tts-settings-group": "Paramètres de synthèse vocale",
Expand Down
2 changes: 2 additions & 0 deletions DFAssist/Resources/localization/ja-jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"ui-disable-toasts": "トーストを無効にする",
"ui-flash-taskbar": "通知を受け取ったときにタスクバーをフラッシュする",

"ui-test-log-level-selction-label": "ログレベル",

"ui-general-settings-group": "一般設定",
"ui-toast-settings-group": "トースト設定",
"ui-tts-settings-group": "テキスト読み上げ設定",
Expand Down
2 changes: 2 additions & 0 deletions DFAssist/Resources/localization/ko-kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"ui-disable-toasts": "토스트 비활성화",
"ui-flash-taskbar": "알림이 수신되면 Flash 작업 표시 줄",

"ui-test-log-level-selction-label": "로그 레벨",

"ui-general-settings-group": "일반 설정",
"ui-toast-settings-group": "토스트 설정",
"ui-tts-settings-group": "TTS 설정",
Expand Down

0 comments on commit 993725b

Please sign in to comment.