Added Logging Levels
This commit is contained in:
parent
958913d3d2
commit
f30cef46c9
@ -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 };
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user