aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorJustin Clarke Casey2008-08-16 20:24:08 +0000
committerJustin Clarke Casey2008-08-16 20:24:08 +0000
commitc602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff (patch)
treec890bca7c2bc8050b0eedd8a8f339c4af25abf1a /OpenSim/Framework
parentMantis#1960. Thank you kindly, Tyre for a patch that: (diff)
downloadopensim-SC_OLD-c602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff.zip
opensim-SC_OLD-c602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff.tar.gz
opensim-SC_OLD-c602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff.tar.bz2
opensim-SC_OLD-c602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff.tar.xz
* Insert a new 'set log level [level] command on the console'
* The primary immediate use is to provide a means of temporarily reducing log output on the console when executing console commands * Changing the log level on the console is not permanent and does not affect the log information being put into OpenSim.log * This could have been done by putting in a threshold level on the Console appeneder in OpenSim.exe.config and implementing config watching in the code. * But I think that it's a little more user friendly to make this doable via the console.
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/Console/OpenSimAppender.cs7
-rw-r--r--OpenSim/Framework/Servers/BaseOpenSimServer.cs85
2 files changed, 86 insertions, 6 deletions
diff --git a/OpenSim/Framework/Console/OpenSimAppender.cs b/OpenSim/Framework/Console/OpenSimAppender.cs
index ddd6d9a..2527977 100644
--- a/OpenSim/Framework/Console/OpenSimAppender.cs
+++ b/OpenSim/Framework/Console/OpenSimAppender.cs
@@ -32,17 +32,22 @@ using log4net.Core;
32 32
33namespace OpenSim.Framework.Console 33namespace OpenSim.Framework.Console
34{ 34{
35 /// <summary>
36 /// Writes log information out onto the console
37 /// </summary>
35 public class OpenSimAppender : AnsiColorTerminalAppender 38 public class OpenSimAppender : AnsiColorTerminalAppender
36 { 39 {
37 override protected void Append(LoggingEvent le) 40 override protected void Append(LoggingEvent le)
38 { 41 {
39 try { 42 try
43 {
40 string loggingMessage = RenderLoggingEvent(le); 44 string loggingMessage = RenderLoggingEvent(le);
41 45
42 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)"; 46 string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";
43 47
44 Regex RE = new Regex(regex, RegexOptions.Multiline); 48 Regex RE = new Regex(regex, RegexOptions.Multiline);
45 MatchCollection matches = RE.Matches(loggingMessage); 49 MatchCollection matches = RE.Matches(loggingMessage);
50
46 // Get some direct matches $1 $4 is a 51 // Get some direct matches $1 $4 is a
47 if (matches.Count == 1) 52 if (matches.Count == 1)
48 { 53 {
diff --git a/OpenSim/Framework/Servers/BaseOpenSimServer.cs b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
index 65c989d..e901b68 100644
--- a/OpenSim/Framework/Servers/BaseOpenSimServer.cs
+++ b/OpenSim/Framework/Servers/BaseOpenSimServer.cs
@@ -33,6 +33,9 @@ using System.Text;
33using System.Threading; 33using System.Threading;
34using System.Timers; 34using System.Timers;
35using log4net; 35using log4net;
36using log4net.Appender;
37using log4net.Core;
38using log4net.Repository;
36using OpenSim.Framework.Console; 39using OpenSim.Framework.Console;
37using OpenSim.Framework.Statistics; 40using OpenSim.Framework.Statistics;
38 41
@@ -120,6 +123,50 @@ namespace OpenSim.Framework.Servers
120 123
121 return sb.ToString(); 124 return sb.ToString();
122 } 125 }
126
127 /// <summary>
128 /// Set the level of log notices being echoed to the console
129 /// </summary>
130 /// <param name="setParams"></param>
131 private void SetConsoleLogLevel(string[] setParams)
132 {
133 ILoggerRepository repository = LogManager.GetRepository();
134 IAppender[] appenders = repository.GetAppenders();
135 OpenSimAppender consoleAppender = null;
136
137 foreach (IAppender appender in appenders)
138 {
139 if (appender.Name == "Console")
140 {
141 consoleAppender = (OpenSimAppender)appender;
142 break;
143 }
144 }
145
146 if (null == consoleAppender)
147 {
148 Notice("No appender named Console found (see the log4net config file for this executable)!");
149 return;
150 }
151
152 if (setParams.Length > 0)
153 {
154 Level consoleLevel = repository.LevelMap[setParams[0]];
155 if (consoleLevel != null)
156 consoleAppender.Threshold = consoleLevel;
157 else
158 Notice(
159 String.Format(
160 "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF",
161 setParams[0]));
162 }
163
164 // If there is no threshold set then the threshold is effectively everything.
165 Level thresholdLevel
166 = (null != consoleAppender.Threshold ? consoleAppender.Threshold : log4net.Core.Level.All);
167
168 Notice(String.Format("Console log level is {0}", thresholdLevel));
169 }
123 170
124 /// <summary> 171 /// <summary>
125 /// Performs initialisation of the scene, such as loading configuration from disk. 172 /// Performs initialisation of the scene, such as loading configuration from disk.
@@ -156,6 +203,7 @@ namespace OpenSim.Framework.Servers
156 Notice(""); 203 Notice("");
157 Notice("quit - equivalent to shutdown."); 204 Notice("quit - equivalent to shutdown.");
158 205
206 Notice("set log level [level] - change the console logging level only. For example, off or debug.");
159 Notice("show info - show server information (e.g. startup path)."); 207 Notice("show info - show server information (e.g. startup path).");
160 208
161 if (m_stats != null) 209 if (m_stats != null)
@@ -168,6 +216,10 @@ namespace OpenSim.Framework.Servers
168 216
169 break; 217 break;
170 218
219 case "set":
220 Set(cmdparams);
221 break;
222
171 case "show": 223 case "show":
172 if (cmdparams.Length > 0) 224 if (cmdparams.Length > 0)
173 { 225 {
@@ -180,15 +232,38 @@ namespace OpenSim.Framework.Servers
180 Shutdown(); 232 Shutdown();
181 break; 233 break;
182 } 234 }
183 } 235 }
236
237 /// <summary>
238 /// Set an OpenSim parameter
239 /// </summary>
240 /// <param name="setArgs">
241 /// The arguments given to the set command.
242 /// </param>
243 public virtual void Set(string[] setArgs)
244 {
245 // Temporary while we only have one command which takes at least two parameters
246 if (setArgs.Length < 2)
247 return;
248
249 if (setArgs[0] == "log" && setArgs[1] == "level")
250 {
251 string[] setParams = new string[setArgs.Length - 2];
252 Array.Copy(setArgs, 2, setParams, 0, setArgs.Length - 2);
253
254 SetConsoleLogLevel(setParams);
255 }
256 }
184 257
185 /// <summary> 258 /// <summary>
186 /// Outputs to the console information about the region 259 /// Outputs to the console information about the region
187 /// </summary> 260 /// </summary>
188 /// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param> 261 /// <param name="showWhat">
189 public virtual void Show(string ShowWhat) 262 /// What information to display (valid arguments are "uptime", "users")
263 /// </param>
264 public virtual void Show(string showWhat)
190 { 265 {
191 switch (ShowWhat) 266 switch (showWhat)
192 { 267 {
193 case "info": 268 case "info":
194 Notice("Version: " + m_version); 269 Notice("Version: " + m_version);
@@ -226,7 +301,7 @@ namespace OpenSim.Framework.Servers
226 Notice("Version: " + m_version); 301 Notice("Version: " + m_version);
227 break; 302 break;
228 } 303 }
229 } 304 }
230 305
231 /// <summary> 306 /// <summary>
232 /// Console output is only possible if a console has been established. 307 /// Console output is only possible if a console has been established.