logging refactors

This commit is contained in:
Zoryn Aaron 2016-03-21 21:05:07 -04:00
parent 87f576f164
commit 074d72840d
2 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Globalization;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
@ -28,7 +29,7 @@ namespace StardewModdingAPI
catch (Exception) catch (Exception)
{ {
// TODO: not use general exception // TODO: not use general exception
Log.Error("Could not initialize LogStream - Logging is disabled"); Error("Could not initialize LogStream - Logging is disabled");
} }
} }
@ -36,11 +37,11 @@ namespace StardewModdingAPI
/// Print provided parameters to the console/file as applicable /// Print provided parameters to the console/file as applicable
/// </summary> /// </summary>
/// <param name="message">Desired message</param> /// <param name="message">Desired message</param>
/// <param name="suppressMessage">When true, writes to ONLY console and not the log file.</param> /// <param name="disableLogging">When true, writes to ONLY console and not the log file.</param>
/// <param name="values">Additional params to be added to the message</param> /// <param name="values">Additional params to be added to the message</param>
private static void PrintLog(object message, bool disableLogging, params object[] values) private static void PrintLog(object message, bool disableLogging, params object[] values)
{ {
string logOutput = string.Format("[{0}] {1}", System.DateTime.Now.ToLongTimeString(), String.Format(message.ToString(), values)); string logOutput = $"[{DateTime.Now.ToLongTimeString()}] {string.Format(message.ToString(), values)}";
Console.WriteLine(logOutput); Console.WriteLine(logOutput);
if (_logStream != null && !disableLogging) if (_logStream != null && !disableLogging)
@ -58,7 +59,7 @@ namespace StardewModdingAPI
public static void Success(object message, params object[] values) public static void Success(object message, params object[] values)
{ {
Console.ForegroundColor = ConsoleColor.Green; Console.ForegroundColor = ConsoleColor.Green;
Log.PrintLog(message?.ToString(), false, values); PrintLog(message?.ToString(), false, values);
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }
@ -69,7 +70,9 @@ namespace StardewModdingAPI
/// <param name="values"></param> /// <param name="values"></param>
public static void Verbose(object message, params object[] values) public static void Verbose(object message, params object[] values)
{ {
Log.PrintLog(message?.ToString(), false, values); Console.ForegroundColor = ConsoleColor.Gray;
PrintLog(message?.ToString(), false, values);
Console.ForegroundColor = ConsoleColor.Gray;
} }
/// <summary> /// <summary>
@ -80,7 +83,7 @@ namespace StardewModdingAPI
public static void Comment(object message, params object[] values) public static void Comment(object message, params object[] values)
{ {
Console.ForegroundColor = ConsoleColor.Yellow; Console.ForegroundColor = ConsoleColor.Yellow;
Log.PrintLog(message?.ToString(), false, values); PrintLog(message?.ToString(), false, values);
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }
@ -91,7 +94,9 @@ namespace StardewModdingAPI
/// <param name="values"></param> /// <param name="values"></param>
public static void Info(object message, params object[] values) public static void Info(object message, params object[] values)
{ {
Log.PrintLog(message.ToString(), true, values); Console.ForegroundColor = ConsoleColor.Gray;
PrintLog(message?.ToString(), true, values);
Console.ForegroundColor = ConsoleColor.Gray;
} }
/// <summary> /// <summary>
@ -102,7 +107,7 @@ namespace StardewModdingAPI
public static void Error(object message, params object[] values) public static void Error(object message, params object[] values)
{ {
Console.ForegroundColor = ConsoleColor.Red; Console.ForegroundColor = ConsoleColor.Red;
Log.PrintLog(message.ToString(), false, values); PrintLog(message?.ToString(), false, values);
Console.ForegroundColor = ConsoleColor.Gray; Console.ForegroundColor = ConsoleColor.Gray;
} }
@ -127,7 +132,7 @@ namespace StardewModdingAPI
public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) public static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{ {
Console.WriteLine("An exception has been caught"); Console.WriteLine("An exception has been caught");
File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + Extensions.Random.Next(100000000, 999999999) + ".txt", e.ExceptionObject.ToString()); File.WriteAllText(_logPath + "\\MODDED_ErrorLog.Log_" + DateTime.UtcNow.Ticks + ".txt", e.ExceptionObject.ToString());
} }
/// <summary> /// <summary>

View File

@ -8,6 +8,7 @@ using StardewValley.Menus;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -46,6 +47,8 @@ namespace StardewModdingAPI
/// <param name="args"></param> /// <param name="args"></param>
private static void Main(string[] args) private static void Main(string[] args)
{ {
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-GB");
try try
{ {
ConfigureUI(); ConfigureUI();