* 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.0.6.0-stable
parent
701ee43e46
commit
c602d76b79
|
@ -32,17 +32,22 @@ using log4net.Core;
|
||||||
|
|
||||||
namespace OpenSim.Framework.Console
|
namespace OpenSim.Framework.Console
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Writes log information out onto the console
|
||||||
|
/// </summary>
|
||||||
public class OpenSimAppender : AnsiColorTerminalAppender
|
public class OpenSimAppender : AnsiColorTerminalAppender
|
||||||
{
|
{
|
||||||
override protected void Append(LoggingEvent le)
|
override protected void Append(LoggingEvent le)
|
||||||
{
|
{
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
string loggingMessage = RenderLoggingEvent(le);
|
string loggingMessage = RenderLoggingEvent(le);
|
||||||
|
|
||||||
string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";
|
string regex = @"^(?<Front>.*?)\[(?<Category>[^\]]+)\]:?(?<End>.*)";
|
||||||
|
|
||||||
Regex RE = new Regex(regex, RegexOptions.Multiline);
|
Regex RE = new Regex(regex, RegexOptions.Multiline);
|
||||||
MatchCollection matches = RE.Matches(loggingMessage);
|
MatchCollection matches = RE.Matches(loggingMessage);
|
||||||
|
|
||||||
// Get some direct matches $1 $4 is a
|
// Get some direct matches $1 $4 is a
|
||||||
if (matches.Count == 1)
|
if (matches.Count == 1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,9 @@ using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using log4net;
|
using log4net;
|
||||||
|
using log4net.Appender;
|
||||||
|
using log4net.Core;
|
||||||
|
using log4net.Repository;
|
||||||
using OpenSim.Framework.Console;
|
using OpenSim.Framework.Console;
|
||||||
using OpenSim.Framework.Statistics;
|
using OpenSim.Framework.Statistics;
|
||||||
|
|
||||||
|
@ -121,6 +124,50 @@ namespace OpenSim.Framework.Servers
|
||||||
return sb.ToString();
|
return sb.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set the level of log notices being echoed to the console
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="setParams"></param>
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Performs initialisation of the scene, such as loading configuration from disk.
|
/// Performs initialisation of the scene, such as loading configuration from disk.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -156,6 +203,7 @@ namespace OpenSim.Framework.Servers
|
||||||
Notice("");
|
Notice("");
|
||||||
Notice("quit - equivalent to shutdown.");
|
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).");
|
Notice("show info - show server information (e.g. startup path).");
|
||||||
|
|
||||||
if (m_stats != null)
|
if (m_stats != null)
|
||||||
|
@ -168,6 +216,10 @@ namespace OpenSim.Framework.Servers
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case "set":
|
||||||
|
Set(cmdparams);
|
||||||
|
break;
|
||||||
|
|
||||||
case "show":
|
case "show":
|
||||||
if (cmdparams.Length > 0)
|
if (cmdparams.Length > 0)
|
||||||
{
|
{
|
||||||
|
@ -182,13 +234,36 @@ namespace OpenSim.Framework.Servers
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set an OpenSim parameter
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="setArgs">
|
||||||
|
/// The arguments given to the set command.
|
||||||
|
/// </param>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Outputs to the console information about the region
|
/// Outputs to the console information about the region
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="ShowWhat">What information to display (valid arguments are "uptime", "users")</param>
|
/// <param name="showWhat">
|
||||||
public virtual void Show(string ShowWhat)
|
/// What information to display (valid arguments are "uptime", "users")
|
||||||
|
/// </param>
|
||||||
|
public virtual void Show(string showWhat)
|
||||||
{
|
{
|
||||||
switch (ShowWhat)
|
switch (showWhat)
|
||||||
{
|
{
|
||||||
case "info":
|
case "info":
|
||||||
Notice("Version: " + m_version);
|
Notice("Version: " + m_version);
|
||||||
|
|
|
@ -214,6 +214,7 @@ namespace OpenSim
|
||||||
{
|
{
|
||||||
base.RunCmd(command, cmdparams);
|
base.RunCmd(command, cmdparams);
|
||||||
RunPluginCommands(command , cmdparams);
|
RunPluginCommands(command , cmdparams);
|
||||||
|
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case "clear-assets":
|
case "clear-assets":
|
||||||
|
|
|
@ -48,7 +48,6 @@ namespace OpenSim.Region.ClientStack.LindenUDP
|
||||||
{
|
{
|
||||||
public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
|
public delegate bool PacketMethod(IClientAPI simClient, Packet packet);
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles new client connections
|
/// Handles new client connections
|
||||||
/// Constructor takes a single Packet and authenticates everything
|
/// Constructor takes a single Packet and authenticates everything
|
||||||
|
|
Loading…
Reference in New Issue