mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-02 19:42:05 -04:00
cleaned up logging, added log_level param to enable/disable types of logging
This commit is contained in:
parent
c23f9c7ca9
commit
c5516511b0
@ -2,7 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Linq;
|
||||
|
||||
namespace FFXIVClassic.Common
|
||||
{
|
||||
@ -11,16 +11,17 @@ namespace FFXIVClassic.Common
|
||||
public string LogDirectory;
|
||||
public string LogFileName;
|
||||
public int EnabledLogTypes;
|
||||
public Queue<Tuple<String, LogColour>> LogQueue;
|
||||
public Queue<Tuple<String, LogType>> LogQueue;
|
||||
|
||||
public Log(string path, string file, int enabledtypes)
|
||||
{
|
||||
LogQueue = new Queue<Tuple<String, LogColour>>();
|
||||
LogQueue = new Queue<Tuple<String, LogType>>();
|
||||
EnabledLogTypes = enabledtypes;
|
||||
LogDirectory = path;
|
||||
LogFileName = file;
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum LogType
|
||||
{
|
||||
None = 0x000,
|
||||
@ -33,6 +34,7 @@ namespace FFXIVClassic.Common
|
||||
Error = 0x040,
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum LogColour
|
||||
{
|
||||
Status = ConsoleColor.Green,
|
||||
@ -44,42 +46,42 @@ namespace FFXIVClassic.Common
|
||||
|
||||
public void Status(String message, params object[] formatargs)
|
||||
{
|
||||
if (formatargs.Length > 0)
|
||||
if (formatargs.Any())
|
||||
message = String.Format(message, formatargs);
|
||||
|
||||
QueueMessage(message, LogColour.Status);
|
||||
QueueMessage(message, LogType.Status);
|
||||
}
|
||||
|
||||
public void Sql(String message, params object[] formatargs)
|
||||
{
|
||||
if (formatargs.Length > 0)
|
||||
if (formatargs.Any())
|
||||
message = String.Format(message, formatargs);
|
||||
|
||||
QueueMessage(message, LogColour.Sql);
|
||||
QueueMessage(message, LogType.Sql);
|
||||
}
|
||||
|
||||
public void Info(String message, params object[] formatargs)
|
||||
{
|
||||
if (formatargs.Length > 0)
|
||||
if (formatargs.Any())
|
||||
message = String.Format(message, formatargs);
|
||||
|
||||
QueueMessage(message, LogColour.Info);
|
||||
QueueMessage(message, LogType.Info);
|
||||
}
|
||||
|
||||
public void Debug(String message, params object[] formatargs)
|
||||
{
|
||||
if (formatargs.Length > 0)
|
||||
if (formatargs.Any())
|
||||
message = String.Format(message, formatargs);
|
||||
|
||||
QueueMessage(message, LogColour.Debug);
|
||||
QueueMessage(message, LogType.Debug);
|
||||
}
|
||||
|
||||
public void Error(String message, params object[] formatargs)
|
||||
{
|
||||
if (formatargs.Length > 0)
|
||||
if (formatargs.Any())
|
||||
message = String.Format(message, formatargs);
|
||||
|
||||
QueueMessage(message, LogColour.Error);
|
||||
QueueMessage(message, LogType.Error);
|
||||
}
|
||||
|
||||
public void Packet(String message, params object[] formatargs)
|
||||
@ -87,20 +89,17 @@ namespace FFXIVClassic.Common
|
||||
|
||||
}
|
||||
|
||||
private void QueueMessage(String message, LogColour type)
|
||||
private void QueueMessage(String message, LogType colour)
|
||||
{
|
||||
LogQueue.Enqueue(Tuple.Create(message, type));
|
||||
LogQueue.Enqueue(Tuple.Create(message, colour));
|
||||
}
|
||||
|
||||
public void WriteMessage(String message, LogColour type)
|
||||
{
|
||||
var canLog = false;
|
||||
|
||||
try
|
||||
{
|
||||
canLog = ((EnabledLogTypes & (int)(Enum.Parse(typeof(LogType), type.ToString()))) != 0);
|
||||
}
|
||||
catch (Exception e) { }
|
||||
public void WriteMessage(String message, LogType type)
|
||||
{
|
||||
if (((LogType)EnabledLogTypes & (LogType)type) == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string timestamp = String.Format("[{0}]", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
|
||||
string messageType = String.Format("[{0}] ", type.ToString().ToUpper());
|
||||
@ -108,7 +107,7 @@ namespace FFXIVClassic.Common
|
||||
if ((EnabledLogTypes & (int)LogType.Console) != 0)
|
||||
{
|
||||
Console.Write(timestamp);
|
||||
Console.ForegroundColor = (ConsoleColor)type;
|
||||
Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(LogColour),type.ToString());
|
||||
Console.Write(messageType);
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
Console.WriteLine(message);
|
||||
|
@ -71,8 +71,6 @@ namespace FFXIVClassic_Lobby_Server
|
||||
{
|
||||
Server server = new Server();
|
||||
server.startServer();
|
||||
|
||||
while (true) Thread.Sleep(10000);
|
||||
}
|
||||
|
||||
Program.Log.Info("Press any key to continue...");
|
||||
|
@ -1,11 +1,28 @@
|
||||
[General]
|
||||
server_ip=127.0.0.1
|
||||
showtimestamp = true
|
||||
|
||||
# log_level: add up values for types you want to enable
|
||||
# then convert hex -> dec and set log_level = value
|
||||
# 0x000 None,
|
||||
# 0x001 Console,
|
||||
# 0x002 File,
|
||||
# 0x004 Status,
|
||||
# 0x008 Sql,
|
||||
# 0x010 Info,
|
||||
# 0x020 Debug,
|
||||
# 0x040 Error,
|
||||
|
||||
log_level = 127
|
||||
|
||||
#log_path = ./logs/
|
||||
#log_file = lobby.log
|
||||
|
||||
|
||||
[Database]
|
||||
worldid=1
|
||||
host=127.0.0.1
|
||||
port=3306
|
||||
database=ffxiv_server
|
||||
username=root
|
||||
password=root
|
||||
password=root
|
||||
|
@ -1,11 +1,28 @@
|
||||
[General]
|
||||
server_ip=127.0.0.1
|
||||
showtimestamp = true
|
||||
|
||||
# log_level: add up values for types you want to enable
|
||||
# then convert hex -> dec and set log_level = value
|
||||
# 0x000 None,
|
||||
# 0x001 Console,
|
||||
# 0x002 File,
|
||||
# 0x004 Status,
|
||||
# 0x008 Sql,
|
||||
# 0x010 Info,
|
||||
# 0x020 Debug,
|
||||
# 0x040 Error,
|
||||
|
||||
log_level = 127
|
||||
|
||||
#log_path = ./logs/
|
||||
#log_file = map.log
|
||||
|
||||
|
||||
[Database]
|
||||
worldid=1
|
||||
host=127.0.0.1
|
||||
port=3306
|
||||
database=ffxiv_server
|
||||
username=root
|
||||
password=root
|
||||
password=root
|
||||
|
Loading…
Reference in New Issue
Block a user