Add some logging
parent
5afb70b9fe
commit
08b6b3bb48
|
@ -27,6 +27,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Timers;
|
||||
using log4net;
|
||||
using Nini.Config;
|
||||
using OpenMetaverse;
|
||||
|
@ -42,6 +43,10 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
|
|||
private static readonly ILog m_log = LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
private Timer m_logTimer = new Timer(10000);
|
||||
private List<GridInstantMessage> m_logData = new List<GridInstantMessage>();
|
||||
private string m_restUrl;
|
||||
|
||||
/// <value>
|
||||
/// Is this module enabled?
|
||||
/// </value>
|
||||
|
@ -61,9 +66,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
|
|||
"InstantMessageModule", "InstantMessageModule") !=
|
||||
"InstantMessageModule")
|
||||
return;
|
||||
m_restUrl = config.Configs["Messaging"].GetString("LogURL", String.Empty);
|
||||
}
|
||||
|
||||
m_enabled = true;
|
||||
m_logTimer.AutoReset = false;
|
||||
m_logTimer.Elapsed += LogTimerElapsed;
|
||||
}
|
||||
|
||||
public void AddRegion(Scene scene)
|
||||
|
@ -148,6 +156,9 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
|
|||
{
|
||||
byte dialog = im.dialog;
|
||||
|
||||
if (client != null && dialog == (byte)InstantMessageDialog.MessageFromAgent)
|
||||
LogInstantMesssage(im);
|
||||
|
||||
if (dialog != (byte)InstantMessageDialog.MessageFromAgent
|
||||
&& dialog != (byte)InstantMessageDialog.StartTyping
|
||||
&& dialog != (byte)InstantMessageDialog.StopTyping
|
||||
|
@ -226,5 +237,35 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
|
|||
//
|
||||
OnInstantMessage(null, msg);
|
||||
}
|
||||
|
||||
private void LogInstantMesssage(GridInstantMessage im)
|
||||
{
|
||||
if (m_logData.Count < 20)
|
||||
{
|
||||
// Restart the log write timer
|
||||
m_logTimer.Stop();
|
||||
}
|
||||
if (!m_logTimer.Enabled)
|
||||
m_logTimer.Start();
|
||||
|
||||
lock (m_logData)
|
||||
{
|
||||
m_logData.Add(im);
|
||||
}
|
||||
}
|
||||
|
||||
private void LogTimerElapsed(object source, ElapsedEventArgs e)
|
||||
{
|
||||
lock (m_logData)
|
||||
{
|
||||
if (m_restUrl != String.Empty && m_logData.Count > 0)
|
||||
{
|
||||
bool success = SynchronousRestObjectRequester.MakeRequest<List<GridInstantMessage>, bool>("POST", m_restUrl + "/LogMessages/", m_logData);
|
||||
if (!success)
|
||||
m_log.ErrorFormat("[INSTANT MESSAGE]: Failed to save log data");
|
||||
}
|
||||
m_logData.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue