2015-09-25 18:52:25 -04:00
|
|
|
|
using System;
|
2016-06-08 22:29:04 +01:00
|
|
|
|
using System.IO;
|
2015-09-25 18:52:25 -04:00
|
|
|
|
|
2016-06-08 22:29:04 +01:00
|
|
|
|
namespace FFXIVClassic_Map_Server.common
|
2015-09-25 18:52:25 -04:00
|
|
|
|
{
|
|
|
|
|
class Log
|
|
|
|
|
{
|
2016-06-08 22:29:04 +01:00
|
|
|
|
public enum LogType
|
|
|
|
|
{
|
|
|
|
|
Error = ConsoleColor.Red,
|
|
|
|
|
Debug = ConsoleColor.Yellow,
|
|
|
|
|
Info = ConsoleColor.Cyan,
|
|
|
|
|
Sql = ConsoleColor.Magenta,
|
|
|
|
|
Conn = ConsoleColor.Green,
|
|
|
|
|
Default = ConsoleColor.Gray
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-25 18:52:25 -04:00
|
|
|
|
public static void error(String message)
|
|
|
|
|
{
|
2016-06-08 22:29:04 +01:00
|
|
|
|
log(message, LogType.Error);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void debug(String message)
|
2016-06-08 22:29:04 +01:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
log(message, LogType.Debug);
|
|
|
|
|
#endif
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void info(String message)
|
|
|
|
|
{
|
2016-06-08 22:29:04 +01:00
|
|
|
|
log(message, LogType.Info);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void database(String message)
|
|
|
|
|
{
|
2016-06-08 22:29:04 +01:00
|
|
|
|
log(message, LogType.Sql);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void conn(String message)
|
|
|
|
|
{
|
2016-06-08 22:29:04 +01:00
|
|
|
|
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);
|
2015-09-25 18:52:25 -04:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
|
Console.WriteLine(message);
|
2016-06-08 22:29:04 +01:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2015-09-25 18:52:25 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|