From c5516511b0e52c9513215e6a5897370a7e617212 Mon Sep 17 00:00:00 2001 From: Tahir Akhlaq Date: Tue, 14 Jun 2016 03:00:57 +0100 Subject: [PATCH] cleaned up logging, added log_level param to enable/disable types of logging --- FFXIVClassic Common Class Lib/Log.cs | 49 ++++++++++++++-------------- FFXIVClassic Lobby Server/Program.cs | 2 -- data/lobby_config.ini | 19 ++++++++++- data/map_config.ini | 19 ++++++++++- 4 files changed, 60 insertions(+), 29 deletions(-) diff --git a/FFXIVClassic Common Class Lib/Log.cs b/FFXIVClassic Common Class Lib/Log.cs index 54ce9084..6c2f88e3 100644 --- a/FFXIVClassic Common Class Lib/Log.cs +++ b/FFXIVClassic Common Class Lib/Log.cs @@ -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> LogQueue; + public Queue> LogQueue; public Log(string path, string file, int enabledtypes) { - LogQueue = new Queue>(); + LogQueue = new Queue>(); 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); diff --git a/FFXIVClassic Lobby Server/Program.cs b/FFXIVClassic Lobby Server/Program.cs index 37019433..9303f30f 100644 --- a/FFXIVClassic Lobby Server/Program.cs +++ b/FFXIVClassic Lobby Server/Program.cs @@ -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..."); diff --git a/data/lobby_config.ini b/data/lobby_config.ini index fb02ff5b..50a3f8bd 100644 --- a/data/lobby_config.ini +++ b/data/lobby_config.ini @@ -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 \ No newline at end of file +password=root diff --git a/data/map_config.ini b/data/map_config.ini index fb02ff5b..b5b8c243 100644 --- a/data/map_config.ini +++ b/data/map_config.ini @@ -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 \ No newline at end of file +password=root