diff options
author | UbitUmarov | 2018-07-14 00:46:47 +0100 |
---|---|---|
committer | UbitUmarov | 2018-07-14 00:46:47 +0100 |
commit | 8ed4bee521d9736abd753ed1e72c7e0461e49846 (patch) | |
tree | 09b475a99a255e49ee3c63703033ee8b281201d3 /OpenSim/Framework/Console/LocalConsole.cs | |
parent | minor changes to last patch (diff) | |
download | opensim-SC-8ed4bee521d9736abd753ed1e72c7e0461e49846.zip opensim-SC-8ed4bee521d9736abd753ed1e72c7e0461e49846.tar.gz opensim-SC-8ed4bee521d9736abd753ed1e72c7e0461e49846.tar.bz2 opensim-SC-8ed4bee521d9736abd753ed1e72c7e0461e49846.tar.xz |
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)
Diffstat (limited to 'OpenSim/Framework/Console/LocalConsole.cs')
-rw-r--r-- | OpenSim/Framework/Console/LocalConsole.cs | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/OpenSim/Framework/Console/LocalConsole.cs b/OpenSim/Framework/Console/LocalConsole.cs index 73f0323..ba32f50 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", "OpenSimConsoleHistory.txt"); | 99 | string m_historyFile = startupConfig.GetString("ConsoleHistoryFile", "OpenSimConsoleHistory.txt"); |
99 | int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100); | 100 | int m_historySize = startupConfig.GetInt("ConsoleHistoryFileLines", 100); |
100 | m_historyPath = Path.GetFullPath(Path.Combine(Util.configDir(), m_historyFile)); | 101 | m_historyPath = Path.GetFullPath(Path.Combine(Util.configDir(), 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 | } |