Add "debug attachments" console command to allow highly verbose attachment logging to be switched on and off.

Default is off.
user_profiles
Justin Clark-Casey (justincc) 2013-03-28 23:09:35 +00:00
parent feffc8081d
commit 2b142f2f9e
1 changed files with 109 additions and 61 deletions

View File

@ -49,6 +49,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
#region INonSharedRegionModule
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public int DebugLevel { get; set; }
private Scene m_scene;
private IInventoryAccessModule m_invAccessModule;
@ -79,11 +81,37 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
m_scene.EventManager.OnNewClient += SubscribeToClientEvents;
m_scene.EventManager.OnStartScript += (localID, itemID) => HandleScriptStateChange(localID, true);
m_scene.EventManager.OnStopScript += (localID, itemID) => HandleScriptStateChange(localID, false);
MainConsole.Instance.Commands.AddCommand(
"Debug",
false,
"debug attachments",
"debug attachments [0|1]",
"Turn on attachments debugging\n"
+ " <= 0 - turns off debugging\n"
+ " >= 1 - turns on attachment message logging\n",
HandleDebugAttachments);
}
// TODO: Should probably be subscribing to CloseClient too, but this doesn't yet give us IClientAPI
}
private void HandleDebugAttachments(string module, string[] args)
{
int debugLevel;
if (!(args.Length == 3 && int.TryParse(args[2], out debugLevel)))
{
MainConsole.Instance.OutputFormat("Usage: debug attachments [0|1]");
}
else
{
DebugLevel = debugLevel;
MainConsole.Instance.OutputFormat(
"Set event queue debug level to {0} in {1}", DebugLevel, m_scene.Name);
}
}
/// <summary>
/// Listen for client triggered running state changes so that we can persist the script's object if necessary.
/// </summary>
@ -196,14 +224,16 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (sp.GetAttachments().Count > 0)
{
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments",
// m_scene.Name, sp.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Not doing simulator-side attachment rez for {0} in {1} as their viewer has already rezzed attachments",
m_scene.Name, sp.Name);
return;
}
// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
if (DebugLevel > 0)
m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing any attachments for {0} from simulator-side", sp.Name);
List<AvatarAttachment> attachments = sp.Appearance.GetAttachments();
foreach (AvatarAttachment attach in attachments)
@ -245,7 +275,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
// m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
if (DebugLevel > 0)
m_log.DebugFormat("[ATTACHMENTS MODULE]: Saving changed attachments for {0}", sp.Name);
List<SceneObjectGroup> attachments = sp.GetAttachments();
@ -278,9 +309,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
// m_scene.RegionInfo.RegionName, sp.Name, silent);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Deleting attachments from scene {0} for {1}, silent = {2}",
m_scene.RegionInfo.RegionName, sp.Name, silent);
foreach (SceneObjectGroup sop in sp.GetAttachments())
{
@ -313,9 +345,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{
if (group.GetSittingAvatarsCount() != 0)
{
// m_log.WarnFormat(
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it",
// group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount());
if (DebugLevel > 0)
m_log.WarnFormat(
"[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since {4} avatars are still sitting on it",
group.Name, group.LocalId, sp.Name, attachmentPt, group.GetSittingAvatarsCount());
return false;
}
@ -351,9 +384,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (attachments.Contains(group))
{
// m_log.WarnFormat(
// "[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
// group.Name, group.LocalId, sp.Name, AttachmentPt);
if (DebugLevel > 0)
m_log.WarnFormat(
"[ATTACHMENTS MODULE]: Ignoring request to attach {0} {1} to {2} on {3} since it's already attached",
group.Name, group.LocalId, sp.Name, attachmentPt);
return false;
}
@ -418,9 +452,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return null;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}",
// (AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: RezSingleAttachmentFromInventory to point {0} from item {1} for {2} in {3}",
(AttachmentPoint)AttachmentPt, itemID, sp.Name, m_scene.Name);
bool append = (AttachmentPt & 0x80) != 0;
AttachmentPt &= 0x7f;
@ -444,9 +479,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// if (sp.Appearance.GetAttachmentForItem(itemID) != null)
if (alreadyOn)
{
// m_log.WarnFormat(
// "[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn",
// sp.Name, itemID, AttachmentPt);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Ignoring request by {0} to wear item {1} at {2} since it is already worn",
sp.Name, itemID, AttachmentPt);
return null;
}
@ -459,7 +495,8 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
// m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name);
if (DebugLevel > 0)
m_log.DebugFormat("[ATTACHMENTS MODULE]: Rezzing multiple attachments from inventory for {0}", sp.Name);
foreach (KeyValuePair<UUID, uint> rez in rezlist)
{
@ -477,9 +514,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
// sp.UUID, soLocalId);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: DetachSingleAttachmentToGround() for {0}, object {1}",
sp.UUID, soLocalId);
SceneObjectGroup so = m_scene.GetGroupByPrim(soLocalId);
@ -495,9 +533,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (inventoryID == UUID.Zero)
return;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
// so.Name, so.LocalId, inventoryID);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: In DetachSingleAttachmentToGround(), object is {0} {1}, associated item is {2}",
so.Name, so.LocalId, inventoryID);
lock (sp.AttachmentsSyncLock)
{
@ -552,9 +591,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return;
}
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Detaching object {0} {1} (FromItemID {2}) for {3} in {4}",
// so.Name, so.LocalId, so.FromItemID, sp.Name, m_scene.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Detaching object {0} {1} (FromItemID {2}) for {3} in {4}",
so.Name, so.LocalId, so.FromItemID, sp.Name, m_scene.Name);
// Scripts MUST be snapshotted before the object is
// removed from the scene because doing otherwise will
@ -680,12 +720,12 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
grp.HasGroupChanged = false; // Prevent it being saved over and over
}
// else
// {
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
// grp.UUID, grp.AttachmentPoint);
// }
else if (DebugLevel > 0)
{
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Don't need to update asset for unchanged attachment {0}, attachpoint {1}",
grp.UUID, grp.AttachmentPoint);
}
}
/// <summary>
@ -703,9 +743,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private void AttachToAgent(
IScenePresence sp, SceneObjectGroup so, uint attachmentpoint, Vector3 attachOffset, bool silent)
{
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}",
// so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Adding attachment {0} to avatar {1} in pt {2} pos {3} {4}",
so.Name, sp.Name, attachmentpoint, attachOffset, so.RootPart.AttachedPos);
so.DetachFromBackup();
@ -730,9 +771,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
{
if (so.HasPrivateAttachmentPoint)
{
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}",
// so.Name, sp.Name, so.AttachmentPoint);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Killing private HUD {0} for avatars other than {1} at attachment point {2}",
so.Name, sp.Name, so.AttachmentPoint);
// As this scene object can now only be seen by the attaching avatar, tell everybody else in the
// scene that it's no longer in their awareness.
@ -766,9 +808,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (m_invAccessModule == null)
return null;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
// grp.Name, grp.LocalId, remoteClient.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Called AddSceneObjectAsAttachment for object {0} {1} for {2}",
grp.Name, grp.LocalId, sp.Name);
InventoryItemBase newItem
= m_invAccessModule.CopyToInventory(
@ -877,9 +920,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
return null;
}
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
// objatt.Name, sp.Name, attachmentPt, m_scene.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Rezzed single object {0} for attachment to {1} on point {2} in {3}",
objatt.Name, sp.Name, attachmentPt, m_scene.Name);
// HasGroupChanged is being set from within RezObject. Ideally it would be set by the caller.
objatt.HasGroupChanged = false;
@ -949,9 +993,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
bool changed = sp.Appearance.SetAttachment((int)AttachmentPt | attFlag, itemID, item.AssetID);
if (changed && m_scene.AvatarFactory != null)
{
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
// sp.Name, att.Name, AttachmentPt);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Queueing appearance save for {0}, attachment {1} point {2} in ShowAttachInUserInventory()",
sp.Name, att.Name, AttachmentPt);
m_scene.AvatarFactory.QueueAppearanceSave(sp.UUID);
}
@ -966,9 +1011,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
if (!Enabled)
return null;
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
// (AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Rezzing attachment to point {0} from item {1} for {2}",
(AttachmentPoint)AttachmentPt, itemID, remoteClient.Name);
ScenePresence sp = m_scene.GetScenePresence(remoteClient.AgentId);
@ -999,9 +1045,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
private void Client_OnObjectAttach(IClientAPI remoteClient, uint objectLocalID, uint AttachmentPt, bool silent)
{
// m_log.DebugFormat(
// "[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
// objectLocalID, remoteClient.Name, AttachmentPt, silent);
if (DebugLevel > 0)
m_log.DebugFormat(
"[ATTACHMENTS MODULE]: Attaching object local id {0} to {1} point {2} from ground (silent = {3})",
objectLocalID, remoteClient.Name, AttachmentPt, silent);
if (!Enabled)
return;
@ -1036,9 +1083,10 @@ namespace OpenSim.Region.CoreModules.Avatar.Attachments
// Calls attach with a Zero position
if (AttachObject(sp, part.ParentGroup, AttachmentPt, false, false, append))
{
// m_log.Debug(
// "[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
// + ", AttachmentPoint: " + AttachmentPt);
if (DebugLevel > 0)
m_log.Debug(
"[ATTACHMENTS MODULE]: Saving avatar attachment. AgentID: " + remoteClient.AgentId
+ ", AttachmentPoint: " + AttachmentPt);
// Save avatar attachment information
m_scene.EventManager.TriggerOnAttach(objectLocalID, part.ParentGroup.FromItemID, remoteClient.AgentId);