Index: res_jabber.c
===================================================================
--- res_jabber.c	(revision 69009)
+++ res_jabber.c	(working copy)
@@ -683,32 +683,26 @@
 
 	switch (pak->type) {
 	case IKS_PAK_NONE:
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Don't know what to do with you NONE\n");
+		ast_debug(1, "JABBER: I Don't know what to do with you NONE\n");
 		break;
 	case IKS_PAK_MESSAGE:
 		aji_handle_message(client, pak);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Don't know what to do with you MESSAGE\n");
+		ast_debug(1, "JABBER: I Don't know what to do with you MESSAGE\n");
 		break;
 	case IKS_PAK_PRESENCE:
 		aji_handle_presence(client, pak);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Do know how to handle presence!!\n");
+		ast_debug(1, "JABBER: I Do know how to handle presence!!\n");
 		break;
 	case IKS_PAK_S10N:
 		aji_handle_subscribe(client, pak);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Dont know S10N subscribe!!\n");
+		ast_debug(1, "JABBER: I Dont know S10N subscribe!!\n");
 		break;
 	case IKS_PAK_IQ:
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Dont have an IQ!!!\n");
+		ast_debug(1, "JABBER: I Dont have an IQ!!!\n");
 		aji_handle_iq(client, node);
 		break;
 	default:
-		if (option_debug)
-			ast_log(LOG_DEBUG, "JABBER: I Dont know %i\n", pak->type);
+		ast_debug(1, "JABBER: I Dont know %i\n", pak->type);
 		break;
 	}
 	
@@ -1346,8 +1340,7 @@
 		if(gtalk_yuck(pak->x)) /* gtalk should do discover */
 			found->cap->jingle = 1;
 		if(found->cap->jingle && option_debug > 4) {
-			if (option_debug)
-				ast_log(LOG_DEBUG,"Special case for google till they support discover.\n");
+			ast_debug(1,"Special case for google till they support discover.\n");
 		}
 		else {
 			iks *iq, *query;
@@ -1597,8 +1590,7 @@
 		res = iks_recv(client->p, 1);
 
 		if (client->state == AJI_DISCONNECTING) {
-			if (option_debug > 1)
-				ast_log(LOG_DEBUG, "Ending our Jabber client's thread due to a disconnect\n");
+			ast_debug(2, "Ending our Jabber client's thread due to a disconnect\n");
 			pthread_exit(NULL);
 		}
 		client->timeout--;
@@ -2512,8 +2504,7 @@
 	
 	ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {
 		ASTOBJ_RDLOCK(iterator);
-		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "JABBER: Releasing and disconneing client: %s\n", iterator->name);
+		ast_debug(3, "JABBER: Releasing and disconneing client: %s\n", iterator->name);
 		iterator->state = AJI_DISCONNECTING;
 		ast_aji_disconnect(iterator);
 		pthread_join(iterator->thread, NULL);
Index: res_config_sqlite.c
===================================================================
--- res_config_sqlite.c	(revision 69009)
+++ res_config_sqlite.c	(working copy)
@@ -909,7 +909,7 @@
 	}
 
 	query = tmp_str;
-	ast_log(LOG_DEBUG, "SQL query: %s\n", query);
+	ast_debug(1, "SQL query: %s\n", query);
 	args.var = NULL;
 	args.last = NULL;
 
@@ -1074,7 +1074,7 @@
 
 	sqlite_freemem(query);
 	query = tmp_str;
-	ast_log(LOG_DEBUG, "SQL query: %s\n", query);
+	ast_debug(1, "SQL query: %s\n", query);
 	args.cfg = cfg;
 	args.initfield = initfield;
 
@@ -1157,7 +1157,7 @@
 
 	sqlite_freemem(query);
 	query = tmp_str;
-	ast_log(LOG_DEBUG, "SQL query: %s\n", query);
+	ast_debug(1, "SQL query: %s\n", query);
 
 	ast_mutex_lock(&mutex);
 
Index: res_monitor.c
===================================================================
--- res_monitor.c	(revision 69009)
+++ res_monitor.c	(working copy)
@@ -222,9 +222,7 @@
 		/* so we know this call has been monitored in case we need to bill for it or something */
 		pbx_builtin_setvar_helper(chan, "__MONITORED","true");
 	} else {
-		if (option_debug)
-			ast_log(LOG_DEBUG,"Cannot start monitoring %s, already monitored\n",
-						chan->name);
+		ast_debug(1,"Cannot start monitoring %s, already monitored\n", chan->name);
 		res = -1;
 	}
 
@@ -315,8 +313,7 @@
 				snprintf(tmp2,sizeof(tmp2), "( %s& rm -f \"%s/%s-\"* ) &",tmp, dir ,name); /* remove legs when done mixing */
 				ast_copy_string(tmp, tmp2, sizeof(tmp));
 			}
-			if (option_debug)
-				ast_log(LOG_DEBUG,"monitor executing %s\n",tmp);
+			ast_debug(1,"monitor executing %s\n",tmp);
 			if (ast_safe_system(tmp) == -1)
 				ast_log(LOG_WARNING, "Execute of %s failed.\n",tmp);
 		}
Index: res_smdi.c
===================================================================
--- res_smdi.c	(revision 69009)
+++ res_smdi.c	(working copy)
@@ -111,8 +111,7 @@
 	fclose(file);
 
 	ASTOBJ_UNLOCK(iface);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Sent MWI set message for %s on %s\n", mailbox, iface->name);
+	ast_debug(1, "Sent MWI set message for %s on %s\n", mailbox, iface->name);
 	return 0;
 }
 
@@ -143,8 +142,7 @@
 	fclose(file);
 
 	ASTOBJ_UNLOCK(iface);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Sent MWI unset message for %s on %s\n", mailbox, iface->name);
+	ast_debug(1, "Sent MWI unset message for %s on %s\n", mailbox, iface->name);
 	return 0;
 }
 
@@ -413,8 +411,7 @@
 				/* add the message to the message queue */
 				md_msg->timestamp = ast_tvnow();
 				ast_smdi_md_message_push(iface, md_msg);
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Recieved SMDI MD message on %s\n", iface->name);
+				ast_debug(1, "Recieved SMDI MD message on %s\n", iface->name);
 				
 				ASTOBJ_UNREF(md_msg, ast_smdi_md_message_destroy);
 
@@ -457,8 +454,7 @@
 				/* add the message to the message queue */
 				mwi_msg->timestamp = ast_tvnow();
 				ast_smdi_mwi_message_push(iface, mwi_msg);
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Recieved SMDI MWI message on %s\n", iface->name);
+				ast_debug(1, "Recieved SMDI MWI message on %s\n", iface->name);
 				
 				ASTOBJ_UNREF(mwi_msg, ast_smdi_mwi_message_destroy);
 			} else {
Index: res_agi.c
===================================================================
--- res_agi.c	(revision 69009)
+++ res_agi.c	(working copy)
@@ -224,8 +224,7 @@
 	if (!ast_strlen_zero(script))
 		fdprintf(s, "agi_network_script: %s\n", script);
 
-	if (option_debug > 3)
-		ast_log(LOG_DEBUG, "Wow, connected!\n");
+	ast_debug(4, "Wow, connected!\n");
 	fds[0] = s;
 	fds[1] = s;
 	*opid = -1;
@@ -584,8 +583,7 @@
 		return RESULT_SUCCESS;
 	}	
 	vfs = ast_openvstream(chan, argv[2], chan->language);
-	if (vfs && option_debug)
-		ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n");
+	ast_debug(vfs && 1, "Ooh, found a video stream, too\n");
 		
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (sample_offset %ld)\n", argv[2], edigits, sample_offset);
@@ -649,8 +647,7 @@
 		return RESULT_SUCCESS;
 	}
 	vfs = ast_openvstream(chan, argv[2], chan->language);
-	if (vfs && option_debug)
-		ast_log(LOG_DEBUG, "Ooh, found a video stream, too\n");
+	ast_debug(vfs && 1, "Ooh, found a video stream, too\n");
 	
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Playing '%s' (escape_digits=%s) (timeout %d)\n", argv[2], edigits, timeout);
@@ -1860,8 +1857,7 @@
 			/* Idle the channel until we get a command */
 			f = ast_read(c);
 			if (!f) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "%s hungup\n", chan->name);
+				ast_debug(1, "%s hungup\n", chan->name);
 				returnstatus = AGI_RESULT_HANGUP;
 				break;
 			} else {
Index: res_config_pgsql.c
===================================================================
--- res_config_pgsql.c	(revision 69009)
+++ res_config_pgsql.c	(working copy)
@@ -132,11 +132,8 @@
 	if (!(result = PQexec(pgsqlConn, sql))) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
-					PQerrorMessage(pgsqlConn));
-		}
+		ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+		ast_debug(1, "Postgresql RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
 		ast_mutex_unlock(&pgsql_lock);
 		return NULL;
 	} else {
@@ -146,18 +143,15 @@
 			&& result_status != PGRES_NONFATAL_ERROR) {
 			ast_log(LOG_WARNING,
 					"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
+			ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+			ast_debug(1, "Postgresql RealTime: Query Failed because: %s (%s)\n",
 						PQresultErrorMessage(result), PQresStatus(result_status));
-			}
 			ast_mutex_unlock(&pgsql_lock);
 			return NULL;
 		}
 	}
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "1Postgresql RealTime: Result=%p Query: %s\n", result, sql);
+	ast_debug(1, "1Postgresql RealTime: Result=%p Query: %s\n", result, sql);
 
 	if ((num_rows = PQntuples(result)) > 0) {
 		int i = 0;
@@ -165,8 +159,7 @@
 		int numFields = PQnfields(result);
 		char **fieldnames = NULL;
 
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
+		ast_debug(1, "Postgresql RealTime: Found %d rows.\n", num_rows);
 
 		if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
 			ast_mutex_unlock(&pgsql_lock);
@@ -284,11 +277,8 @@
 	if (!(result = PQexec(pgsqlConn, sql))) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
-					PQerrorMessage(pgsqlConn));
-		}
+		ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+		ast_debug(1, "Postgresql RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
 		ast_mutex_unlock(&pgsql_lock);
 		return NULL;
 	} else {
@@ -298,18 +288,15 @@
 			&& result_status != PGRES_NONFATAL_ERROR) {
 			ast_log(LOG_WARNING,
 					"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
+			ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+			ast_debug(1, "Postgresql RealTime: Query Failed because: %s (%s)\n",
 						PQresultErrorMessage(result), PQresStatus(result_status));
-			}
 			ast_mutex_unlock(&pgsql_lock);
 			return NULL;
 		}
 	}
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "2Postgresql RealTime: Result=%p Query: %s\n", result, sql);
+	ast_debug(1, "2Postgresql RealTime: Result=%p Query: %s\n", result, sql);
 
 	if ((num_rows = PQntuples(result)) > 0) {
 		int numFields = PQnfields(result);
@@ -317,8 +304,7 @@
 		int rowIndex = 0;
 		char **fieldnames = NULL;
 
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Found %d rows.\n", num_rows);
+		ast_debug(1, "Postgresql RealTime: Found %d rows.\n", num_rows);
 
 		if (!(fieldnames = ast_calloc(1, numFields * sizeof(char *)))) {
 			ast_mutex_unlock(&pgsql_lock);
@@ -398,8 +384,7 @@
 	snprintf(sql + strlen(sql), sizeof(sql) - strlen(sql), " WHERE %s = '%s'", keyfield,
 			 lookup);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Postgresql RealTime: Update SQL: %s\n", sql);
+	ast_debug(1, "Postgresql RealTime: Update SQL: %s\n", sql);
 
 	/* We now have our complete statement; Lets connect to the server and execute it. */
 	ast_mutex_lock(&pgsql_lock);
@@ -411,11 +396,8 @@
 	if (!(result = PQexec(pgsqlConn, sql))) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
-					PQerrorMessage(pgsqlConn));
-		}
+		ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+		ast_debug(1, "Postgresql RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
 		ast_mutex_unlock(&pgsql_lock);
 		return -1;
 	} else {
@@ -425,11 +407,9 @@
 			&& result_status != PGRES_NONFATAL_ERROR) {
 			ast_log(LOG_WARNING,
 					"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
+			ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+			ast_debug(1, "Postgresql RealTime: Query Failed because: %s (%s)\n",
 						PQresultErrorMessage(result), PQresStatus(result_status));
-			}
 			ast_mutex_unlock(&pgsql_lock);
 			return -1;
 		}
@@ -438,9 +418,7 @@
 	numrows = atoi(PQcmdTuples(result));
 	ast_mutex_unlock(&pgsql_lock);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Postgresql RealTime: Updated %d rows on table: %s\n", numrows,
-				table);
+	ast_debug(1, "Postgresql RealTime: Updated %d rows on table: %s\n", numrows, table);
 
 	/* From http://dev.pgsql.com/doc/pgsql/en/pgsql-affected-rows.html
 	 * An integer greater than zero indicates the number of rows affected
@@ -479,8 +457,7 @@
 	ast_build_string(&sql, &sqlleft, "WHERE filename='%s' and commented=0", file);
 	ast_build_string(&sql, &sqlleft, "ORDER BY cat_metric DESC, var_metric ASC, category, var_name ");
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Postgresql RealTime: Static SQL: %s\n", sqlbuf);
+	ast_debug(1, "Postgresql RealTime: Static SQL: %s\n", sqlbuf);
 
 	/* We now have our complete statement; Lets connect to the server and execute it. */
 	ast_mutex_lock(&pgsql_lock);
@@ -492,11 +469,8 @@
 	if (!(result = PQexec(pgsqlConn, sqlbuf))) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s\n",
-					PQerrorMessage(pgsqlConn));
-		}
+		ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+		ast_debug(1, "Postgresql RealTime: Query Failed because: %s\n", PQerrorMessage(pgsqlConn));
 		ast_mutex_unlock(&pgsql_lock);
 		return NULL;
 	} else {
@@ -506,11 +480,9 @@
 			&& result_status != PGRES_NONFATAL_ERROR) {
 			ast_log(LOG_WARNING,
 					"Postgresql RealTime: Failed to query database. Check debug for more info.\n");
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query: %s\n", sql);
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Query Failed because: %s (%s)\n",
+			ast_debug(1, "Postgresql RealTime: Query: %s\n", sql);
+			ast_debug(1, "Postgresql RealTime: Query Failed because: %s (%s)\n",
 						PQresultErrorMessage(result), PQresStatus(result_status));
-			}
 			ast_mutex_unlock(&pgsql_lock);
 			return NULL;
 		}
@@ -519,8 +491,7 @@
 	if ((num_rows = PQntuples(result)) > 0) {
 		int rowIndex = 0;
 
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Found %ld rows.\n", num_rows);
+		ast_debug(1, "Postgresql RealTime: Found %ld rows.\n", num_rows);
 
 		for (rowIndex = 0; rowIndex < num_rows; rowIndex++) {
 			char *field_category = PQgetvalue(result, rowIndex, 0);
@@ -576,9 +547,7 @@
 	if (!pgsql_reconnect(NULL)) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Couldn't establish connection. Check debug.\n");
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
-					PQerrorMessage(pgsqlConn));
+		ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn));
 	}
 
 	ast_config_engine_register(&pgsql_engine);
@@ -629,9 +598,7 @@
 	if (!pgsql_reconnect(NULL)) {
 		ast_log(LOG_WARNING,
 				"Postgresql RealTime: Couldn't establish connection. Check debug.\n");
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
-					PQerrorMessage(pgsqlConn));
+		ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQerrorMessage(pgsqlConn));
 	}
 
 	ast_verbose(VERBOSE_PREFIX_2 "Postgresql RealTime reloaded.\n");
@@ -704,14 +671,14 @@
 
 	if (option_debug) {
 		if (dbhost) {
-			ast_log(LOG_DEBUG, "Postgresql RealTime Host: %s\n", dbhost);
-			ast_log(LOG_DEBUG, "Postgresql RealTime Port: %i\n", dbport);
+			ast_debug(1, "Postgresql RealTime Host: %s\n", dbhost);
+			ast_debug(1, "Postgresql RealTime Port: %i\n", dbport);
 		} else {
-			ast_log(LOG_DEBUG, "Postgresql RealTime Socket: %s\n", dbsock);
+			ast_debug(1, "Postgresql RealTime Socket: %s\n", dbsock);
 		}
-		ast_log(LOG_DEBUG, "Postgresql RealTime User: %s\n", dbuser);
-		ast_log(LOG_DEBUG, "Postgresql RealTime Password: %s\n", dbpass);
-		ast_log(LOG_DEBUG, "Postgresql RealTime DBName: %s\n", dbname);
+		ast_debug(1, "Postgresql RealTime User: %s\n", dbuser);
+		ast_debug(1, "Postgresql RealTime Password: %s\n", dbpass);
+		ast_debug(1, "Postgresql RealTime DBName: %s\n", dbname);
 	}
 
 	return 1;
@@ -742,32 +709,25 @@
 		
 		sprintf(connInfo, "host=%s port=%d dbname=%s user=%s password=%s",
 					dbhost, dbport, my_database, dbuser, dbpass);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
+		ast_debug(1, "%u connInfo=%s\n", size, connInfo);
 		pgsqlConn = PQconnectdb(connInfo);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "%u connInfo=%s\n", size, connInfo);
+		ast_debug(1, "%u connInfo=%s\n", size, connInfo);
 		ast_free(connInfo);
 		connInfo = NULL;
-		if (option_debug)
-			ast_log(LOG_DEBUG, "pgsqlConn=%p\n", pgsqlConn);
+		ast_debug(1, "pgsqlConn=%p\n", pgsqlConn);
 		if (pgsqlConn && PQstatus(pgsqlConn) == CONNECTION_OK) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Successfully connected to database.\n");
+			ast_debug(1, "Postgresql RealTime: Successfully connected to database.\n");
 			connect_time = time(NULL);
 			return 1;
 		} else {
 			ast_log(LOG_ERROR,
 					"Postgresql RealTime: Failed to connect database server %s on %s. Check debug for more info.\n",
 					dbname, dbhost);
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Postgresql RealTime: Cannot Connect: %s\n",
-						PQresultErrorMessage(NULL));
+			ast_debug(1, "Postgresql RealTime: Cannot Connect: %s\n", PQresultErrorMessage(NULL));
 			return 0;
 		}
 	} else {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Postgresql RealTime: Everything is fine.\n");
+		ast_debug(1, "Postgresql RealTime: Everything is fine.\n");
 		return 1;
 	}
 }
Index: res_features.c
===================================================================
--- res_features.c	(revision 69009)
+++ res_features.c	(working copy)
@@ -324,8 +324,7 @@
 /*! \brief Notify metermaids that we've changed an extension */
 static void notify_metermaids(const char *exten, char *context)
 {
-	if (option_debug > 3)
-		ast_log(LOG_DEBUG, "Notification of state change to metermaids %s@%s\n", exten, context);
+	ast_debug(4, "Notification of state change to metermaids %s@%s\n", exten, context);
 
 	/* Send notification to devicestate subsystem */
 	ast_device_state_changed("park:%s@%s", exten, context);
@@ -343,8 +342,7 @@
 	if (!context)
 		return res;
 	
-	if (option_debug > 3)
-		ast_log(LOG_DEBUG, "Checking state of exten %s in context %s\n", exten, context);
+	ast_debug(4, "Checking state of exten %s in context %s\n", exten, context);
 
 	res = ast_exists_extension(NULL, context, exten, 1, NULL);
 
@@ -807,8 +805,7 @@
 	struct ast_frame *f;
 	int l;
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Executing Attended Transfer %s, %s (sense=%d) \n", chan->name, peer->name, sense);
+	ast_debug(1, "Executing Attended Transfer %s, %s (sense=%d) \n", chan->name, peer->name, sense);
 	set_peers(&transferer, &transferee, peer, chan, sense);
         transferer_real_context = real_ctx(transferer, transferee);
 	/* Start autoservice on chan while we talk to the originator */
@@ -957,11 +954,9 @@
 				}
 				if (!newchan) {
 					/* Transfer failed, sleeping */
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Sleeping for %d ms before callback.\n", atxferloopdelay);
+					ast_debug(1, "Sleeping for %d ms before callback.\n", atxferloopdelay);
 					ast_safe_sleep(transferee, atxferloopdelay);
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Trying to callback...\n");
+					ast_debug(1, "Trying to callback...\n");
 					newchan = ast_feature_request_and_dial(transferee, NULL, "Local", ast_best_codec(transferee->nativeformats),
 						callbackto, atxfernoanswertimeout, &outstate, transferee->cid.cid_num, transferee->cid.cid_name, 0);
 				}
@@ -1329,8 +1324,7 @@
 		ast_copy_flags(&features, &(config->features_caller), AST_FLAGS_ALL);
 	else
 		ast_copy_flags(&features, &(config->features_callee), AST_FLAGS_ALL);
-	if (option_debug > 2)
-		ast_log(LOG_DEBUG, "Feature interpret: chan=%s, peer=%s, sense=%d, features=%d\n", chan->name, peer->name, sense, features.flags);
+	ast_debug(3, "Feature interpret: chan=%s, peer=%s, sense=%d, features=%d\n", chan->name, peer->name, sense, features.flags);
 
 	ast_rwlock_rdlock(&features_lock);
 	for (x = 0; x < FEATURES_COUNT; x++) {
@@ -1693,8 +1687,7 @@
 				   activated, but that's no excuse to keep things going 
 				   indefinitely! */
 				if (backup_config.feature_timer && ((backup_config.feature_timer -= diff) <= 0)) {
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Timed out, realtime this time!\n");
+					ast_debug(1, "Timed out, realtime this time!\n");
 					config->feature_timer = 0;
 					who = chan;
 					if (f)
@@ -1704,8 +1697,7 @@
 				} else if (config->feature_timer <= 0) {
 					/* Not *really* out of time, just out of time for
 					   digits to come in for features. */
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Timed out for feature!\n");
+					ast_debug(1, "Timed out for feature!\n");
 					if (!ast_strlen_zero(peer_featurecode)) {
 						ast_dtmf_stream(chan, peer, peer_featurecode, 0);
 						memset(peer_featurecode, 0, sizeof(peer_featurecode));
@@ -1827,8 +1819,7 @@
 				}
 				config->start_time = ast_tvnow();
 				config->feature_timer = featuredigittimeout;
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Set time limit to %ld\n", config->feature_timer);
+				ast_debug(1, "Set time limit to %ld\n", config->feature_timer);
 			}
 		}
 		if (f)
@@ -2032,8 +2023,7 @@
 						/*! \todo XXX Maybe we could do something with packets, like dial "0" for operator or something XXX */
 						ast_frfree(f);
 						if (pu->moh_trys < 3 && !chan->generatordata) {
-							if (option_debug)
-								ast_log(LOG_DEBUG, "MOH on parked call stopped by outside source.  Restarting.\n");
+							ast_debug(1, "MOH on parked call stopped by outside source.  Restarting.\n");
 							ast_indicate_data(chan, AST_CONTROL_HOLD, 
 								S_OR(parkmohclass, NULL),
 								!ast_strlen_zero(parkmohclass) ? strlen(parkmohclass) + 1 : 0);
@@ -2573,8 +2563,7 @@
 		ast_channel_unlock(cur);
 	}
 	if (cur) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
+		ast_debug(1, "Call pickup on chan '%s' by '%s'\n",cur->name, chan->name);
 		res = ast_answer(chan);
 		if (res)
 			ast_log(LOG_WARNING, "Unable to answer '%s'\n", chan->name);
@@ -2586,8 +2575,7 @@
 			ast_log(LOG_WARNING, "Unable to masquerade '%s' into '%s'\n", chan->name, cur->name);		/* Done */
 		ast_channel_unlock(cur);
 	} else	{
-		if (option_debug)
-			ast_log(LOG_DEBUG, "No call pickup possible...\n");
+		ast_debug(1, "No call pickup possible...\n");
 	}
 	return res;
 }
@@ -2880,8 +2868,7 @@
 	if (!ast_strlen_zero(old_parking_con) && (con = ast_context_find(old_parking_con)))	{
 		if(ast_context_remove_extension2(con, old_parking_ext, 1, registrar))
 				notify_metermaids(old_parking_ext, old_parking_con);
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Removed old parking extension %s@%s\n", old_parking_ext, old_parking_con);
+		ast_debug(1, "Removed old parking extension %s@%s\n", old_parking_ext, old_parking_con);
 	}
 	
 	if (!(con = ast_context_find(parking_con)) && !(con = ast_context_create(NULL, parking_con, registrar))) {
@@ -3023,20 +3010,17 @@
 	/* the bridge has ended, set BRIDGERESULT to SUCCESS. If the other channel has not been hung up, return it to the PBX */
 	pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "SUCCESS");
 	if (!ast_check_hangup(final_dest_chan)) {
-		if (option_debug) {
-			ast_log(LOG_DEBUG, "starting new PBX in %s,%s,%d for chan %s\n", 
+		ast_debug(1, "starting new PBX in %s,%s,%d for chan %s\n", 
 			final_dest_chan->context, final_dest_chan->exten, 
 			final_dest_chan->priority, final_dest_chan->name);
-		}
 
 		if (ast_pbx_start(final_dest_chan) != AST_PBX_SUCCESS) {
 			ast_log(LOG_WARNING, "FAILED continuing PBX on dest chan %s\n", final_dest_chan->name);
 			ast_hangup(final_dest_chan);
-		} else if (option_debug)
-			ast_log(LOG_DEBUG, "SUCCESS continuing PBX on chan %s\n", final_dest_chan->name);
+		} else
+			ast_debug(1, "SUCCESS continuing PBX on chan %s\n", final_dest_chan->name);
 	} else {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "hangup chan %s since the other endpoint has hung up\n", final_dest_chan->name);
+		ast_debug(1, "hangup chan %s since the other endpoint has hung up\n", final_dest_chan->name);
 		ast_hangup(final_dest_chan);
 	}
 
Index: res_crypto.c
===================================================================
--- res_crypto.c	(revision 69009)
+++ res_crypto.c	(working copy)
@@ -258,8 +258,7 @@
 			key->ktype &= ~KEY_NEEDS_PASSCODE;
 			if (option_verbose > 2)
 				ast_verbose(VERBOSE_PREFIX_3 "Loaded %s key '%s'\n", key->ktype == AST_KEY_PUBLIC ? "PUBLIC" : "PRIVATE", key->name);
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Key '%s' loaded OK\n", key->name);
+			ast_debug(1, "Key '%s' loaded OK\n", key->name);
 			key->delme = 0;
 		} else
 			ast_log(LOG_NOTICE, "Key '%s' is not expected size.\n", key->name);
@@ -436,8 +435,7 @@
 	res = RSA_verify(NID_sha1, digest, sizeof(digest), (unsigned char *)dsig, 128, key->rsa);
 	
 	if (!res) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Key failed verification: %s\n", key->name);
+		ast_debug(1, "Key failed verification: %s\n", key->name);
 		return -1;
 	}
 	/* Pass */
@@ -491,8 +489,7 @@
 	while(key) {
 		nkey = key->next;
 		if (key->delme) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Deleting key %s type %d\n", key->name, key->ktype);
+			ast_debug(1, "Deleting key %s type %d\n", key->name, key->ktype);
 			/* Do the delete */
 			if (last)
 				last->next = nkey;
Index: res_adsi.c
===================================================================
--- res_adsi.c	(revision 69009)
+++ res_adsi.c	(working copy)
@@ -232,8 +232,7 @@
 			for(;;) {
 				if (((res = ast_waitfor(chan, waittime)) < 1)) {
 					/* Didn't get back DTMF A in time */
-					if (option_debug)
-						ast_log(LOG_DEBUG, "No ADSI CPE detected (%d)\n", res);
+					ast_debug(1, "No ADSI CPE detected (%d)\n", res);
 					if (!chan->adsicpe)
 						chan->adsicpe = AST_ADSI_UNAVAILABLE;
 					errno = ENOSYS;
@@ -242,8 +241,7 @@
 				waittime = res;
 				f = ast_read(chan);
 				if (!f) {
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Hangup in ADSI\n");
+					ast_debug(1, "Hangup in ADSI\n");
 					return -1;
 				}
 				if (f->frametype == AST_FRAME_DTMF) {
@@ -254,8 +252,7 @@
 						break;
 					} else {
 						if (f->subclass == 'D')  {
-							if (option_debug)
-								ast_log(LOG_DEBUG, "Off-hook capable CPE only, not ADSI\n");
+							ast_debug(1, "Off-hook capable CPE only, not ADSI\n");
 						} else
 							ast_log(LOG_WARNING, "Unknown ADSI response '%c'\n", f->subclass);
 						if (!chan->adsicpe)
@@ -267,11 +264,9 @@
 				ast_frfree(f);
 			}
 
-			if (option_debug)
-				ast_log(LOG_DEBUG, "ADSI Compatible CPE Detected\n");
+			ast_debug(1, "ADSI Compatible CPE Detected\n");
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Already in data mode\n");
+			ast_debug(1, "Already in data mode\n");
 		}
 
 		x = 0;
@@ -285,9 +280,7 @@
 				ast_log(LOG_WARNING, "Failed to generate ADSI message %d on channel %s\n", x + 1, chan->name);
 				return -1;
 			}
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Message %d, of %d input bytes, %d output bytes\n", 
-						x + 1, msglen[x], res);
+			ast_debug(1, "Message %d, of %d input bytes, %d output bytes\n", x + 1, msglen[x], res);
 			pos += res; 
 			x++;
 		}
@@ -300,8 +293,7 @@
 		if (res)
 			return -1;
 
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Sent total spill of %d bytes\n", pos);
+		ast_debug(1, "Sent total spill of %d bytes\n", pos);
 
 		memset(ack, 0, sizeof(ack));
 		/* Get real result */
@@ -310,15 +302,12 @@
 		if (res < 0)
 			return -1;
 		if (ack[0] == 'D') {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Acked up to message %d\n", atoi(ack + 1));
-			start += atoi(ack + 1);
+			ast_debug(1, "Acked up to message %d\n", atoi(ack + 1)); start += atoi(ack + 1);
 			if (start >= x)
 				break;
 			else {
 				retries++;
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Retransmitting (%d), from %d\n", retries, start + 1);
+				ast_debug(1, "Retransmitting (%d), from %d\n", retries, start + 1);
 			}
 		} else {
 			retries++;
@@ -349,8 +338,7 @@
 		return -1;
 	if (ack[0] == 'B')
 		return 0;
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Download was denied by CPE\n");
+	ast_debug(1, "Download was denied by CPE\n");
 	return -1;
 }
 
@@ -385,15 +373,13 @@
 
 	for (x=0;x<msglen;x+=(msg[x+1]+2)) {
 		if (msg[x] == ADSI_SWITCH_TO_DATA) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Switch to data is sent!\n");
+			ast_debug(1, "Switch to data is sent!\n");
 			waitforswitch++;
 			newdatamode = ADSI_FLAG_DATAMODE;
 		}
 		
 		if (msg[x] == ADSI_SWITCH_TO_VOICE) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Switch to voice is sent!\n");
+			ast_debug(1, "Switch to voice is sent!\n");
 			waitforswitch++;
 			newdatamode = 0;
 		}
@@ -426,12 +412,10 @@
 	res = __adsi_transmit_messages(chan, msgs, msglens, msgtypes);
 
 	if (dowait) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Wait for switch is '%d'\n", waitforswitch);
+		ast_debug(1, "Wait for switch is '%d'\n", waitforswitch);
 		while (waitforswitch-- && ((res = ast_waitfordigit(chan, 1000)) > 0)) { 
 			res = 0; 
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Waiting for 'B'...\n");
+			ast_debug(1, "Waiting for 'B'...\n");
 		}
 	}
 	
@@ -1014,17 +998,14 @@
 		if (res < 0)
 			return -1;
 		if (res) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "No response from CPE about version.  Assuming not there.\n");
+			ast_debug(1, "No response from CPE about version.  Assuming not there.\n");
 			return 0;
 		}
 		if (!strcmp(resp, "B")) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "CPE has script '%s' version %d already loaded\n", app, ver);
+			ast_debug(1, "CPE has script '%s' version %d already loaded\n", app, ver);
 			return 1;
 		} else if (!strcmp(resp, "A")) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "CPE hasn't script '%s' version %d already loaded\n", app, ver);
+			ast_debug(1, "CPE hasn't script '%s' version %d already loaded\n", app, ver);
 		} else {
 			ast_log(LOG_WARNING, "Unexpected CPE response to script query: %s\n", resp);
 		}
Index: res_musiconhold.c
===================================================================
--- res_musiconhold.c	(revision 69009)
+++ res_musiconhold.c	(working copy)
@@ -250,8 +250,7 @@
 		return -1;
 	}
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);
+	ast_debug(LOG_DEBUG, "%s Opened file %d '%s'\n", chan->name, state->pos, state->class->filearray[state->pos]);
 
 	if (state->samples)
 		ast_seekstream(chan->stream, state->samples, SEEK_SET);
@@ -583,8 +582,7 @@
 					class->pid = 0;
 				}
 			} else {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, len);
+				ast_debug(1, "Read %d bytes of audio while expecting %d\n", res2, len);
 			}
 			continue;
 		}
@@ -593,8 +591,7 @@
 		AST_RWLIST_TRAVERSE(&class->members, moh, list) {
 			/* Write data */
 			if ((res = write(moh->pipe[1], sbuf, res2)) != res2) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Only wrote %d of %d bytes to pipe\n", res, res2);
+				ast_debug(1, "Only wrote %d of %d bytes to pipe\n", res, res2);
 			}
 		}
 		AST_RWLIST_UNLOCK(&mohclasses);
@@ -875,8 +872,7 @@
 	AST_RWLIST_WRLOCK(&mohclasses);
 	if (get_mohbyname(moh->name)) {
 		if (reload) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Music on Hold class '%s' left alone from initial load.\n", moh->name);
+			ast_debug(1, "Music on Hold class '%s' left alone from initial load.\n", moh->name);
 		} else {
 			ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name);
 		}
@@ -1100,8 +1096,7 @@
 	AST_RWLIST_WRLOCK(&mohclasses);
 	while ((moh = AST_RWLIST_REMOVE_HEAD(&mohclasses, list))) {
 		if (moh->pid > 1) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "killing %d!\n", moh->pid);
+			ast_debug(1, "killing %d!\n", moh->pid);
 			stime = time(NULL) + 2;
 			pid = moh->pid;
 			moh->pid = 0;
@@ -1115,8 +1110,7 @@
 			kill(pid, SIGKILL);
 			while ((ast_wait_for_input(moh->srcfd, 100) > 0) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime)
 				tbytes = tbytes + bytes;
-			if (option_debug)
-				ast_log(LOG_DEBUG, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes);
+			ast_debug(1, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes);
 			close(moh->srcfd);
 		}
 		ast_moh_free_class(&moh);
