From c602d76b79f09c745ae4e7a1a7ab6a2d6f2c3bff Mon Sep 17 00:00:00 2001
From: Justin Clarke Casey
Date: Sat, 16 Aug 2008 20:24:08 +0000
Subject: * 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.
---
OpenSim/Framework/Console/OpenSimAppender.cs | 7 +-
OpenSim/Framework/Servers/BaseOpenSimServer.cs | 85 ++++++++++++++++++++--
OpenSim/Region/Application/OpenSim.cs | 1 +
.../Region/ClientStack/LindenUDP/LLClientView.cs | 1 -
4 files changed, 87 insertions(+), 7 deletions(-)
(limited to 'OpenSim')
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;
namespace OpenSim.Framework.Console
{
+ ///
+ /// Writes log information out onto the console
+ ///
public class OpenSimAppender : AnsiColorTerminalAppender
{
override protected void Append(LoggingEvent le)
{
- try {
+ try
+ {
string loggingMessage = RenderLoggingEvent(le);
string regex = @"^(?.*?)\[(?[^\]]+)\]:?(?.*)";
Regex RE = new Regex(regex, RegexOptions.Multiline);
MatchCollection matches = RE.Matches(loggingMessage);
+
// Get some direct matches $1 $4 is a
if (matches.Count == 1)
{
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;
using System.Threading;
using System.Timers;
using log4net;
+using log4net.Appender;
+using log4net.Core;
+using log4net.Repository;
using OpenSim.Framework.Console;
using OpenSim.Framework.Statistics;
@@ -120,6 +123,50 @@ namespace OpenSim.Framework.Servers
return sb.ToString();
}
+
+ ///
+ /// Set the level of log notices being echoed to the console
+ ///
+ ///
+ private void SetConsoleLogLevel(string[] setParams)
+ {
+ ILoggerRepository repository = LogManager.GetRepository();
+ IAppender[] appenders = repository.GetAppenders();
+ OpenSimAppender consoleAppender = null;
+
+ foreach (IAppender appender in appenders)
+ {
+ if (appender.Name == "Console")
+ {
+ consoleAppender = (OpenSimAppender)appender;
+ break;
+ }
+ }
+
+ if (null == consoleAppender)
+ {
+ Notice("No appender named Console found (see the log4net config file for this executable)!");
+ return;
+ }
+
+ if (setParams.Length > 0)
+ {
+ Level consoleLevel = repository.LevelMap[setParams[0]];
+ if (consoleLevel != null)
+ consoleAppender.Threshold = consoleLevel;
+ else
+ Notice(
+ String.Format(
+ "{0} is not a valid logging level. Valid logging levels are ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF",
+ setParams[0]));
+ }
+
+ // If there is no threshold set then the threshold is effectively everything.
+ Level thresholdLevel
+ = (null != consoleAppender.Threshold ? consoleAppender.Threshold : log4net.Core.Level.All);
+
+ Notice(String.Format("Console log level is {0}", thresholdLevel));
+ }
///
/// Performs initialisation of the scene, such as loading configuration from disk.
@@ -156,6 +203,7 @@ namespace OpenSim.Framework.Servers
Notice("");
Notice("quit - equivalent to shutdown.");
+ Notice("set log level [level] - change the console logging level only. For example, off or debug.");
Notice("show info - show server information (e.g. startup path).");
if (m_stats != null)
@@ -168,6 +216,10 @@ namespace OpenSim.Framework.Servers
break;
+ case "set":
+ Set(cmdparams);
+ break;
+
case "show":
if (cmdparams.Length > 0)
{
@@ -180,15 +232,38 @@ namespace OpenSim.Framework.Servers
Shutdown();
break;
}
- }
+ }
+
+ ///
+ /// Set an OpenSim parameter
+ ///
+ ///
+ /// The arguments given to the set command.
+ ///
+ public virtual void Set(string[] setArgs)
+ {
+ // Temporary while we only have one command which takes at least two parameters
+ if (setArgs.Length < 2)
+ return;
+
+ if (setArgs[0] == "log" && setArgs[1] == "level")
+ {
+ string[] setParams = new string[setArgs.Length - 2];
+ Array.Copy(setArgs, 2, setParams, 0, setArgs.Length - 2);
+
+ SetConsoleLogLevel(setParams);
+ }
+ }
///
/// Outputs to the console information about the region
///
- /// What information to display (valid arguments are "uptime", "users")
- public virtual void Show(string ShowWhat)
+ ///
+ /// What information to display (valid arguments are "uptime", "users")
+ ///
+ public virtual void Show(string showWhat)
{
- switch (ShowWhat)
+ switch (showWhat)
{
case "info":
Notice("Version: " + m_version);
@@ -226,7 +301,7 @@ namespace OpenSim.Framework.Servers
Notice("Version: " + m_version);
break;
}
- }
+ }
///
/// Console output is only possible if a console has been established.
diff --git a/OpenSim/Region/Application/OpenSim.cs b/OpenSim/Region/Application/OpenSim.cs
index bf7044f..4664b0b 100644
--- a/OpenSim/Region/Application/OpenSim.cs
+++ b/OpenSim/Region/Application/OpenSim.cs
@@ -214,6 +214,7 @@ namespace OpenSim
{
base.RunCmd(command, cmdparams);
RunPluginCommands(command , cmdparams);
+
switch (command)
{
case "clear-assets":
diff --git a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
index 4869858..b14b3db 100644
--- a/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
+++ b/OpenSim/Region/ClientStack/LindenUDP/LLClientView.cs
@@ -48,7 +48,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
{
public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
-
///
/// Handles new client connections
/// Constructor takes a single Packet and authenticates everything
--
cgit v1.1