aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/LocalConsole.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/LocalConsole.cs58
1 files changed, 49 insertions, 9 deletions
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs
index 476fc15..39351e1 100644
--- a/OpenSim/Framework/Console/LocalConsole.cs
+++ b/OpenSim/Framework/Console/LocalConsole.cs
@@ -46,6 +46,7 @@ namespace OpenSim.Framework.Console
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); 46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47 private string m_historyPath; 47 private string m_historyPath;
48 private bool m_historyEnable; 48 private bool m_historyEnable;
49 private bool m_historytimestamps;
49 50
50 // private readonly object m_syncRoot = new object(); 51 // private readonly object m_syncRoot = new object();
51 private const string LOGLEVEL_NONE = "(none)"; 52 private const string LOGLEVEL_NONE = "(none)";
@@ -98,15 +99,30 @@ namespace OpenSim.Framework.Console
98 string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", Path.Combine(Util.logsDir(), "OpenSimConsoleHistory.txt")); 99 string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", Path.Combine(Util.logsDir(), "OpenSimConsoleHistory.txt"));
99 int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100); 100 int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100);
100 m_historyPath = Path.GetFullPath(m_historyFile); 101 m_historyPath = Path.GetFullPath(m_historyFile);
101 m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1}", m_historySize, m_historyPath); 102 m_historytimestamps = startupConfig.GetBoolean("ConsoleHistoryTimeStamp", false);
103 m_log.InfoFormat("[LOCAL CONSOLE]: Persistent command line history is Enabled, up to {0} lines from file {1} {2} timestamps",
104 m_historySize, m_historyPath, m_historytimestamps?"with":"without");
102 105
103 if (File.Exists(m_historyPath)) 106 if (File.Exists(m_historyPath))
104 { 107 {
108 List<string> originallines = new List<string>();
105 using (StreamReader history_file = new StreamReader(m_historyPath)) 109 using (StreamReader history_file = new StreamReader(m_historyPath))
106 { 110 {
107 string line; 111 string line;
108 while ((line = history_file.ReadLine()) != null) 112 while ((line = history_file.ReadLine()) != null)
109 { 113 {
114 originallines.Add(line);
115 if(line.StartsWith("["))
116 {
117 int indx = line.IndexOf("]:> ");
118 if(indx > 0)
119 {
120 if(indx + 4 >= line.Length)
121 line = String.Empty;
122 else
123 line = line.Substring(indx + 4);
124 }
125 }
110 m_history.Add(line); 126 m_history.Add(line);
111 } 127 }
112 } 128 }
@@ -114,11 +130,14 @@ namespace OpenSim.Framework.Console
114 if (m_history.Count > m_historySize) 130 if (m_history.Count > m_historySize)
115 { 131 {
116 while (m_history.Count > m_historySize) 132 while (m_history.Count > m_historySize)
133 {
117 m_history.RemoveAt(0); 134 m_history.RemoveAt(0);
135 originallines.RemoveAt(0);
136 }
118 137
119 using (StreamWriter history_file = new StreamWriter(m_historyPath)) 138 using (StreamWriter history_file = new StreamWriter(m_historyPath))
120 { 139 {
121 foreach (string line in m_history) 140 foreach (string line in originallines)
122 { 141 {
123 history_file.WriteLine(line); 142 history_file.WriteLine(line);
124 } 143 }
@@ -141,6 +160,8 @@ namespace OpenSim.Framework.Console
141 m_history.Add(text); 160 m_history.Add(text);
142 if (m_historyEnable) 161 if (m_historyEnable)
143 { 162 {
163 if (m_historytimestamps)
164 text = String.Format("[{0} {1}]:> {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), text);
144 File.AppendAllText(m_historyPath, text + Environment.NewLine); 165 File.AppendAllText(m_historyPath, text + Environment.NewLine);
145 } 166 }
146 } 167 }
@@ -338,7 +359,7 @@ namespace OpenSim.Framework.Console
338 { 359 {
339 string outText = text; 360 string outText = text;
340 361
341 if (level != LOGLEVEL_NONE) 362 if (level != null)
342 { 363 {
343 MatchCollection matches = m_categoryRegex.Matches(text); 364 MatchCollection matches = m_categoryRegex.Matches(text);
344 365
@@ -368,13 +389,33 @@ namespace OpenSim.Framework.Console
368 System.Console.WriteLine(); 389 System.Console.WriteLine();
369 } 390 }
370 391
371 public override void Output(string text) 392 public override void Output(string format, params object[] components)
372 { 393 {
373 Output(text, LOGLEVEL_NONE); 394 string level = null;
374 } 395 if(components != null && components.Length > 0)
396 {
397 if(components[0] == null || components[0] is ConsoleLevel)
398 {
399 if(components[0] is ConsoleLevel)
400 level = ((ConsoleLevel)components[0]).ToString();
401
402 if (components.Length > 1)
403 {
404 object[] tmp = new object[components.Length - 1];
405 Array.Copy(components, 1, tmp, 0, components.Length - 1);
406 components = tmp;
407 }
408 else
409 components = null;
410 }
411
412 }
413 string text;
414 if (components == null || components.Length == 0)
415 text = format;
416 else
417 text = String.Format(format, components);
375 418
376 public override void Output(string text, string level)
377 {
378 FireOnOutput(text); 419 FireOnOutput(text);
379 420
380 lock (m_commandLine) 421 lock (m_commandLine)
@@ -382,7 +423,6 @@ namespace OpenSim.Framework.Console
382 if (m_cursorYPosition == -1) 423 if (m_cursorYPosition == -1)
383 { 424 {
384 WriteLocalText(text, level); 425 WriteLocalText(text, level);
385
386 return; 426 return;
387 } 427 }
388 428