servers now log (almost) everything to file

- regex'd in mysqlexception logging
- servers can now specify server_port, log_path, log_file
- added scripts to import/export all tables (exporting will export a handful of garbage table names, open and check for structure before deleting)
- fixed packet logging (thanks deviltti)
This commit is contained in:
Tahir Akhlaq 2016-06-08 22:29:04 +01:00
parent 92339ba0c4
commit 8b93abe86e
238 changed files with 684 additions and 1532 deletions

View file

@ -1,58 +1,73 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace FFXIVClassic_Lobby_Server.common
namespace FFXIVClassic_Map_Server.common
{
class Log
{
public enum LogType
{
Error = ConsoleColor.Red,
Debug = ConsoleColor.Yellow,
Info = ConsoleColor.Cyan,
Sql = ConsoleColor.Magenta,
Conn = ConsoleColor.Green,
Default = ConsoleColor.Gray
}
public static void error(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("[ERROR] ");
Console.ForegroundColor = ConsoleColor.Gray ;
Console.WriteLine(message);
log(message, LogType.Error);
}
public static void debug(String message)
{
#if DEBUG
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("[DEBUG] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
#endif
{
#if DEBUG
log(message, LogType.Debug);
#endif
}
public static void info(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Cyan;
Console.Write("[INFO] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
log(message, LogType.Info);
}
public static void database(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Magenta;
Console.Write("[SQL] ");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
log(message, LogType.Sql);
}
public static void conn(String message)
{
Console.Write("[{0}]", DateTime.Now.ToString("dd/MMM HH:mm"));
Console.ForegroundColor = ConsoleColor.Green;
Console.Write("[CONN] ");
log(message, LogType.Conn);
}
private static void log(String message, LogType type)
{
var timestamp = String.Format("[{0}] ", DateTime.Now.ToString("dd/MMM HH:mm:ss"));
var typestr = String.Format("[{0}] ", type.ToString().ToUpper());
Console.Write(timestamp);
Console.ForegroundColor = (ConsoleColor)type;
Console.Write(typestr);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
message = message.Insert(0, typestr);
message = message.Insert(0, timestamp);
Directory.CreateDirectory(ConfigConstants.OPTIONS_LOGPATH);
try
{
File.AppendAllText(ConfigConstants.OPTIONS_LOGPATH + ConfigConstants.OPTIONS_LOGFILE, message + Environment.NewLine);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(e.Message);
Console.ForegroundColor = ConsoleColor.Gray;
}
}
}
}