Skip to content
This repository has been archived by the owner on Feb 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #112 from theClueless/fuzzyMatchUpdates
Browse files Browse the repository at this point in the history
Fuzzy match logic update
  • Loading branch information
jjw24 authored Jan 13, 2020
2 parents 92febf0 + 504c08a commit 6cad4bc
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 186 deletions.
126 changes: 60 additions & 66 deletions Wox.Infrastructure/Logger/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,53 @@ private static bool FormatValid(string message)
return valid;
}

/// <param name="message">example: "|prefix|unprefixed" </param>
public static void Error(string message)


[MethodImpl(MethodImplOptions.Synchronized)]
public static void Exception(string className, string message, System.Exception exception, [CallerMemberName] string methodName = "")
{
if (string.IsNullOrWhiteSpace(className))
{
LogFaultyFormat($"Fail to specify a class name during logging of message: {message ?? "no message entered"}");
}

if (string.IsNullOrWhiteSpace(message))
{ // todo: not sure we really need that
LogFaultyFormat($"Fail to specify a message during logging");
}

if (!string.IsNullOrWhiteSpace(methodName))
{
className += "." + methodName;
}

ExceptionInternal(className, message, exception);
}

private static void ExceptionInternal(string classAndMethod, string message, System.Exception e)
{
var logger = LogManager.GetLogger(classAndMethod);

System.Diagnostics.Debug.WriteLine($"ERROR|{message}");

logger.Error("-------------------------- Begin exception --------------------------");
logger.Error(message);

do
{
logger.Error($"Exception full name:\n <{e.GetType().FullName}>");
logger.Error($"Exception message:\n <{e.Message}>");
logger.Error($"Exception stack trace:\n <{e.StackTrace}>");
logger.Error($"Exception source:\n <{e.Source}>");
logger.Error($"Exception target site:\n <{e.TargetSite}>");
logger.Error($"Exception HResult:\n <{e.HResult}>");
e = e.InnerException;
} while (e != null);

logger.Error("-------------------------- End exception --------------------------");
}

private static void LogInternal(string message, LogLevel level)
{
if (FormatValid(message))
{
Expand All @@ -57,8 +102,8 @@ public static void Error(string message)
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);

System.Diagnostics.Debug.WriteLine($"ERROR|{message}");
logger.Error(unprefixed);
System.Diagnostics.Debug.WriteLine($"{level.Name}|{message}");
logger.Log(level, unprefixed);
}
else
{
Expand All @@ -78,88 +123,37 @@ public static void Exception(string message, System.Exception e)
var parts = message.Split('|');
var prefix = parts[1];
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);

System.Diagnostics.Debug.WriteLine($"ERROR|{message}");

logger.Error("-------------------------- Begin exception --------------------------");
logger.Error(unprefixed);

do
{
logger.Error($"Exception full name:\n <{e.GetType().FullName}>");
logger.Error($"Exception message:\n <{e.Message}>");
logger.Error($"Exception stack trace:\n <{e.StackTrace}>");
logger.Error($"Exception source:\n <{e.Source}>");
logger.Error($"Exception target site:\n <{e.TargetSite}>");
logger.Error($"Exception HResult:\n <{e.HResult}>");
e = e.InnerException;
} while (e != null);

logger.Error("-------------------------- End exception --------------------------");
ExceptionInternal(prefix, unprefixed, e);
}
else
{
LogFaultyFormat(message);
}
#endif
}

/// <param name="message">example: "|prefix|unprefixed" </param>
public static void Debug(string message)
public static void Error(string message)
{
if (FormatValid(message))
{
var parts = message.Split('|');
var prefix = parts[1];
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);
LogInternal(message, LogLevel.Error);
}

System.Diagnostics.Debug.WriteLine($"DEBUG|{message}");
logger.Debug(unprefixed);
}
else
{
LogFaultyFormat(message);
}
/// <param name="message">example: "|prefix|unprefixed" </param>
public static void Debug(string message)
{
LogInternal(message, LogLevel.Debug);
}

/// <param name="message">example: "|prefix|unprefixed" </param>
public static void Info(string message)
{
if (FormatValid(message))
{
var parts = message.Split('|');
var prefix = parts[1];
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);

System.Diagnostics.Debug.WriteLine($"INFO|{message}");
logger.Info(unprefixed);
}
else
{
LogFaultyFormat(message);
}
LogInternal(message, LogLevel.Info);
}

/// <param name="message">example: "|prefix|unprefixed" </param>
public static void Warn(string message)
{
if (FormatValid(message))
{
var parts = message.Split('|');
var prefix = parts[1];
var unprefixed = parts[2];
var logger = LogManager.GetLogger(prefix);

System.Diagnostics.Debug.WriteLine($"WARN|{message}");
logger.Warn(unprefixed);
}
else
{
LogFaultyFormat(message);
}
LogInternal(message, LogLevel.Warn);
}
}
}
Loading

0 comments on commit 6cad4bc

Please sign in to comment.