--- asterisk-1.4-old/asterisk-1.4.27.1-vici/channels/chan_local.c	2009-10-29 11:11:26.000000000 -0700
+++ asterisk-1.4.27.1-vici/channels/chan_local.c	2010-07-12 08:45:36.000000000 -0700
@@ -246,8 +246,41 @@
 static void check_bridge(struct local_pvt *p, int isoutbound)
 {
 	struct ast_channel_monitor *tmp;
-	if (ast_test_flag(p, LOCAL_ALREADY_MASQED) || ast_test_flag(p, LOCAL_NO_OPTIMIZATION) || !p->chan || !p->owner || (p->chan->_bridge != ast_bridged_channel(p->chan)))
+
+	/* Error Variables. Set these and spit out the error after the locks are released, so as not to hold the lock too long. */
+	int chan_bridge = 0;
+	int readq_empty = 0;
+	int chan_bridge_lock = 0;
+	int chan_bridge_shangup = 0;
+	int owner_lock = 0;
+	int owner_shangup = 0;
+	int owner_monitor = 0;
+	int bridge_not_monitor = 0;
+
+
+	if (ast_test_flag(p, LOCAL_ALREADY_MASQED) || ast_test_flag(p, LOCAL_NO_OPTIMIZATION) || !p->chan || !p->owner || (p->chan->_bridge != ast_bridged_channel(p->chan))) {	
+		if ( ast_test_flag(p, LOCAL_ALREADY_MASQED) ) {
+			ast_log(LOG_WARNING, "Unable to bridge Local Channel.  The LOCAL_ALREADY_MASQED flag is set.\n" );
+		}
+			
+		if ( ast_test_flag(p, LOCAL_ALREADY_MASQED) ) {
+			ast_log(LOG_WARNING, "Unable to bridge Local Channel.  The LOCAL_NO_OPTIMIZATION flag is set.\n" );
+		}
+
+		if ( !p->chan ) {
+			ast_log(LOG_WARNING, "Unable to bridge Local Channel.  p->chan exists.\n" );
+		}
+
+		if ( !p->owner ) {
+			ast_log(LOG_WARNING, "Unable to bridge Local Channel.  p->owner exists.\n" );
+		}
+
+		if ( p->chan->_bridge != ast_bridged_channel(p->chan) ) {
+			ast_log(LOG_WARNING, "Unable to bridge Local Channel.  p->chan->_bridge != ast_bridged_channel(p->chan).\n" );
+		}
+
 		return;
+	}
 
 	/* only do the masquerade if we are being called on the outbound channel,
 	   if it has been bridged to another channel and if there are no pending
@@ -272,6 +305,13 @@
 							tmp = p->owner->monitor;
 							p->owner->monitor = p->chan->_bridge->monitor;
 							p->chan->_bridge->monitor = tmp;
+						} else {
+							if (!p->owner->monitor ) {
+								owner_monitor = 1;
+							}
+							if (p->chan->_bridge->monitor) {
+								bridge_not_monitor = 1;
+							}
 						}
 						if (p->chan->audiohooks) {
 							struct ast_audiohook_list *audiohooks_swapper;
@@ -282,11 +322,19 @@
 						ast_app_group_update(p->chan, p->owner);
 						ast_channel_masquerade(p->owner, p->chan->_bridge);
 						ast_set_flag(p, LOCAL_ALREADY_MASQED);
+					} else {
+						owner_shangup = 1;
 					}
 					ast_mutex_unlock(&p->owner->lock);
+				} else {
+					owner_lock = 1;
 				}
 				ast_mutex_unlock(&(p->chan->_bridge)->lock);
+			} else {
+				chan_bridge_shangup = 1;
 			}
+		} else {
+			chan_bridge_lock = 1;
 		}
 	/* We only allow masquerading in one 'direction'... it's important to preserve the state
 	   (group variables, etc.) that live on p->chan->_bridge (and were put there by the dialplan)
@@ -308,7 +356,56 @@
 			ast_mutex_unlock(&(p->owner->_bridge)->lock);
 		}
 #endif
+	} else {
+		if ( !p->chan->_bridge ) {
+			chan_bridge = 1;
+		}
+		if ( !AST_LIST_EMPTY(&p->owner->readq) ) {
+			readq_empty = 1;
+		}
+	}
+
+	/* channel is not outbound or is not bridged */
+	if ( isoutbound ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  It is not the outbound channel.\n" );
+	}
+
+	if ( chan_bridge ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  It is not the bridged channel.\n" );
+	}
+
+	if ( readq_empty ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  Its readq is not empty.\n" );
+	}
+
+	/* unable to get a lock on the bridged channel */
+	if ( chan_bridge_lock ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  Unable to get a lock on the bridged channel.\n" );
+	}
+
+	/* the channel is a soft hangup */
+	if ( chan_bridge_shangup ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  The bridged channel is in soft hangup.\n" );
+	}
+
+	/* unable to get a lock on the owner */
+	if ( owner_lock ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  Unable to get a lock on the owner.\n" );
+	}
+
+	/* the owner is a soft hangup */
+	if ( owner_shangup ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  The owner is in soft hangup.\n" );
+	}
+
+	/* Either owner is not being monitored or the bridge is being monitored */
+	if ( owner_monitor ) {
+		ast_log(LOG_WARNING, "Unable to bridge Local Channel.  Its owner is not being monitored.\n" );
 	}
+
+	if ( bridge_not_monitor ) {
+                ast_log(LOG_WARNING, "Unable to bridge Local Channel.  Its bridge is being monitored.\n" );
+        }
 }
 
 static struct ast_frame  *local_read(struct ast_channel *ast)

