mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 11:46:30 +02:00
Better logger
1. Throw exception for fatal/error log when debugging 2. Write to debug output for warn/debug/info log when debugging 3. part of #355
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Wox.Core.Exception;
|
||||
using Wox.Infrastructure.Logger;
|
||||
using Wox.Plugin;
|
||||
|
||||
@@ -19,10 +20,10 @@ namespace Wox.Core.Plugin
|
||||
try
|
||||
{
|
||||
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
|
||||
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && o.GetInterfaces().Contains(typeof(IPlugin))).ToList();
|
||||
if (types.Count == 0)
|
||||
{
|
||||
Log.Warn(string.Format("Couldn't load plugin {0}: didn't find the class that implement IPlugin", metadata.Name));
|
||||
Log.Warn($"Couldn't load plugin {metadata.Name}: didn't find the class that implement IPlugin");
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -39,12 +40,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(string.Format("Couldn't load plugin {0}: {1}", metadata.Name, e.Message));
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
Log.Error(new WoxPluginException(metadata.Name, $"Couldn't load plugin", e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -47,7 +47,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(ExceptionFormatter.FormatExcpetion(e));
|
||||
Log.Fatal(e);
|
||||
}
|
||||
}
|
||||
PluginMetadata metadata = GetPluginMetadata(directory);
|
||||
@@ -63,7 +63,7 @@ namespace Wox.Core.Plugin
|
||||
string configPath = Path.Combine(pluginDirectory, pluginConfigName);
|
||||
if (!File.Exists(configPath))
|
||||
{
|
||||
Log.Warn(string.Format("parse plugin {0} failed: didn't find config file.", configPath));
|
||||
Log.Warn($"parse plugin {configPath} failed: didn't find config file.");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -77,40 +77,25 @@ namespace Wox.Core.Plugin
|
||||
// for plugin still use old ActionKeyword
|
||||
metadata.ActionKeyword = metadata.ActionKeywords?[0];
|
||||
}
|
||||
catch (System.Exception)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: json format is not valid", configPath);
|
||||
Log.Warn(error);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new WoxException(error);
|
||||
}
|
||||
#endif
|
||||
string msg = $"Parse plugin config {configPath} failed: json format is not valid";
|
||||
Log.Error(new WoxException(msg));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if (!AllowedLanguage.IsAllowed(metadata.Language))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: invalid language {1}", configPath, metadata.Language);
|
||||
Log.Warn(error);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new WoxException(error);
|
||||
}
|
||||
#endif
|
||||
string msg = $"Parse plugin config {configPath} failed: invalid language {metadata.Language}";
|
||||
Log.Error(new WoxException(msg));
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!File.Exists(metadata.ExecuteFilePath))
|
||||
{
|
||||
string error = string.Format("Parse plugin config {0} failed: ExecuteFile {1} didn't exist", configPath, metadata.ExecuteFilePath);
|
||||
Log.Warn(error);
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw new WoxException(error);
|
||||
}
|
||||
#endif
|
||||
string msg = $"Parse plugin config {configPath} failed: ExecuteFile {metadata.ExecuteFilePath} didn't exist";
|
||||
Log.Error(new WoxException(msg));
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error(e.Message);
|
||||
Log.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Wox.Core.Plugin
|
||||
/// </summary>
|
||||
public static void Init(IPublicAPI api)
|
||||
{
|
||||
if (api == null) throw new WoxCritialException("api is null");
|
||||
if (api == null) throw new WoxFatalException("api is null");
|
||||
|
||||
SetupPluginDirectories();
|
||||
API = api;
|
||||
@@ -164,7 +164,7 @@ namespace Wox.Core.Plugin
|
||||
if (customizedPluginConfig != null && customizedPluginConfig.Disabled) continue;
|
||||
if (IsInstantQueryPlugin(plugin))
|
||||
{
|
||||
Stopwatch.Debug($"Instant Query for {plugin.Metadata.Name}", () =>
|
||||
Stopwatch.Normal($"Instant QueryForPlugin for {plugin.Metadata.Name}", () =>
|
||||
{
|
||||
QueryForPlugin(plugin, query);
|
||||
});
|
||||
@@ -173,7 +173,10 @@ namespace Wox.Core.Plugin
|
||||
{
|
||||
ThreadPool.QueueUserWorkItem(state =>
|
||||
{
|
||||
QueryForPlugin(plugin, query);
|
||||
Stopwatch.Normal($"Normal QueryForPlugin for {plugin.Metadata.Name}", () =>
|
||||
{
|
||||
QueryForPlugin(plugin, query);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -184,7 +187,7 @@ namespace Wox.Core.Plugin
|
||||
try
|
||||
{
|
||||
List<Result> results = new List<Result>();
|
||||
var milliseconds = Stopwatch.Normal($"Query for {pair.Metadata.Name}", () =>
|
||||
var milliseconds = Stopwatch.Normal($"Plugin.Query cost for {pair.Metadata.Name}", () =>
|
||||
{
|
||||
results = pair.Plugin.Query(query) ?? results;
|
||||
results.ForEach(o => { o.PluginID = pair.Metadata.ID; });
|
||||
@@ -195,7 +198,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
throw new WoxPluginException(pair.Metadata.Name, e);
|
||||
throw new WoxPluginException(pair.Metadata.Name, $"QueryForPlugin failed", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,12 +242,7 @@ namespace Wox.Core.Plugin
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Log.Error($"Couldn't load plugin context menus {pluginPair.Metadata.Name}: {e.Message}");
|
||||
#if (DEBUG)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#endif
|
||||
Log.Error(new WoxPluginException(pluginPair.Metadata.Name, $"Couldn't load plugin context menus", e));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user