diff --git a/Logging/Logger.cs b/Logging/Logger.cs index 73e8e58..7f61613 100644 --- a/Logging/Logger.cs +++ b/Logging/Logger.cs @@ -4,31 +4,39 @@ { private LogType logType; private string logfilepath; - public Logger(LogType type) + private loglevel level; + public Logger(LogType type, loglevel level) { this.logType = type; this.logfilepath = ""; + this.level = level; } - public Logger(LogType type, string path) + public Logger(LogType type, loglevel level, string path) { this.logType = type; this.logfilepath = path; + this.level = level; } - public void log(string message, params object[] ?replace) + public void log(loglevel type, string message, params object[] ?replace) { - switch (this.logType) + if(type >= this.level) { - case LogType.Console: - Console.WriteLine(string.Format(message, replace)); - break; - case LogType.Logfile: - File.WriteAllText(this.logfilepath, string.Format(message, replace)); - break; + string header = string.Format("{0} {1} {2}:", DateTime.Now.ToLocalTime().ToShortDateString(), DateTime.Now.ToLocalTime().ToLongTimeString(), type.ToString()); + switch (this.logType) + { + case LogType.Console: + Console.WriteLine(string.Format(header + message, replace)); + break; + case LogType.Logfile: + File.WriteAllText(this.logfilepath, string.Format(header + message, replace)); + break; + } } } } public enum LogType { Console, Logfile } + public enum loglevel : ushort { DEBUG = 0, INFO = 1, ERROR = 2 }; } diff --git a/astar/Astar.cs b/astar/Astar.cs index 36c9ae4..5222650 100644 --- a/astar/Astar.cs +++ b/astar/Astar.cs @@ -8,7 +8,7 @@ namespace astar private Logger logger; public Astar() { - this.logger = new Logger(LogType.Console); + this.logger = new Logger(LogType.Console, loglevel.DEBUG); Importer.Import(logger); } } diff --git a/astar/Importer.cs b/astar/Importer.cs index e1a97fa..dfda644 100644 --- a/astar/Importer.cs +++ b/astar/Importer.cs @@ -34,7 +34,7 @@ namespace astar if(currentNodeType == nodeType.WAY) { ImportWay(currentWay); - logger.log("Way nodes: {0}", currentWay.nodes.Count); + logger.log(loglevel.INFO, "Way nodes: {0}", currentWay.nodes.Count); } currentNodeType = nodeType.WAY; currentNode = nullNode; @@ -44,7 +44,7 @@ namespace astar UInt64 id = Convert.ToUInt64(reader.GetAttribute("ref")); if (!nodes.TryGetValue(id, out currentNode)) { - logger.log("ERR: Node with id {0} not imported.", id); + logger.log(loglevel.DEBUG, "Node with id {0} not imported.", id); } else { @@ -83,7 +83,7 @@ namespace astar } } - logger.log("Loaded. Nodes: {0}", nodes.Count); + logger.log(loglevel.INFO, "Loaded. Nodes: {0}", nodes.Count); } internal static void ImportWay(Way way)