From 08b6b3bb48fb9872fda04c06e7ba82b25c811ab6 Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 17 Jan 2012 17:36:26 +0100 Subject: Add some logging --- .../Avatar/InstantMessage/InstantMessageModule.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage') diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs index 1af4d68..727f1c9 100644 --- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs +++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/InstantMessageModule.cs @@ -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 m_logData = new List(); + private string m_restUrl; + /// /// Is this module enabled? /// @@ -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, bool>("POST", m_restUrl + "/LogMessages/", m_logData); + if (!success) + m_log.ErrorFormat("[INSTANT MESSAGE]: Failed to save log data"); + } + m_logData.Clear(); + } + } } } -- cgit v1.1