aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Console/LogBase.cs
diff options
context:
space:
mode:
authorSean Dague2007-07-16 15:40:11 +0000
committerSean Dague2007-07-16 15:40:11 +0000
commit2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 (patch)
treee3f80ad51736cf17e856547b1bcf956010927434 /OpenSim/Framework/Console/LogBase.cs
parent*Trunk compiles now (diff)
downloadopensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.zip
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.gz
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.bz2
opensim-SC-2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6.tar.xz
changed to native line ending encoding
Diffstat (limited to 'OpenSim/Framework/Console/LogBase.cs')
-rw-r--r--OpenSim/Framework/Console/LogBase.cs564
1 files changed, 282 insertions, 282 deletions
diff --git a/OpenSim/Framework/Console/LogBase.cs b/OpenSim/Framework/Console/LogBase.cs
index f73e15e..1eb6ff0 100644
--- a/OpenSim/Framework/Console/LogBase.cs
+++ b/OpenSim/Framework/Console/LogBase.cs
@@ -1,282 +1,282 @@
1/* 1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/ 2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Net; 30using System.Net;
31 31
32namespace OpenSim.Framework.Console 32namespace OpenSim.Framework.Console
33{ 33{
34 public enum LogPriority : int 34 public enum LogPriority : int
35 { 35 {
36 CRITICAL, 36 CRITICAL,
37 HIGH, 37 HIGH,
38 MEDIUM, 38 MEDIUM,
39 NORMAL, 39 NORMAL,
40 LOW, 40 LOW,
41 VERBOSE, 41 VERBOSE,
42 EXTRAVERBOSE 42 EXTRAVERBOSE
43 } 43 }
44 44
45 public class LogBase 45 public class LogBase
46 { 46 {
47 StreamWriter Log; 47 StreamWriter Log;
48 public conscmd_callback cmdparser; 48 public conscmd_callback cmdparser;
49 public string componentname; 49 public string componentname;
50 private bool m_silent; 50 private bool m_silent;
51 51
52 public LogBase(string LogFile, string componentname, conscmd_callback cmdparser, bool silent) 52 public LogBase(string LogFile, string componentname, conscmd_callback cmdparser, bool silent)
53 { 53 {
54 this.componentname = componentname; 54 this.componentname = componentname;
55 this.cmdparser = cmdparser; 55 this.cmdparser = cmdparser;
56 this.m_silent = silent; 56 this.m_silent = silent;
57 System.Console.WriteLine("ServerConsole.cs - creating new local console"); 57 System.Console.WriteLine("ServerConsole.cs - creating new local console");
58 58
59 if (String.IsNullOrEmpty(LogFile)) 59 if (String.IsNullOrEmpty(LogFile))
60 { 60 {
61 LogFile = componentname + ".log"; 61 LogFile = componentname + ".log";
62 } 62 }
63 63
64 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile); 64 System.Console.WriteLine("Logs will be saved to current directory in " + LogFile);
65 Log = File.AppendText(LogFile); 65 Log = File.AppendText(LogFile);
66 Log.WriteLine("========================================================================"); 66 Log.WriteLine("========================================================================");
67 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString()); 67 Log.WriteLine(componentname + " Started at " + DateTime.Now.ToString());
68 } 68 }
69 69
70 public void Close() 70 public void Close()
71 { 71 {
72 Log.WriteLine("Shutdown at " + DateTime.Now.ToString()); 72 Log.WriteLine("Shutdown at " + DateTime.Now.ToString());
73 Log.Close(); 73 Log.Close();
74 } 74 }
75 75
76 public void Write(string format, params object[] args) 76 public void Write(string format, params object[] args)
77 { 77 {
78 Notice(format, args); 78 Notice(format, args);
79 return; 79 return;
80 } 80 }
81 81
82 public void WriteLine(LogPriority importance, string format, params object[] args) 82 public void WriteLine(LogPriority importance, string format, params object[] args)
83 { 83 {
84 Log.WriteLine(format, args); 84 Log.WriteLine(format, args);
85 Log.Flush(); 85 Log.Flush();
86 if (!m_silent) 86 if (!m_silent)
87 { 87 {
88 System.Console.WriteLine(format, args); 88 System.Console.WriteLine(format, args);
89 } 89 }
90 return; 90 return;
91 } 91 }
92 92
93 public void Warn(string format, params object[] args) 93 public void Warn(string format, params object[] args)
94 { 94 {
95 WriteNewLine(ConsoleColor.Yellow, format, args); 95 WriteNewLine(ConsoleColor.Yellow, format, args);
96 return; 96 return;
97 } 97 }
98 98
99 public void Notice(string format, params object[] args) 99 public void Notice(string format, params object[] args)
100 { 100 {
101 WriteNewLine(ConsoleColor.White, format, args); 101 WriteNewLine(ConsoleColor.White, format, args);
102 return; 102 return;
103 } 103 }
104 104
105 public void Error(string format, params object[] args) 105 public void Error(string format, params object[] args)
106 { 106 {
107 WriteNewLine(ConsoleColor.Red, format, args); 107 WriteNewLine(ConsoleColor.Red, format, args);
108 return; 108 return;
109 } 109 }
110 110
111 public void Verbose(string format, params object[] args) 111 public void Verbose(string format, params object[] args)
112 { 112 {
113 WriteNewLine(ConsoleColor.Gray, format, args); 113 WriteNewLine(ConsoleColor.Gray, format, args);
114 return; 114 return;
115 } 115 }
116 116
117 public void Status(string format, params object[] args) 117 public void Status(string format, params object[] args)
118 { 118 {
119 WriteNewLine(ConsoleColor.Blue, format, args); 119 WriteNewLine(ConsoleColor.Blue, format, args);
120 return; 120 return;
121 } 121 }
122 122
123 private void WriteNewLine(ConsoleColor color, string format, params object[] args) 123 private void WriteNewLine(ConsoleColor color, string format, params object[] args)
124 { 124 {
125 Log.WriteLine(format, args); 125 Log.WriteLine(format, args);
126 Log.Flush(); 126 Log.Flush();
127 if (!m_silent) 127 if (!m_silent)
128 { 128 {
129 try 129 try
130 { 130 {
131 System.Console.ForegroundColor = color; 131 System.Console.ForegroundColor = color;
132 System.Console.WriteLine(format, args); 132 System.Console.WriteLine(format, args);
133 System.Console.ResetColor(); 133 System.Console.ResetColor();
134 } 134 }
135 catch (ArgumentNullException) 135 catch (ArgumentNullException)
136 { 136 {
137 // Some older systems dont support coloured text. 137 // Some older systems dont support coloured text.
138 System.Console.WriteLine(format, args); 138 System.Console.WriteLine(format, args);
139 } 139 }
140 } 140 }
141 return; 141 return;
142 } 142 }
143 143
144 public string ReadLine() 144 public string ReadLine()
145 { 145 {
146 string TempStr = System.Console.ReadLine(); 146 string TempStr = System.Console.ReadLine();
147 Log.WriteLine(TempStr); 147 Log.WriteLine(TempStr);
148 return TempStr; 148 return TempStr;
149 } 149 }
150 150
151 public int Read() 151 public int Read()
152 { 152 {
153 int TempInt = System.Console.Read(); 153 int TempInt = System.Console.Read();
154 Log.Write((char)TempInt); 154 Log.Write((char)TempInt);
155 return TempInt; 155 return TempInt;
156 } 156 }
157 157
158 public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue) 158 public IPAddress CmdPromptIPAddress(string prompt, string defaultvalue)
159 { 159 {
160 IPAddress address; 160 IPAddress address;
161 string addressStr; 161 string addressStr;
162 162
163 while (true) 163 while (true)
164 { 164 {
165 addressStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue); 165 addressStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue);
166 if (IPAddress.TryParse(addressStr, out address)) 166 if (IPAddress.TryParse(addressStr, out address))
167 { 167 {
168 break; 168 break;
169 } 169 }
170 else 170 else
171 { 171 {
172 MainLog.Instance.Error("Illegal address. Please re-enter."); 172 MainLog.Instance.Error("Illegal address. Please re-enter.");
173 } 173 }
174 } 174 }
175 175
176 return address; 176 return address;
177 } 177 }
178 178
179 public int CmdPromptIPPort(string prompt, string defaultvalue) 179 public int CmdPromptIPPort(string prompt, string defaultvalue)
180 { 180 {
181 int port; 181 int port;
182 string portStr; 182 string portStr;
183 183
184 while (true) 184 while (true)
185 { 185 {
186 portStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue); 186 portStr = MainLog.Instance.CmdPrompt(prompt, defaultvalue);
187 if (int.TryParse(portStr, out port)) 187 if (int.TryParse(portStr, out port))
188 { 188 {
189 if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort) 189 if (port >= IPEndPoint.MinPort && port <= IPEndPoint.MaxPort)
190 { 190 {
191 break; 191 break;
192 } 192 }
193 } 193 }
194 194
195 MainLog.Instance.Error("Illegal address. Please re-enter."); 195 MainLog.Instance.Error("Illegal address. Please re-enter.");
196 } 196 }
197 197
198 return port; 198 return port;
199 } 199 }
200 200
201 // Displays a prompt and waits for the user to enter a string, then returns that string 201 // Displays a prompt and waits for the user to enter a string, then returns that string
202 // Done with no echo and suitable for passwords 202 // Done with no echo and suitable for passwords
203 public string PasswdPrompt(string prompt) 203 public string PasswdPrompt(string prompt)
204 { 204 {
205 // FIXME: Needs to be better abstracted 205 // FIXME: Needs to be better abstracted
206 Log.WriteLine(prompt); 206 Log.WriteLine(prompt);
207 this.Write(prompt); 207 this.Write(prompt);
208 ConsoleColor oldfg = System.Console.ForegroundColor; 208 ConsoleColor oldfg = System.Console.ForegroundColor;
209 System.Console.ForegroundColor = System.Console.BackgroundColor; 209 System.Console.ForegroundColor = System.Console.BackgroundColor;
210 string temp = System.Console.ReadLine(); 210 string temp = System.Console.ReadLine();
211 System.Console.ForegroundColor = oldfg; 211 System.Console.ForegroundColor = oldfg;
212 return temp; 212 return temp;
213 } 213 }
214 214
215 // Displays a command prompt and waits for the user to enter a string, then returns that string 215 // Displays a command prompt and waits for the user to enter a string, then returns that string
216 public string CmdPrompt(string prompt) 216 public string CmdPrompt(string prompt)
217 { 217 {
218 this.Write(String.Format("{0}: ", prompt)); 218 this.Write(String.Format("{0}: ", prompt));
219 return this.ReadLine(); 219 return this.ReadLine();
220 } 220 }
221 221
222 // Displays a command prompt and returns a default value if the user simply presses enter 222 // Displays a command prompt and returns a default value if the user simply presses enter
223 public string CmdPrompt(string prompt, string defaultresponse) 223 public string CmdPrompt(string prompt, string defaultresponse)
224 { 224 {
225 string temp = CmdPrompt(String.Format("{0} [{1}]", prompt, defaultresponse)); 225 string temp = CmdPrompt(String.Format("{0} [{1}]", prompt, defaultresponse));
226 if (temp == "") 226 if (temp == "")
227 { 227 {
228 return defaultresponse; 228 return defaultresponse;
229 } 229 }
230 else 230 else
231 { 231 {
232 return temp; 232 return temp;
233 } 233 }
234 } 234 }
235 235
236 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options 236 // Displays a command prompt and returns a default value, user may only enter 1 of 2 options
237 public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB) 237 public string CmdPrompt(string prompt, string defaultresponse, string OptionA, string OptionB)
238 { 238 {
239 bool itisdone = false; 239 bool itisdone = false;
240 string temp = CmdPrompt(prompt, defaultresponse); 240 string temp = CmdPrompt(prompt, defaultresponse);
241 while (itisdone == false) 241 while (itisdone == false)
242 { 242 {
243 if ((temp == OptionA) || (temp == OptionB)) 243 if ((temp == OptionA) || (temp == OptionB))
244 { 244 {
245 itisdone = true; 245 itisdone = true;
246 } 246 }
247 else 247 else
248 { 248 {
249 Notice("Valid options are " + OptionA + " or " + OptionB); 249 Notice("Valid options are " + OptionA + " or " + OptionB);
250 temp = CmdPrompt(prompt, defaultresponse); 250 temp = CmdPrompt(prompt, defaultresponse);
251 } 251 }
252 } 252 }
253 return temp; 253 return temp;
254 } 254 }
255 255
256 // Runs a command with a number of parameters 256 // Runs a command with a number of parameters
257 public Object RunCmd(string Cmd, string[] cmdparams) 257 public Object RunCmd(string Cmd, string[] cmdparams)
258 { 258 {
259 cmdparser.RunCmd(Cmd, cmdparams); 259 cmdparser.RunCmd(Cmd, cmdparams);
260 return null; 260 return null;
261 } 261 }
262 262
263 // Shows data about something 263 // Shows data about something
264 public void ShowCommands(string ShowWhat) 264 public void ShowCommands(string ShowWhat)
265 { 265 {
266 cmdparser.Show(ShowWhat); 266 cmdparser.Show(ShowWhat);
267 } 267 }
268 268
269 public void MainLogPrompt() 269 public void MainLogPrompt()
270 { 270 {
271 string[] tempstrarray; 271 string[] tempstrarray;
272 string tempstr = this.CmdPrompt(this.componentname + "# "); 272 string tempstr = this.CmdPrompt(this.componentname + "# ");
273 tempstrarray = tempstr.Split(' '); 273 tempstrarray = tempstr.Split(' ');
274 string cmd = tempstrarray[0]; 274 string cmd = tempstrarray[0];
275 Array.Reverse(tempstrarray); 275 Array.Reverse(tempstrarray);
276 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1); 276 Array.Resize<string>(ref tempstrarray, tempstrarray.Length - 1);
277 Array.Reverse(tempstrarray); 277 Array.Reverse(tempstrarray);
278 string[] cmdparams = (string[])tempstrarray; 278 string[] cmdparams = (string[])tempstrarray;
279 RunCmd(cmd, cmdparams); 279 RunCmd(cmd, cmdparams);
280 } 280 }
281 } 281 }
282} 282}