From 61c1232690a9d64bf597b1227ea2f46e946bcbc3 Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sun, 23 Mar 2014 17:43:46 +0800 Subject: [PATCH] close #47 Add log level config --- Wox/App.config | 7 ++++++- Wox/Helper/Log.cs | 20 ++++++++++++++++++++ Wox/MainWindow.xaml.cs | 10 ++++++++-- Wox/PluginLoader/BasePluginLoader.cs | 8 ++++---- Wox/PluginLoader/CSharpPluginLoader.cs | 2 +- Wox/PluginLoader/PythonPluginLoader.cs | 2 +- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Wox/App.config b/Wox/App.config index e1eb5518f..f376f313b 100644 --- a/Wox/App.config +++ b/Wox/App.config @@ -14,7 +14,12 @@ + + - + + + + diff --git a/Wox/Helper/Log.cs b/Wox/Helper/Log.cs index 656320f66..c23785d23 100644 --- a/Wox/Helper/Log.cs +++ b/Wox/Helper/Log.cs @@ -11,5 +11,25 @@ namespace Wox.Helper { fileLogger.Error(msg); } + + public static void Debug(string msg) + { + fileLogger.Debug(msg); + } + + public static void Info(string msg) + { + fileLogger.Info(msg); + } + + public static void Warn(string msg) + { + fileLogger.Warn(msg); + } + + public static void Fatal(string msg) + { + fileLogger.Fatal(msg); + } } } diff --git a/Wox/MainWindow.xaml.cs b/Wox/MainWindow.xaml.cs index 136ded6cc..dcdedb9ff 100644 --- a/Wox/MainWindow.xaml.cs +++ b/Wox/MainWindow.xaml.cs @@ -73,7 +73,7 @@ namespace Wox globalHotkey.hookedKeyboardCallback += KListener_hookedKeyboardCallback; - this.Closing += new System.ComponentModel.CancelEventHandler(MainWindow_Closing); + this.Closing += MainWindow_Closing; } void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) @@ -93,6 +93,8 @@ namespace Wox //DwmDropShadow.DropShadowToWindow(this); WindowIntelopHelper.DisableControlBox(this); + + throw new Exception(); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) @@ -100,11 +102,15 @@ namespace Wox if (!System.Diagnostics.Debugger.IsAttached) { string error = "Wox has an error that can't be handled. " + e.ExceptionObject; - Log.Error(error); if (e.IsTerminating) { notifyIcon.Visible = false; MessageBox.Show(error); + Log.Fatal(error); + } + else + { + Log.Error(error); } } } diff --git a/Wox/PluginLoader/BasePluginLoader.cs b/Wox/PluginLoader/BasePluginLoader.cs index ab71816f6..a91e8b51a 100644 --- a/Wox/PluginLoader/BasePluginLoader.cs +++ b/Wox/PluginLoader/BasePluginLoader.cs @@ -71,7 +71,7 @@ namespace Wox.PluginLoader if (!File.Exists(configPath)) { - Log.Error(string.Format("parse plugin {0} failed: didn't find config file.", configPath)); + Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath)); return null; } @@ -84,7 +84,7 @@ namespace Wox.PluginLoader catch (Exception) { string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath); - Log.Error(error); + Log.Warn(error); #if (DEBUG) { throw new WoxException(error); @@ -98,7 +98,7 @@ namespace Wox.PluginLoader { string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language); - Log.Error(error); + Log.Warn(error); #if (DEBUG) { throw new WoxException(error); @@ -110,7 +110,7 @@ namespace Wox.PluginLoader { string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath); - Log.Error(error); + Log.Warn(error); #if (DEBUG) { throw new WoxException(error); diff --git a/Wox/PluginLoader/CSharpPluginLoader.cs b/Wox/PluginLoader/CSharpPluginLoader.cs index 520e407d3..9bcde2352 100644 --- a/Wox/PluginLoader/CSharpPluginLoader.cs +++ b/Wox/PluginLoader/CSharpPluginLoader.cs @@ -25,7 +25,7 @@ namespace Wox.PluginLoader List types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList(); if (types.Count == 0) { - Log.Error(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin", + Log.Warn(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin", metadata.Name)); continue; } diff --git a/Wox/PluginLoader/PythonPluginLoader.cs b/Wox/PluginLoader/PythonPluginLoader.cs index 644b82fbd..e5bd223b3 100644 --- a/Wox/PluginLoader/PythonPluginLoader.cs +++ b/Wox/PluginLoader/PythonPluginLoader.cs @@ -39,7 +39,7 @@ namespace Wox.PluginLoader PythonEngine.Shutdown(); } catch { - Log.Error("Could't find python environment, all python plugins disabled."); + Log.Warn("Could't find python environment, all python plugins disabled."); return false; } return true;