mantis 8333: kept idea but my own code. With ini setting ConsoleHistoryTimeStamp set to true, the console history file will have timestamps. Im lazy date is in en-us culture for now. (robust also)

0.9.1.0-post-fixes
UbitUmarov 2018-07-14 00:46:47 +01:00
parent a235a28132
commit 8ed4bee521
2 changed files with 24 additions and 3 deletions

View File

@ -850,7 +850,7 @@ namespace OpenSim.Groups
return false;
}
if (!add && data == null) // it dosn't exist, can't update
if (!add && data == null) // it doesn't exist, can't update
{
m_log.DebugFormat("[Groups]: Group {0} doesn't exist. Can't update it", groupID);
return false;

View File

@ -46,6 +46,7 @@ namespace OpenSim.Framework.Console
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private string m_historyPath;
private bool m_historyEnable;
private bool m_historytimestamps;
// private readonly object m_syncRoot = new object();
private const string LOGLEVEL_NONE = "(none)";
@ -98,15 +99,30 @@ namespace OpenSim.Framework.Console
string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", "OpenSimConsoleHistory.txt");
int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100);
m_historyPath = Path.GetFullPath(Path.Combine(Util.configDir(), m_historyFile));
m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1}", m_historySize, m_historyPath);
m_historytimestamps = startupConfig.GetBoolean("ConsoleHistoryTimeStamp", false);
m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1} {2} timestamps",
m_historySize, m_historyPath, m_historytimestamps?"with":"without");
if (File.Exists(m_historyPath))
{
List<string> originallines = new List<string>();
using (StreamReader history_file = new StreamReader(m_historyPath))
{
string line;
while ((line = history_file.ReadLine()) != null)
{
originallines.Add(line);
if(line.StartsWith("["))
{
int indx = line.IndexOf("]:> ");
if(indx > 0)
{
if(indx + 4 >= line.Length)
line = String.Empty;
else
line = line.Substring(indx + 4);
}
}
m_history.Add(line);
}
}
@ -114,11 +130,14 @@ namespace OpenSim.Framework.Console
if (m_history.Count > m_historySize)
{
while (m_history.Count > m_historySize)
{
m_history.RemoveAt(0);
originallines.RemoveAt(0);
}
using (StreamWriter history_file = new StreamWriter(m_historyPath))
{
foreach (string line in m_history)
foreach (string line in originallines)
{
history_file.WriteLine(line);
}
@ -141,6 +160,8 @@ namespace OpenSim.Framework.Console
m_history.Add(text);
if (m_historyEnable)
{
if (m_historytimestamps)
text = String.Format("[{0} {1}]:> {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), text);
File.AppendAllText(m_historyPath, text + Environment.NewLine);
}
}