aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/ConsoleBase.cs
diff options
context:
space:
mode:
authorJeff Ames2008-02-05 19:44:27 +0000
committerJeff Ames2008-02-05 19:44:27 +0000
commit6ed5283bc06a62f38eb517e67b975832b603bf61 (patch)
treee5f635018789b73a99ddeca0883a68368fa5eece /OpenSim/Framework/Console/ConsoleBase.cs
parentCut down on the number of packets sent during terraforming. Terraforming shou... (diff)
downloadopensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.zip
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.gz
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.bz2
opensim-SC_OLD-6ed5283bc06a62f38eb517e67b975832b603bf61.tar.xz
Converted logging to use log4net.
Changed LogBase to ConsoleBase, which handles console I/O. This is mostly an in-place conversion, so lots of refactoring can still be done.
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Console/ConsoleBase.cs (renamed from OpenSim/Framework/Console/LogBase.cs)154
1 files changed, 38 insertions, 116 deletions
diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/ConsoleBase.cs
index a2c4b3a..3f68e50 100644
--- a/OpenSim/Framework/Console/LogBase.cs
+++ b/OpenSim/Framework/Console/ConsoleBase.cs
@@ -33,61 +33,28 @@ using System.Net;
33 33
34namespace OpenSim.Framework.Console 34namespace OpenSim.Framework.Console
35{ 35{
36 public enum LogPriority : int 36 public class ConsoleBase
37 { 37 {
38 CRITICAL, 38 private static readonly log4net.ILog m_log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
39 HIGH,
40 MEDIUM,
41 NORMAL,
42 LOW,
43 VERBOSE,
44 EXTRAVERBOSE
45 }
46 39
47 public class LogBase
48 {
49 private object m_syncRoot = new object(); 40 private object m_syncRoot = new object();
50 41
51 private StreamWriter Log; 42 public conscmd_callback m_cmdParser;
52 public conscmd_callback cmdparser; 43 public string m_componentName;
53 public string componentname;
54 private bool m_verbose;
55 44
56 public LogBase(string LogFile, string componentname, conscmd_callback cmdparser, bool verbose) 45 public ConsoleBase(string componentname, conscmd_callback cmdparser)
57 { 46 {
58 this.componentname = componentname; 47 m_componentName = componentname;
59 this.cmdparser = cmdparser; 48 m_cmdParser = cmdparser;
60 m_verbose = verbose;
61 System.Console.WriteLine("Creating new local console");
62
63 if (String.IsNullOrEmpty(LogFile))
64 {
65 LogFile = componentname + ".log";
66 }
67 49
68 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile); 50 System.Console.WriteLine("Creating new local console");
69 51
70 try 52 m_log.Info("[" + m_componentName + "]: Started at " + DateTime.Now.ToString());
71 {
72 Log = File.AppendText(LogFile);
73 }
74 catch (Exception ex)
75 {
76 System.Console.WriteLine("Unable to open log file. Do you already have another copy of OpenSim running? Permission problem?");
77 System.Console.WriteLine(ex.Message);
78 System.Console.WriteLine("");
79 System.Console.WriteLine("Application is terminating.");
80 System.Console.WriteLine("");
81 System.Threading.Thread.CurrentThread.Abort();
82 }
83 Log.WriteLine("========================================================================");
84 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
85 } 53 }
86 54
87 public void Close() 55 public void Close()
88 { 56 {
89 Log.WriteLine("Shutdown at " + DateTime.Now.ToString()); 57 m_log.Info("[" + m_componentName + "]: Shutdown at " + DateTime.Now.ToString());
90 Log.Close();
91 } 58 }
92 59
93 /// <summary> 60 /// <summary>
@@ -99,23 +66,22 @@ namespace OpenSim.Framework.Console
99 /// <returns>an ansii color</returns> 66 /// <returns>an ansii color</returns>
100 private ConsoleColor DeriveColor(string input) 67 private ConsoleColor DeriveColor(string input)
101 { 68 {
102 int colIdx = (input.ToUpper().GetHashCode()%6) + 9; 69 int colIdx = (input.ToUpper().GetHashCode() % 6) + 9;
103 return (ConsoleColor) colIdx; 70 return (ConsoleColor) colIdx;
104 } 71 }
105 72
106 /// <summary> 73 /// <summary>
107 /// Sends a warning to the current log output 74 /// Sends a warning to the current console output
108 /// </summary> 75 /// </summary>
109 /// <param name="format">The message to send</param> 76 /// <param name="format">The message to send</param>
110 /// <param name="args">WriteLine-style message arguments</param> 77 /// <param name="args">WriteLine-style message arguments</param>
111 public void Warn(string format, params object[] args) 78 public void Warn(string format, params object[] args)
112 { 79 {
113 WriteNewLine(ConsoleColor.Yellow, format, args); 80 WriteNewLine(ConsoleColor.Yellow, format, args);
114 return;
115 } 81 }
116 82
117 /// <summary> 83 /// <summary>
118 /// Sends a warning to the current log output 84 /// Sends a warning to the current console output
119 /// </summary> 85 /// </summary>
120 /// <param name="sender">The module that sent this message</param> 86 /// <param name="sender">The module that sent this message</param>
121 /// <param name="format">The message to send</param> 87 /// <param name="format">The message to send</param>
@@ -124,22 +90,20 @@ namespace OpenSim.Framework.Console
124 { 90 {
125 WritePrefixLine(DeriveColor(sender), sender); 91 WritePrefixLine(DeriveColor(sender), sender);
126 WriteNewLine(ConsoleColor.Yellow, format, args); 92 WriteNewLine(ConsoleColor.Yellow, format, args);
127 return;
128 } 93 }
129 94
130 /// <summary> 95 /// <summary>
131 /// Sends a notice to the current log output 96 /// Sends a notice to the current console output
132 /// </summary> 97 /// </summary>
133 /// <param name="format">The message to send</param> 98 /// <param name="format">The message to send</param>
134 /// <param name="args">WriteLine-style message arguments</param> 99 /// <param name="args">WriteLine-style message arguments</param>
135 public void Notice(string format, params object[] args) 100 public void Notice(string format, params object[] args)
136 { 101 {
137 WriteNewLine(ConsoleColor.White, format, args); 102 WriteNewLine(ConsoleColor.White, format, args);
138 return;
139 } 103 }
140 104
141 /// <summary> 105 /// <summary>
142 /// Sends a notice to the current log output 106 /// Sends a notice to the current console output
143 /// </summary> 107 /// </summary>
144 /// <param name="sender">The module that sent this message</param> 108 /// <param name="sender">The module that sent this message</param>
145 /// <param name="format">The message to send</param> 109 /// <param name="format">The message to send</param>
@@ -148,22 +112,20 @@ namespace OpenSim.Framework.Console
148 { 112 {
149 WritePrefixLine(DeriveColor(sender), sender); 113 WritePrefixLine(DeriveColor(sender), sender);
150 WriteNewLine(ConsoleColor.White, format, args); 114 WriteNewLine(ConsoleColor.White, format, args);
151 return;
152 } 115 }
153 116
154 /// <summary> 117 /// <summary>
155 /// Sends an error to the current log output 118 /// Sends an error to the current console output
156 /// </summary> 119 /// </summary>
157 /// <param name="format">The message to send</param> 120 /// <param name="format">The message to send</param>
158 /// <param name="args">WriteLine-style message arguments</param> 121 /// <param name="args">WriteLine-style message arguments</param>
159 public void Error(string format, params object[] args) 122 public void Error(string format, params object[] args)
160 { 123 {
161 WriteNewLine(ConsoleColor.Red, format, args); 124 WriteNewLine(ConsoleColor.Red, format, args);
162 return;
163 } 125 }
164 126
165 /// <summary> 127 /// <summary>
166 /// Sends an error to the current log output 128 /// Sends an error to the current console output
167 /// </summary> 129 /// </summary>
168 /// <param name="sender">The module that sent this message</param> 130 /// <param name="sender">The module that sent this message</param>
169 /// <param name="format">The message to send</param> 131 /// <param name="format">The message to send</param>
@@ -172,38 +134,20 @@ namespace OpenSim.Framework.Console
172 { 134 {
173 WritePrefixLine(DeriveColor(sender), sender); 135 WritePrefixLine(DeriveColor(sender), sender);
174 Error(format, args); 136 Error(format, args);
175 return;
176 } 137 }
177 138
178 /// <summary> 139 /// <summary>
179 /// Sends an informational message to the current log output 140 /// Sends a status message to the current console output
180 /// </summary>
181 /// <param name="sender">The module that sent this message</param>
182 /// <param name="format">The message to send</param>
183 /// <param name="args">WriteLine-style message arguments</param>
184 public void Verbose(string sender, string format, params object[] args)
185 {
186 if (m_verbose)
187 {
188 WritePrefixLine(DeriveColor(sender), sender);
189 WriteNewLine(ConsoleColor.Gray, format, args);
190 return;
191 }
192 }
193
194 /// <summary>
195 /// Sends a status message to the current log output
196 /// </summary> 141 /// </summary>
197 /// <param name="format">The message to send</param> 142 /// <param name="format">The message to send</param>
198 /// <param name="args">WriteLine-style message arguments</param> 143 /// <param name="args">WriteLine-style message arguments</param>
199 public void Status(string format, params object[] args) 144 public void Status(string format, params object[] args)
200 { 145 {
201 WriteNewLine(ConsoleColor.Blue, format, args); 146 WriteNewLine(ConsoleColor.Blue, format, args);
202 return;
203 } 147 }
204 148
205 /// <summary> 149 /// <summary>
206 /// Sends a status message to the current log output 150 /// Sends a status message to the current console output
207 /// </summary> 151 /// </summary>
208 /// <param name="sender">The module that sent this message</param> 152 /// <param name="sender">The module that sent this message</param>
209 /// <param name="format">The message to send</param> 153 /// <param name="format">The message to send</param>
@@ -212,14 +156,12 @@ namespace OpenSim.Framework.Console
212 { 156 {
213 WritePrefixLine(DeriveColor(sender), sender); 157 WritePrefixLine(DeriveColor(sender), sender);
214 WriteNewLine(ConsoleColor.Blue, format, args); 158 WriteNewLine(ConsoleColor.Blue, format, args);
215 return;
216 } 159 }
217 160
218 [Conditional("DEBUG")] 161 [Conditional("DEBUG")]
219 public void Debug(string format, params object[] args) 162 public void Debug(string format, params object[] args)
220 { 163 {
221 WriteNewLine(ConsoleColor.Gray, format, args); 164 WriteNewLine(ConsoleColor.Gray, format, args);
222 return;
223 } 165 }
224 166
225 [Conditional("DEBUG")] 167 [Conditional("DEBUG")]
@@ -227,7 +169,6 @@ namespace OpenSim.Framework.Console
227 { 169 {
228 WritePrefixLine(DeriveColor(sender), sender); 170 WritePrefixLine(DeriveColor(sender), sender);
229 WriteNewLine(ConsoleColor.Gray, format, args); 171 WriteNewLine(ConsoleColor.Gray, format, args);
230 return;
231 } 172 }
232 173
233 private void WriteNewLine(ConsoleColor color, string format, params object[] args) 174 private void WriteNewLine(ConsoleColor color, string format, params object[] args)
@@ -236,19 +177,16 @@ namespace OpenSim.Framework.Console
236 { 177 {
237 lock (m_syncRoot) 178 lock (m_syncRoot)
238 { 179 {
239 string now = DateTime.Now.ToString("[MM-dd HH:mm:ss] ");
240 Log.Write(now);
241 try 180 try
242 { 181 {
243 Log.WriteLine(format, args); 182 System.Console.WriteLine(format, args);
244 Log.Flush();
245 } 183 }
246 184
247 catch (FormatException) 185 catch (FormatException)
248 { 186 {
249 System.Console.WriteLine(args); 187 System.Console.WriteLine(args);
250 } 188 }
251 System.Console.Write(now); 189
252 try 190 try
253 { 191 {
254 if (color != ConsoleColor.White) 192 if (color != ConsoleColor.White)
@@ -267,13 +205,10 @@ namespace OpenSim.Framework.Console
267 // Some older systems dont support coloured text. 205 // Some older systems dont support coloured text.
268 System.Console.WriteLine(args); 206 System.Console.WriteLine(args);
269 } 207 }
270
271 return;
272 } 208 }
273 } 209 }
274 catch (ObjectDisposedException) 210 catch (ObjectDisposedException)
275 { 211 {
276 return;
277 } 212 }
278 } 213 }
279 214
@@ -285,10 +220,7 @@ namespace OpenSim.Framework.Console
285 { 220 {
286 sender = sender.ToUpper(); 221 sender = sender.ToUpper();
287 222
288 Log.WriteLine("[" + sender + "] "); 223 System.Console.WriteLine("[" + sender + "] ");
289
290
291 Log.Flush();
292 224
293 System.Console.Write("["); 225 System.Console.Write("[");
294 226
@@ -305,37 +237,29 @@ namespace OpenSim.Framework.Console
305 } 237 }
306 238
307 System.Console.Write("] \t"); 239 System.Console.Write("] \t");
308
309 return;
310 } 240 }
311 } 241 }
312 catch (ObjectDisposedException) 242 catch (ObjectDisposedException)
313 { 243 {
314 return;
315 } 244 }
316 } 245 }
317 246
318
319 public string ReadLine() 247 public string ReadLine()
320 { 248 {
321 try 249 try
322 { 250 {
323 string TempStr = System.Console.ReadLine(); 251 return System.Console.ReadLine();
324 Log.WriteLine(TempStr);
325 return TempStr;
326 } 252 }
327 catch (Exception e) 253 catch (Exception e)
328 { 254 {
329 MainLog.Instance.Error("Console", "System.Console.ReadLine exception " + e.ToString()); 255 m_log.Error("[Console]: System.Console.ReadLine exception " + e.ToString());
330 return String.Empty; 256 return String.Empty;
331 } 257 }
332 } 258 }
333 259
334 public int Read() 260 public int Read()
335 { 261 {
336 int TempInt = System.Console.Read(); 262 return System.Console.Read();
337 Log.Write((char) TempInt);
338 return TempInt;
339 } 263 }
340 264
341 public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue) 265 public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue)
@@ -345,14 +269,14 @@ namespace OpenSim.Framework.Console
345 269
346 while (true) 270 while (true)
347 { 271 {
348 addressStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue); 272 addressStr = CmdPrompt(prompt, defaultvalue);
349 if (IPAddress.TryParse(addressStr, out address)) 273 if (IPAddress.TryParse(addressStr, out address))
350 { 274 {
351 break; 275 break;
352 } 276 }
353 else 277 else
354 { 278 {
355 MainLog.Instance.Error("Illegal address. Please re-enter."); 279 m_log.Error("Illegal address. Please re-enter.");
356 } 280 }
357 } 281 }
358 282
@@ -366,7 +290,7 @@ namespace OpenSim.Framework.Console
366 290
367 while (true) 291 while (true)
368 { 292 {
369 portStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue); 293 portStr = CmdPrompt(prompt, defaultvalue);
370 if (uint.TryParse(portStr, out port)) 294 if (uint.TryParse(portStr, out port))
371 { 295 {
372 if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort) 296 if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort)
@@ -375,7 +299,7 @@ namespace OpenSim.Framework.Console
375 } 299 }
376 } 300 }
377 301
378 MainLog.Instance.Error("Illegal address. Please re-enter."); 302 m_log.Error("Illegal address. Please re-enter.");
379 } 303 }
380 304
381 return port; 305 return port;
@@ -386,8 +310,6 @@ namespace OpenSim.Framework.Console
386 public string PasswdPrompt(string prompt) 310 public string PasswdPrompt(string prompt)
387 { 311 {
388 // FIXME: Needs to be better abstracted 312 // FIXME: Needs to be better abstracted
389 Log.WriteLine(prompt);
390 Notice(prompt);
391 ConsoleColor oldfg = System.Console.ForegroundColor; 313 ConsoleColor oldfg = System.Console.ForegroundColor;
392 System.Console.ForegroundColor = System.Console.BackgroundColor; 314 System.Console.ForegroundColor = System.Console.BackgroundColor;
393 string temp = System.Console.ReadLine(); 315 string temp = System.Console.ReadLine();
@@ -398,7 +320,7 @@ namespace OpenSim.Framework.Console
398 // Displays a command prompt and waits for the user to enter a string, then returns that string 320 // Displays a command prompt and waits for the user to enter a string, then returns that string
399 public string CmdPrompt(string prompt) 321 public string CmdPrompt(string prompt)
400 { 322 {
401 Notice(String.Format("{0}: ", prompt)); 323 System.Console.WriteLine(String.Format("{0}: ", prompt));
402 return ReadLine(); 324 return ReadLine();
403 } 325 }
404 326
@@ -429,7 +351,7 @@ namespace OpenSim.Framework.Console
429 } 351 }
430 else 352 else
431 { 353 {
432 Notice("Valid options are " + OptionA + " or " + OptionB); 354 System.Console.WriteLine("Valid options are " + OptionA + " or " + OptionB);
433 temp = CmdPrompt(prompt, defaultresponse); 355 temp = CmdPrompt(prompt, defaultresponse);
434 } 356 }
435 } 357 }
@@ -439,23 +361,23 @@ namespace OpenSim.Framework.Console
439 // Runs a command with a number of parameters 361 // Runs a command with a number of parameters
440 public Object RunCmd(string Cmd, string[] cmdparams) 362 public Object RunCmd(string Cmd, string[] cmdparams)
441 { 363 {
442 cmdparser.RunCmd(Cmd, cmdparams); 364 m_cmdParser.RunCmd(Cmd, cmdparams);
443 return null; 365 return null;
444 } 366 }
445 367
446 // Shows data about something 368 // Shows data about something
447 public void ShowCommands(string ShowWhat) 369 public void ShowCommands(string ShowWhat)
448 { 370 {
449 cmdparser.Show(ShowWhat); 371 m_cmdParser.Show(ShowWhat);
450 } 372 }
451 373
452 public void MainLogPrompt() 374 public void Prompt()
453 { 375 {
454 string tempstr = CmdPrompt(componentname + "# "); 376 string tempstr = CmdPrompt(m_componentName + "# ");
455 MainLogRunCommand(tempstr); 377 RunCommand(tempstr);
456 } 378 }
457 379
458 public void MainLogRunCommand(string command) 380 public void RunCommand(string command)
459 { 381 {
460 string[] tempstrarray; 382 string[] tempstrarray;
461 tempstrarray = command.Split(' '); 383 tempstrarray = command.Split(' ');
@@ -470,7 +392,7 @@ namespace OpenSim.Framework.Console
470 } 392 }
471 catch (Exception e) 393 catch (Exception e)
472 { 394 {
473 MainLog.Instance.Error("Console", "Command failed with exception " + e.ToString()); 395 m_log.Error("[Console]: Command failed with exception " + e.ToString());
474 } 396 }
475 } 397 }
476 398