2012-03-19 23:57:59 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2015-01-03 02:14:38 +00:00
|
|
|
|
using Axios.Engine.Data;
|
|
|
|
|
using Axios.Engine.File;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Axios.Engine.Log
|
|
|
|
|
{
|
|
|
|
|
[Flags]
|
|
|
|
|
public enum LoggingFlag
|
|
|
|
|
{
|
|
|
|
|
NONE = 0,
|
|
|
|
|
DEBUG = 1,
|
|
|
|
|
INFO = 2,
|
|
|
|
|
WARN = 4,
|
|
|
|
|
ERROR = 8,
|
|
|
|
|
FATAL = 16,
|
2015-01-03 02:14:38 +00:00
|
|
|
|
ALL = ~0
|
2012-03-19 23:57:59 +00:00
|
|
|
|
}
|
|
|
|
|
public class AxiosLog : Singleton<AxiosLog>
|
|
|
|
|
{
|
|
|
|
|
private List<string> _log;
|
2015-01-03 02:14:38 +00:00
|
|
|
|
// Logs everything regardless of log level
|
|
|
|
|
// Used for debugging purposes
|
|
|
|
|
private List<string> _extendedlog;
|
2012-03-19 23:57:59 +00:00
|
|
|
|
|
|
|
|
|
public AxiosLog()
|
|
|
|
|
{
|
|
|
|
|
_log = new List<string>();
|
2015-01-03 02:14:38 +00:00
|
|
|
|
_extendedlog = new List<string>();
|
2012-03-19 23:57:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void AddLine(string line, LoggingFlag flag)
|
|
|
|
|
{
|
2015-01-03 02:14:38 +00:00
|
|
|
|
|
|
|
|
|
if (Settings.Loglevel.HasFlag(flag))
|
|
|
|
|
{
|
|
|
|
|
AxiosCommandConsole c = (AxiosCommandConsole)Cache.Instance.get("commandconsole");
|
|
|
|
|
if (c != null)
|
|
|
|
|
c.AddToLog(line);
|
2012-03-19 23:57:59 +00:00
|
|
|
|
_log.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line);
|
2015-01-03 02:14:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_extendedlog.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line);
|
2012-03-19 23:57:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<string> GetLogList()
|
|
|
|
|
{
|
|
|
|
|
return _log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetLog(string seperator)
|
|
|
|
|
{
|
|
|
|
|
return String.Join(seperator, _log.ToArray()) + seperator;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetLog()
|
|
|
|
|
{
|
|
|
|
|
return GetLog("\r\n");
|
|
|
|
|
}
|
2015-01-03 02:14:38 +00:00
|
|
|
|
|
|
|
|
|
public void writeLog()
|
|
|
|
|
{
|
|
|
|
|
using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log"))
|
|
|
|
|
{
|
|
|
|
|
file.WriteData(GetLog(), System.IO.FileMode.Create);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void writeExtendedLog()
|
|
|
|
|
{
|
|
|
|
|
using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log"))
|
|
|
|
|
{
|
|
|
|
|
file.WriteData(String.Join("\r\n", _extendedlog.ToArray()), System.IO.FileMode.Create);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-19 23:57:59 +00:00
|
|
|
|
}
|
|
|
|
|
}
|