mirror of
https://bitbucket.org/Ioncannon/project-meteor-server.git
synced 2025-04-22 12:47:46 +00:00
cleaned up logging, added log_level param to enable/disable types of logging
This commit is contained in:
parent
c23f9c7ca9
commit
c5516511b0
4 changed files with 60 additions and 29 deletions
|
@ -2,7 +2,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Linq;
|
||||||
|
|
||||||
namespace FFXIVClassic.Common
|
namespace FFXIVClassic.Common
|
||||||
{
|
{
|
||||||
|
@ -11,16 +11,17 @@ namespace FFXIVClassic.Common
|
||||||
public string LogDirectory;
|
public string LogDirectory;
|
||||||
public string LogFileName;
|
public string LogFileName;
|
||||||
public int EnabledLogTypes;
|
public int EnabledLogTypes;
|
||||||
public Queue<Tuple<String, LogColour>> LogQueue;
|
public Queue<Tuple<String, LogType>> LogQueue;
|
||||||
|
|
||||||
public Log(string path, string file, int enabledtypes)
|
public Log(string path, string file, int enabledtypes)
|
||||||
{
|
{
|
||||||
LogQueue = new Queue<Tuple<String, LogColour>>();
|
LogQueue = new Queue<Tuple<String, LogType>>();
|
||||||
EnabledLogTypes = enabledtypes;
|
EnabledLogTypes = enabledtypes;
|
||||||
LogDirectory = path;
|
LogDirectory = path;
|
||||||
LogFileName = file;
|
LogFileName = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum LogType
|
public enum LogType
|
||||||
{
|
{
|
||||||
None = 0x000,
|
None = 0x000,
|
||||||
|
@ -33,6 +34,7 @@ namespace FFXIVClassic.Common
|
||||||
Error = 0x040,
|
Error = 0x040,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
public enum LogColour
|
public enum LogColour
|
||||||
{
|
{
|
||||||
Status = ConsoleColor.Green,
|
Status = ConsoleColor.Green,
|
||||||
|
@ -44,42 +46,42 @@ namespace FFXIVClassic.Common
|
||||||
|
|
||||||
public void Status(String message, params object[] formatargs)
|
public void Status(String message, params object[] formatargs)
|
||||||
{
|
{
|
||||||
if (formatargs.Length > 0)
|
if (formatargs.Any())
|
||||||
message = String.Format(message, formatargs);
|
message = String.Format(message, formatargs);
|
||||||
|
|
||||||
QueueMessage(message, LogColour.Status);
|
QueueMessage(message, LogType.Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Sql(String message, params object[] formatargs)
|
public void Sql(String message, params object[] formatargs)
|
||||||
{
|
{
|
||||||
if (formatargs.Length > 0)
|
if (formatargs.Any())
|
||||||
message = String.Format(message, formatargs);
|
message = String.Format(message, formatargs);
|
||||||
|
|
||||||
QueueMessage(message, LogColour.Sql);
|
QueueMessage(message, LogType.Sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Info(String message, params object[] formatargs)
|
public void Info(String message, params object[] formatargs)
|
||||||
{
|
{
|
||||||
if (formatargs.Length > 0)
|
if (formatargs.Any())
|
||||||
message = String.Format(message, formatargs);
|
message = String.Format(message, formatargs);
|
||||||
|
|
||||||
QueueMessage(message, LogColour.Info);
|
QueueMessage(message, LogType.Info);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Debug(String message, params object[] formatargs)
|
public void Debug(String message, params object[] formatargs)
|
||||||
{
|
{
|
||||||
if (formatargs.Length > 0)
|
if (formatargs.Any())
|
||||||
message = String.Format(message, formatargs);
|
message = String.Format(message, formatargs);
|
||||||
|
|
||||||
QueueMessage(message, LogColour.Debug);
|
QueueMessage(message, LogType.Debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Error(String message, params object[] formatargs)
|
public void Error(String message, params object[] formatargs)
|
||||||
{
|
{
|
||||||
if (formatargs.Length > 0)
|
if (formatargs.Any())
|
||||||
message = String.Format(message, formatargs);
|
message = String.Format(message, formatargs);
|
||||||
|
|
||||||
QueueMessage(message, LogColour.Error);
|
QueueMessage(message, LogType.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Packet(String message, params object[] formatargs)
|
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)
|
public void WriteMessage(String message, LogType type)
|
||||||
{
|
{
|
||||||
var canLog = false;
|
if (((LogType)EnabledLogTypes & (LogType)type) == 0)
|
||||||
|
{
|
||||||
try
|
return;
|
||||||
{
|
}
|
||||||
canLog = ((EnabledLogTypes & (int)(Enum.Parse(typeof(LogType), type.ToString()))) != 0);
|
|
||||||
}
|
|
||||||
catch (Exception e) { }
|
|
||||||
|
|
||||||
string timestamp = String.Format("[{0}]", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
|
string timestamp = String.Format("[{0}]", DateTime.Now.ToString("MM/dd/yyyy HH:mm:ss"));
|
||||||
string messageType = String.Format("[{0}] ", type.ToString().ToUpper());
|
string messageType = String.Format("[{0}] ", type.ToString().ToUpper());
|
||||||
|
@ -108,7 +107,7 @@ namespace FFXIVClassic.Common
|
||||||
if ((EnabledLogTypes & (int)LogType.Console) != 0)
|
if ((EnabledLogTypes & (int)LogType.Console) != 0)
|
||||||
{
|
{
|
||||||
Console.Write(timestamp);
|
Console.Write(timestamp);
|
||||||
Console.ForegroundColor = (ConsoleColor)type;
|
Console.ForegroundColor = (ConsoleColor)Enum.Parse(typeof(LogColour),type.ToString());
|
||||||
Console.Write(messageType);
|
Console.Write(messageType);
|
||||||
Console.ForegroundColor = ConsoleColor.Gray;
|
Console.ForegroundColor = ConsoleColor.Gray;
|
||||||
Console.WriteLine(message);
|
Console.WriteLine(message);
|
||||||
|
|
|
@ -71,8 +71,6 @@ namespace FFXIVClassic_Lobby_Server
|
||||||
{
|
{
|
||||||
Server server = new Server();
|
Server server = new Server();
|
||||||
server.startServer();
|
server.startServer();
|
||||||
|
|
||||||
while (true) Thread.Sleep(10000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Program.Log.Info("Press any key to continue...");
|
Program.Log.Info("Press any key to continue...");
|
||||||
|
|
|
@ -1,11 +1,28 @@
|
||||||
[General]
|
[General]
|
||||||
server_ip=127.0.0.1
|
server_ip=127.0.0.1
|
||||||
showtimestamp = true
|
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_level = 127
|
||||||
|
|
||||||
|
#log_path = ./logs/
|
||||||
|
#log_file = lobby.log
|
||||||
|
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
worldid=1
|
worldid=1
|
||||||
host=127.0.0.1
|
host=127.0.0.1
|
||||||
port=3306
|
port=3306
|
||||||
database=ffxiv_server
|
database=ffxiv_server
|
||||||
username=root
|
username=root
|
||||||
password=root
|
password=root
|
||||||
|
|
|
@ -1,11 +1,28 @@
|
||||||
[General]
|
[General]
|
||||||
server_ip=127.0.0.1
|
server_ip=127.0.0.1
|
||||||
showtimestamp = true
|
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_level = 127
|
||||||
|
|
||||||
|
#log_path = ./logs/
|
||||||
|
#log_file = map.log
|
||||||
|
|
||||||
|
|
||||||
[Database]
|
[Database]
|
||||||
worldid=1
|
worldid=1
|
||||||
host=127.0.0.1
|
host=127.0.0.1
|
||||||
port=3306
|
port=3306
|
||||||
database=ffxiv_server
|
database=ffxiv_server
|
||||||
username=root
|
username=root
|
||||||
password=root
|
password=root
|
||||||
|
|
Loading…
Add table
Reference in a new issue