diff --git a/apps/app_meetme.c b/apps/app_meetme.c
index 1a8cb2e280eb3943a3dd5937d537fac3b49734c3..513cd78212e9868ce539f4fc14a3d70feb593d30 100644
--- a/apps/app_meetme.c
+++ b/apps/app_meetme.c
@@ -2165,8 +2165,8 @@ static int conf_run(struct ast_channel *chan, struct ast_conference *conf, int c
 					}
 				} else if (f->frametype == AST_FRAME_NULL) {
 					/* Ignore NULL frames. It is perfectly normal to get these if the person is muted. */
-				} else if (option_debug) {
-					ast_log(LOG_DEBUG,
+				} else {
+					ast_debug(1, 
 						"Got unrecognized frame on channel %s, f->frametype=%d,f->subclass=%d\n",
 						chan->name, f->frametype, f->subclass);
 				}
diff --git a/apps/app_minivm.c b/apps/app_minivm.c
index 73ef61b289b07dec9bb4dc23ed3f47f7d0d88104..728e66b5c43453df4de8afffda20c0143c8861af 100644
--- a/apps/app_minivm.c
+++ b/apps/app_minivm.c
@@ -941,8 +941,7 @@ static int sendmail(struct minivm_template *template, struct minivm_account *vmu
 		snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, filename, format, newtmp, format);
 		ast_safe_system(tmpcmd);
 		finalfilename = newtmp;
-		if (option_debug > 2)
-			ast_log	(LOG_DEBUG, "-- VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
+		ast_debug(3, "-- VOLGAIN: Stored at: %s.%s - Level: %.4f - Mailbox: %s\n", filename, format, vmu->volgain, vmu->username);
 	} else {
 		finalfilename = ast_strdupa(filename);
 	}
diff --git a/apps/app_rpt.c b/apps/app_rpt.c
index 40880dae22f76314a45c123b6c82f269dfa20785..cc979f6d39b37832a40134d87554efe67afc0002 100644
--- a/apps/app_rpt.c
+++ b/apps/app_rpt.c
@@ -805,8 +805,8 @@ static struct function_table_tag function_table[] = {
 	{"ilink", function_ilink},
 	{"status", function_status},
 	{"remote", function_remote},
-	{"macro", function_macro}
-	{"gosub", function_gosub}
+	{"macro", function_macro},
+	{"gosub", function_gosub},
 } ;
 
 /*
diff --git a/apps/app_skel.c b/apps/app_skel.c
index 230e952da3bbdadaed9cc93f99caaffb745e4a82..05897a264c935287bd83246a2f967760259d68cb 100644
--- a/apps/app_skel.c
+++ b/apps/app_skel.c
@@ -127,7 +127,10 @@ static int unload_module(void)
 
 static int load_module(void)
 {
-	return ast_register_application(app, app_exec, synopsis, descrip);
+	if (ast_register_application(app, app_exec, synopsis, descrip))
+		return AST_MODULE_LOAD_DECLINE;
+
+	return AST_MODULE_LOAD_SUCCESS;
 }
 
 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");
diff --git a/apps/app_test.c b/apps/app_test.c
index 8bf7b9e8c801eb0ce2b02a04b0c708d1a7233cbd..7941351567f5582323041ecdd9c6568bf25b8272 100644
--- a/apps/app_test.c
+++ b/apps/app_test.c
@@ -283,7 +283,7 @@ static int testclient_exec(struct ast_channel *chan, void *data)
 				else
 					res = -1;
 			}
-			if (option_debug && !res ) {
+			if (!res) {
 				/* Step 12: Hangup! */
 				ast_debug(1, "TestClient: 12.  Hangup\n");
 			}
diff --git a/main/http.c b/main/http.c
index 0fafef8030a74e26dba4afd7208da5cd1541b09e..d6c4e25f3481742461112f26f65ea6238582f1cb 100644
--- a/main/http.c
+++ b/main/http.c
@@ -338,7 +338,7 @@ static struct ast_http_post_mapping *find_post_mapping(const char *uri)
 	struct ast_http_post_mapping *post_map;
 
 	if (!ast_strlen_zero(prefix) && strncmp(prefix, uri, strlen(prefix))) {
-		ast_log(LOG_DEBUG, "URI %s does not have prefix %s\n", uri, prefix);
+		ast_debug(1, "URI %s does not have prefix %s\n", uri, prefix);
 		return NULL;
 	}
 
@@ -377,8 +377,7 @@ static void post_raw(struct mm_mimepart *part, const char *post_dir, const char
 
 	snprintf(filename, sizeof(filename), "%s/%s", post_dir, fn);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Posting raw data to %s\n", filename);
+	ast_debug(1, "Posting raw data to %s\n", filename);
 
 	if (!(f = fopen(filename, "w"))) {
 		ast_log(LOG_WARNING, "Unable to open %s for writing file from a POST!\n", filename);
@@ -386,15 +385,13 @@ static void post_raw(struct mm_mimepart *part, const char *post_dir, const char
 	}
 
 	if (!(body = mm_mimepart_getbody(part, 0))) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Couldn't get the mimepart body\n");
+		ast_debug(1, "Couldn't get the mimepart body\n");
 		fclose(f);
 		return;
 	}
 	body_len = mm_mimepart_getlength(part);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Body length is %ld\n", (long int)body_len);
+	ast_debug(1, "Body length is %ld\n", (long int)body_len);
 
 	fwrite(body, 1, body_len, f);
 
@@ -450,8 +447,7 @@ static struct ast_str *handle_post(struct server_instance *ser, char *uri,
 				fclose(f);
 				return NULL;
 			}
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Got a Content-Length of %d\n", content_len);
+			ast_debug(1, "Got a Content-Length of %d\n", content_len);
 		} else if (!strcasecmp(var->name, "Content-Type"))
 			fprintf(f, "Content-Type: %s\r\n\r\n", var->value);
 	}
@@ -464,16 +460,14 @@ static struct ast_str *handle_post(struct server_instance *ser, char *uri,
 	}
 
 	if (fseek(f, SEEK_SET, 0)) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Failed to seek temp file back to beginning.\n");
+		ast_debug(1, "Failed to seek temp file back to beginning.\n");
 		fclose(f);
 		return NULL;
 	}
 
 	AST_RWLIST_RDLOCK(&post_mappings);
 	if (!(post_map = find_post_mapping(uri))) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "%s is not a valid URI for POST\n", uri);
+		ast_debug(1, "%s is not a valid URI for POST\n", uri);
 		AST_RWLIST_UNLOCK(&post_mappings);
 		fclose(f);
 		*status = 404;
@@ -484,8 +478,7 @@ static struct ast_str *handle_post(struct server_instance *ser, char *uri,
 	post_map = NULL;
 	AST_RWLIST_UNLOCK(&post_mappings);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Going to post files to dir %s\n", post_dir);
+	ast_debug(1, "Going to post files to dir %s\n", post_dir);
 
 	if (!(ctx = mm_context_new())) {
 		fclose(f);
@@ -513,9 +506,9 @@ static struct ast_str *handle_post(struct server_instance *ser, char *uri,
 
 	if (option_debug) {
 		if (mm_context_iscomposite(ctx))
-			ast_log(LOG_DEBUG, "Found %d MIME parts\n", mm_res - 1);
+			ast_debug(1, "Found %d MIME parts\n", mm_res - 1);
 		else
-			ast_log(LOG_DEBUG, "We have a flat (not multi-part) message\n");
+			ast_debug(1, "We have a flat (not multi-part) message\n");
 	}
 
 	for (i = 1; i < mm_res; i++) {
@@ -523,20 +516,17 @@ static struct ast_str *handle_post(struct server_instance *ser, char *uri,
 		char fn[PATH_MAX];
 
 		if (!(part = mm_context_getpart(ctx, i))) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Failed to get mime part num %d\n", i);
+			ast_debug(1, "Failed to get mime part num %d\n", i);
 			continue;
 		}
 
 		if (get_filename(part, fn, sizeof(fn))) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Failed to retrieve a filename for part num %d\n", i);
+			ast_debug(1, "Failed to retrieve a filename for part num %d\n", i);
 			continue;
 		}
 	
 		if (!part->type) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "This part has no content struct?\n");
+			ast_debug(1, "This part has no content struct?\n");
 			continue;
 		}
 
@@ -979,8 +969,7 @@ void server_start(struct server_args *desc)
 	
 	/* Do nothing if nothing has changed */
 	if (!memcmp(&desc->oldsin, &desc->sin, sizeof(desc->oldsin))) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Nothing changed in %s\n", desc->name);
+		ast_debug(1, "Nothing changed in %s\n", desc->name);
 		return;
 	}
 	
diff --git a/main/io.c b/main/io.c
index a2ab1663590ab788270a68df56627d81c56967c7..c4ba3cffb326ce33ffef76a0c64dc7883250c2f1 100644
--- a/main/io.c
+++ b/main/io.c
@@ -37,6 +37,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/io.h"
 #include "asterisk/logger.h"
 #include "asterisk/utils.h"
+#include "asterisk/options.h"
 
 #ifdef DEBUG_IO
 #define DEBUG DEBUG_M
@@ -119,7 +120,7 @@ static int io_grow(struct io_context *ioc)
 {
 	void *tmp;
 
-	DEBUG(ast_log(LOG_DEBUG, "io_grow()\n"));
+	DEBUG(ast_debug(1, "io_grow()\n"));
 
 	ioc->maxfdcnt += GROW_SHRINK_SIZE;
 
@@ -159,7 +160,7 @@ int *ast_io_add(struct io_context *ioc, int fd, ast_io_cb callback, short events
 {
 	int *ret;
 
-	DEBUG(ast_log(LOG_DEBUG, "ast_io_add()\n"));
+	DEBUG(ast_debug(1, "ast_io_add()\n"));
 
 	if (ioc->fdcnt >= ioc->maxfdcnt) {
 		/* 
@@ -275,7 +276,7 @@ int ast_io_wait(struct io_context *ioc, int howlong)
 {
 	int res, x, origcnt;
 
-	DEBUG(ast_log(LOG_DEBUG, "ast_io_wait()\n"));
+	DEBUG(ast_debug(1, "ast_io_wait()\n"));
 
 	if ((res = poll(ioc->fds, ioc->fdcnt, howlong)) <= 0)
 		return res;
@@ -312,19 +313,19 @@ void ast_io_dump(struct io_context *ioc)
 	 */
 	int x;
 
-	ast_log(LOG_DEBUG, "Asterisk IO Dump: %d entries, %d max entries\n", ioc->fdcnt, ioc->maxfdcnt);
-	ast_log(LOG_DEBUG, "================================================\n");
-	ast_log(LOG_DEBUG, "| ID    FD     Callback    Data        Events  |\n");
-	ast_log(LOG_DEBUG, "+------+------+-----------+-----------+--------+\n");
+	ast_debug(1, "Asterisk IO Dump: %d entries, %d max entries\n", ioc->fdcnt, ioc->maxfdcnt);
+	ast_debug(1, "================================================\n");
+	ast_debug(1, "| ID    FD     Callback    Data        Events  |\n");
+	ast_debug(1, "+------+------+-----------+-----------+--------+\n");
 	for (x = 0; x < ioc->fdcnt; x++) {
-		ast_log(LOG_DEBUG, "| %.4d | %.4d | %p | %p | %.6x |\n", 
+		ast_debug(1, "| %.4d | %.4d | %p | %p | %.6x |\n", 
 				*ioc->ior[x].id,
 				ioc->fds[x].fd,
 				ioc->ior[x].callback,
 				ioc->ior[x].data,
 				ioc->fds[x].events);
 	}
-	ast_log(LOG_DEBUG, "================================================\n");
+	ast_debug(1, "================================================\n");
 }
 
 /* Unrelated I/O functions */
diff --git a/main/jitterbuf.c b/main/jitterbuf.c
index 177e2e625237ee1a3be915ff4f45f8c371b9ae93..12748869653f4c49dc98bccff5fa4600cb82c4ff 100644
--- a/main/jitterbuf.c
+++ b/main/jitterbuf.c
@@ -38,6 +38,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "jitterbuf.h"
 #include "asterisk/utils.h"
+#include "asterisk/options.h"
 
 /*! define these here, just for ancient compiler systems */
 #define JB_LONGMAX 2147483647L
@@ -532,7 +533,7 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
 	if (jb->frames)
 		numts = jb->frames->prev->ts - jb->frames->ts;
 	if (numts >= jb->info.conf.max_jitterbuf) {
-		ast_log(LOG_DEBUG, "Attempting to exceed Jitterbuf max %ld timeslots\n",
+		ast_debug(1, "Attempting to exceed Jitterbuf max %ld timeslots\n",
 			jb->info.conf.max_jitterbuf);
 		jb->dropem = 1;
 		return JB_DROP;
diff --git a/main/loader.c b/main/loader.c
index cd4e09ba4bf9ca285e7bbca9af0080c4e85691d1..5f29fc6b9891eed4b6d392dc4c2dea9935356eb0 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -248,8 +248,7 @@ static int printdigest(const unsigned char *d)
 	for (pos = 0, x = 0; x < 16; x++)
 		pos += sprintf(buf + pos, " %02x", *d++);
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Unexpected signature:%s\n", buf);
+	ast_debug(1, "Unexpected signature:%s\n", buf);
 
 	return 0;
 }
diff --git a/main/logger.c b/main/logger.c
index f02a18e5070851fd28427d8c0a859d06d4d15199..5357f95031f2d1936af253570b113457ec165d49 100644
--- a/main/logger.c
+++ b/main/logger.c
@@ -964,16 +964,13 @@ void ast_backtrace(void)
 	if ((addresses = ast_calloc(MAX_BACKTRACE_FRAMES, sizeof(*addresses)))) {
 		count = backtrace(addresses, MAX_BACKTRACE_FRAMES);
 		if ((strings = backtrace_symbols(addresses, count))) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
+			ast_debug(1, "Got %d backtrace record%c\n", count, count != 1 ? 's' : ' ');
 			for (i=0; i < count ; i++) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
+				ast_debug(1, "#%d: [%08X] %s\n", i, (unsigned int)addresses[i], strings[i]);
 			}
 			free(strings);
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Could not allocate memory for backtrace\n");
+			ast_debug(1, "Could not allocate memory for backtrace\n");
 		}
 		free(addresses);
 	}
diff --git a/main/manager.c b/main/manager.c
index ec6e2d968c9444fcf766c145d1faa1ba16b7cf0d..c5646be5b562e184e3ca1839f6ca2f0ff92a2279 100644
--- a/main/manager.c
+++ b/main/manager.c
@@ -1063,7 +1063,7 @@ static int authenticate(struct mansession *s, const struct message *m)
 			if (!strcmp(md5key, key))
 				error = 0;
 		} else {
-			ast_log(LOG_DEBUG, "MD5 authentication is not possible.  challenge: '%s'\n", 
+			ast_debug(1, "MD5 authentication is not possible.  challenge: '%s'\n", 
 				S_OR(s->challenge, ""));
 			return -1;
 		}
@@ -1370,8 +1370,7 @@ static int action_waitevent(struct mansession *s, const struct message *m)
 
 	/* XXX should this go inside the lock ? */
 	s->waiting_thread = pthread_self();	/* let new events wake up this thread */
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Starting waiting for an event!\n");
+	ast_debug(1, "Starting waiting for an event!\n");
 
 	for (x=0; x < timeout || timeout < 0; x++) {
 		ast_mutex_lock(&s->__lock);
@@ -1395,8 +1394,7 @@ static int action_waitevent(struct mansession *s, const struct message *m)
 			sleep(1);
 		}
 	}
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Finished waiting for an event!\n");
+	ast_debug(1, "Finished waiting for an event!\n");
 	ast_mutex_lock(&s->__lock);
 	if (s->waiting_thread == pthread_self()) {
 		struct eventqent *eqe;
@@ -1415,8 +1413,7 @@ static int action_waitevent(struct mansession *s, const struct message *m)
 			"\r\n", idText);
 		s->waiting_thread = AST_PTHREADT_NULL;
 	} else {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Abandoning event request!\n");
+		ast_debug(1, "Abandoning event request!\n");
 	}
 	ast_mutex_unlock(&s->__lock);
 	return 0;
@@ -2327,8 +2324,7 @@ static int process_message(struct mansession *s, const struct message *m)
 	const char *user = astman_get_header(m, "Username");
 
 	ast_copy_string(action, astman_get_header(m, "Action"), sizeof(action));
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Manager received command '%s'\n", action);
+	ast_debug(1, "Manager received command '%s'\n", action);
 
 	if (ast_strlen_zero(action)) {
 		astman_send_error(s, m, "Missing action in request");
@@ -3157,12 +3153,10 @@ static struct ast_str *generic_http_callback(enum output_format format,
 
 	if (s->needdestroy) {
 		if (s->inuse == 1) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Need destroy, doing it now!\n");
+			ast_debug(1, "Need destroy, doing it now!\n");
 			blastaway = 1;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Need destroy, but can't do it yet!\n");
+			ast_debug(1, "Need destroy, but can't do it yet!\n");
 			if (s->waiting_thread != AST_PTHREADT_NULL)
 				pthread_kill(s->waiting_thread, SIGURG);
 			s->inuse--;
@@ -3419,8 +3413,7 @@ int init_manager(void)
 			}  else if (!strcasecmp(var->name, "displayconnects") )
 				user->displayconnects = ast_true(var->value);
 			else {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "%s is an unknown option.\n", var->name);
+				ast_debug(1, "%s is an unknown option.\n", var->name);
 			}
 			var = var->next;
 		}
diff --git a/main/rtp.c b/main/rtp.c
index 2d86d080eec3faa0cd6d6071be5bad7e428a81a1..04f8e962991cea6077cd9be11e3b30d0729ef131 100644
--- a/main/rtp.c
+++ b/main/rtp.c
@@ -436,34 +436,29 @@ static int stun_handle_packet(int s, struct sockaddr_in *src, unsigned char *dat
 	int resplen, respleft;
 	
 	if (len < sizeof(struct stun_header)) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Runt STUN packet (only %d, wanting at least %d)\n", (int) len, (int) sizeof(struct stun_header));
+		ast_debug(1, "Runt STUN packet (only %d, wanting at least %d)\n", (int) len, (int) sizeof(struct stun_header));
 		return -1;
 	}
 	if (stundebug)
 		ast_verbose("STUN Packet, msg %s (%04x), length: %d\n", stun_msg2str(ntohs(hdr->msgtype)), ntohs(hdr->msgtype), ntohs(hdr->msglen));
 	if (ntohs(hdr->msglen) > len - sizeof(struct stun_header)) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Scrambled STUN packet length (got %d, expecting %d)\n", ntohs(hdr->msglen), (int)(len - sizeof(struct stun_header)));
+		ast_debug(1, "Scrambled STUN packet length (got %d, expecting %d)\n", ntohs(hdr->msglen), (int)(len - sizeof(struct stun_header)));
 	} else
 		len = ntohs(hdr->msglen);
 	data += sizeof(struct stun_header);
 	memset(&st, 0, sizeof(st));
 	while (len) {
 		if (len < sizeof(struct stun_attr)) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Runt Attribute (got %d, expecting %d)\n", (int)len, (int) sizeof(struct stun_attr));
+			ast_debug(1, "Runt Attribute (got %d, expecting %d)\n", (int)len, (int) sizeof(struct stun_attr));
 			break;
 		}
 		attr = (struct stun_attr *)data;
 		if (ntohs(attr->len) > len) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n", ntohs(attr->len), (int)len);
+			ast_debug(1, "Inconsistent Attribute (length %d exceeds remaining msg len %d)\n", ntohs(attr->len), (int)len);
 			break;
 		}
 		if (stun_process_attr(&st, attr)) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Failed to handle attribute %s (%04x)\n", stun_attr2str(ntohs(attr->attr)), ntohs(attr->attr));
+			ast_debug(1, "Failed to handle attribute %s (%04x)\n", stun_attr2str(ntohs(attr->attr)), ntohs(attr->attr));
 			break;
 		}
 		/* Clear attribute in case previous entry was a string */
@@ -638,14 +633,12 @@ static struct ast_frame *send_dtmf(struct ast_rtp *rtp, enum ast_frame_type type
 {
 	if (((ast_test_flag(rtp, FLAG_DTMF_COMPENSATE) && type == AST_FRAME_DTMF_END) ||
 	     (type == AST_FRAME_DTMF_BEGIN)) && ast_tvcmp(ast_tvnow(), rtp->dtmfmute) < 0) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(rtp->them.sin_addr));
+		ast_debug(1, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(rtp->them.sin_addr));
 		rtp->resp = 0;
 		rtp->dtmfsamples = 0;
 		return &ast_null_frame;
 	}
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(rtp->them.sin_addr));
+	ast_debug(1, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(rtp->them.sin_addr));
 	if (rtp->resp == 'X') {
 		rtp->f.frametype = AST_FRAME_CONTROL;
 		rtp->f.subclass = AST_CONTROL_FLASH;
@@ -944,8 +937,7 @@ struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
 		}
 	}
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Got RTCP report of %d bytes\n", res);
+	ast_debug(1, "Got RTCP report of %d bytes\n", res);
 
 	/* Process a compound packet */
 	position = 0;
@@ -1109,8 +1101,7 @@ struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
 				ast_verbose("Received a BYE from %s:%d\n", ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
 			break;
 		default:
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Unknown RTCP packet (pt=%d) received from %s:%d\n", pt, ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
+			ast_debug(1, "Unknown RTCP packet (pt=%d) received from %s:%d\n", pt, ast_inet_ntoa(rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
 			break;
 		}
 		position += (length + 1);
@@ -1204,8 +1195,7 @@ static int bridge_p2p_rtp_write(struct ast_rtp *rtp, struct ast_rtp *bridged, un
 	res = sendto(bridged->s, (void *)rtpheader, len, 0, (struct sockaddr *)&bridged->them, sizeof(bridged->them));
 	if (res < 0) {
 		if (!bridged->nat || (bridged->nat && (ast_test_flag(bridged, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "RTP Transmission error of packet to %s:%d: %s\n", ast_inet_ntoa(bridged->them.sin_addr), ntohs(bridged->them.sin_port), strerror(errno));
+			ast_debug(1, "RTP Transmission error of packet to %s:%d: %s\n", ast_inet_ntoa(bridged->them.sin_addr), ntohs(bridged->them.sin_port), strerror(errno));
 		} else if (((ast_test_flag(bridged, FLAG_NAT_ACTIVE) == FLAG_NAT_INACTIVE) || rtpdebug) && !ast_test_flag(bridged, FLAG_NAT_INACTIVE_NOWARN)) {
 			if (option_debug || rtpdebug)
 				ast_log(LOG_DEBUG, "RTP NAT: Can't write RTP to private address %s:%d, waiting for other end to send audio...\n", ast_inet_ntoa(bridged->them.sin_addr), ntohs(bridged->them.sin_port));
@@ -1632,16 +1622,14 @@ int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 	if (c1)
 		srcpr = get_proto(c1);
 	if (!destpr) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", c0->name);
+		ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", c0->name);
 		ast_channel_unlock(c0);
 		if (c1)
 			ast_channel_unlock(c1);
 		return -1;
 	}
 	if (!srcpr) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", c1 ? c1->name : "<unspecified>");
+		ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", c1 ? c1->name : "<unspecified>");
 		ast_channel_unlock(c0);
 		if (c1)
 			ast_channel_unlock(c1);
@@ -1692,8 +1680,7 @@ int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
 	ast_channel_unlock(c0);
 	if (c1)
 		ast_channel_unlock(c1);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Setting early bridge SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
+	ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
 	return 0;
 }
 
@@ -1717,15 +1704,13 @@ int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, i
 
 	/* Find channel driver interfaces */
 	if (!(destpr = get_proto(dest))) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", dest->name);
+		ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", dest->name);
 		ast_channel_unlock(dest);
 		ast_channel_unlock(src);
 		return 0;
 	}
 	if (!(srcpr = get_proto(src))) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Channel '%s' has no RTP, not doing anything\n", src->name);
+		ast_debug(1, "Channel '%s' has no RTP, not doing anything\n", src->name);
 		ast_channel_unlock(dest);
 		ast_channel_unlock(src);
 		return 0;
@@ -1768,8 +1753,7 @@ int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, i
 	}
 	ast_channel_unlock(dest);
 	ast_channel_unlock(src);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name);
+	ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n", dest->name, src->name);
 	return 1;
 }
 
@@ -2791,8 +2775,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
 			if (abs(rtp->lastts - pred) < MAX_TIMESTAMP_SKEW)
 				rtp->lastts = pred;
 			else {
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms);
+				ast_debug(3, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms);
 				mark = 1;
 			}
 		}
@@ -2807,8 +2790,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
 				rtp->lastts = pred;
 				rtp->lastovidtimestamp += f->samples;
 			} else {
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
+				ast_debug(3, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
 				rtp->lastovidtimestamp = rtp->lastts;
 			}
 		}
@@ -2822,8 +2804,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
 				rtp->lastts = pred;
 				rtp->lastotexttimestamp += f->samples;
 			} else {
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
+				ast_debug(3, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
 				rtp->lastotexttimestamp = rtp->lastts;
 			}
 		}
@@ -2848,8 +2829,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
 		res = sendto(rtp->s, (void *)rtpheader, f->datalen + hdrlen, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
 		if (res <0) {
 			if (!rtp->nat || (rtp->nat && (ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_ACTIVE))) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "RTP Transmission error of packet %d to %s:%d: %s\n", rtp->seqno, ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
+				ast_debug(1, "RTP Transmission error of packet %d to %s:%d: %s\n", rtp->seqno, ast_inet_ntoa(rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
 			} else if (((ast_test_flag(rtp, FLAG_NAT_ACTIVE) == FLAG_NAT_INACTIVE) || rtpdebug) && !ast_test_flag(rtp, FLAG_NAT_INACTIVE_NOWARN)) {
 				/* Only give this error message once if we are not RTP debugging */
 				if (option_debug || rtpdebug)
@@ -2938,8 +2918,7 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
 
 	if (rtp->lasttxformat != subclass) {
 		/* New format, reset the smoother */
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass));
+		ast_debug(1, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass));
 		rtp->lasttxformat = subclass;
 		if (rtp->smoother)
 			ast_smoother_free(rtp->smoother);
@@ -2955,8 +2934,7 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
 			}
 			if (fmt.flags)
 				ast_smoother_set_flags(rtp->smoother, fmt.flags);
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Created smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms));
+			ast_debug(1, "Created smoother: format: %d ms: %d len: %d\n", subclass, fmt.cur_ms, ((fmt.cur_ms * fmt.fr_len) / fmt.inc_ms));
 		}
 	}
 	if (rtp->smoother) {
@@ -3054,8 +3032,7 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 		if ((c0->tech_pvt != pvt0) ||
 		    (c1->tech_pvt != pvt1) ||
 		    (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
+			ast_debug(1, "Oooh, something is weird, backing out\n");
 			if (c0->tech_pvt == pvt0)
 				if (pr0->set_rtp_peer(c0, NULL, NULL, NULL, 0, 0))
 					ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c0->name);
@@ -3084,20 +3061,18 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 		    (vp1 && inaddrcmp(&vt1, &vac1)) ||
 		    (tp1 && inaddrcmp(&tt1, &tac1)) ||
 		    (codec1 != oldcodec1)) {
-			if (option_debug > 1) {
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
-					c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port), codec1);
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
-					c1->name, ast_inet_ntoa(vt1.sin_addr), ntohs(vt1.sin_port), codec1);
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end taddress to %s:%d (format %d)\n",
-					c1->name, ast_inet_ntoa(tt1.sin_addr), ntohs(tt1.sin_port), codec1);
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
-					c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1);
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
-					c1->name, ast_inet_ntoa(vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1);
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
-					c1->name, ast_inet_ntoa(tac1.sin_addr), ntohs(tac1.sin_port), oldcodec1);
-			}
+			ast_debug(2, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
+				c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port), codec1);
+			ast_debug(2, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
+				c1->name, ast_inet_ntoa(vt1.sin_addr), ntohs(vt1.sin_port), codec1);
+			ast_debug(2, "Oooh, '%s' changed end taddress to %s:%d (format %d)\n",
+				c1->name, ast_inet_ntoa(tt1.sin_addr), ntohs(tt1.sin_port), codec1);
+			ast_debug(2, "Oooh, '%s' was %s:%d/(format %d)\n",
+				c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1);
+			ast_debug(2, "Oooh, '%s' was %s:%d/(format %d)\n",
+				c1->name, ast_inet_ntoa(vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1);
+			ast_debug(2, "Oooh, '%s' was %s:%d/(format %d)\n",
+				c1->name, ast_inet_ntoa(tac1.sin_addr), ntohs(tac1.sin_port), oldcodec1);
 			if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, tt1.sin_addr.s_addr ? tp1 : NULL, codec1, ast_test_flag(p1, FLAG_NAT_ACTIVE)))
 				ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
 			memcpy(&ac1, &t1, sizeof(ac1));
@@ -3108,12 +3083,10 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 		if ((inaddrcmp(&t0, &ac0)) ||
 		    (vp0 && inaddrcmp(&vt0, &vac0)) ||
 		    (tp0 && inaddrcmp(&tt0, &tac0))) {
-			if (option_debug > 1) {
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
-					c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port), codec0);
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
-					c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0);
-			}
+			ast_debug(2, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
+				c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port), codec0);
+			ast_debug(2, "Oooh, '%s' was %s:%d/(format %d)\n",
+				c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0);
 			if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, tt0.sin_addr.s_addr ? tp0 : NULL, codec0, ast_test_flag(p0, FLAG_NAT_ACTIVE)))
 				ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
 			memcpy(&ac0, &t0, sizeof(ac0));
@@ -3131,8 +3104,7 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 					ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c1->name);
 				return AST_BRIDGE_RETRY;
 			}
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Ooh, empty read...\n");
+			ast_debug(1, "Ooh, empty read...\n");
 			if (ast_check_hangup(c0) || ast_check_hangup(c1))
 				break;
 			continue;
@@ -3145,8 +3117,7 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 			/* Break out of bridge */
 			*fo = fr;
 			*rc = who;
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Oooh, got a %s\n", fr ? "digit" : "hangup");
+			ast_debug(1, "Oooh, got a %s\n", fr ? "digit" : "hangup");
 			if (c0->tech_pvt == pvt0)
 				if (pr0->set_rtp_peer(c0, NULL, NULL, NULL, 0, 0))
 					ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c0->name);
@@ -3176,8 +3147,7 @@ static enum ast_bridge_result bridge_native_loop(struct ast_channel *c0, struct
 			} else {
 				*fo = fr;
 				*rc = who;
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass, who->name);
+				ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass, who->name);
 				return AST_BRIDGE_COMPLETE;
 			}
 		} else {
@@ -3338,8 +3308,7 @@ static enum ast_bridge_result bridge_p2p_loop(struct ast_channel *c0, struct ast
 		if ((c0->tech_pvt != pvt0) ||
 		    (c1->tech_pvt != pvt1) ||
 		    (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "p2p-rtp-bridge: Oooh, something is weird, backing out\n");
+			ast_debug(3, "p2p-rtp-bridge: Oooh, something is weird, backing out\n");
 			/* If a masquerade needs to happen we have to try to read in a frame so that it actually happens. Without this we risk being called again and going into a loop */
 			if ((c0->masq || c0->masqr) && (fr = ast_read(c0)))
 				ast_frfree(fr);
@@ -3370,8 +3339,7 @@ static enum ast_bridge_result bridge_p2p_loop(struct ast_channel *c0, struct ast
 			/* Record received frame and who */
 			*fo = fr;
 			*rc = who;
-			if (option_debug > 2)
-				ast_log(LOG_DEBUG, "p2p-rtp-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
+			ast_debug(3, "p2p-rtp-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
 			res = AST_BRIDGE_COMPLETE;
 			break;
 		} else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
@@ -3400,8 +3368,7 @@ static enum ast_bridge_result bridge_p2p_loop(struct ast_channel *c0, struct ast
 			} else {
 				*fo = fr;
 				*rc = who;
-				if (option_debug > 2)
-					ast_log(LOG_DEBUG, "p2p-rtp-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass, who->name);
+				ast_debug(3, "p2p-rtp-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass, who->name);
 				res = AST_BRIDGE_COMPLETE;
 				break;
 			}
@@ -3578,8 +3545,7 @@ enum ast_bridge_result ast_rtp_bridge(struct ast_channel *c0, struct ast_channel
 	codec1 = pr1->get_codec ? pr1->get_codec(c1) : 0;
 	if (codec0 && codec1 && !(codec0 & codec1)) {
 		/* Hey, we can't do native bridging if both parties speak different codecs */
-		if (option_debug > 2)
-			ast_log(LOG_DEBUG, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1);
+		ast_debug(3, "Channel codec0 = %d is not codec1 = %d, cannot native bridge in RTP.\n", codec0, codec1);
 		ast_channel_unlock(c0);
 		ast_channel_unlock(c1);
 		return AST_BRIDGE_FAILED_NOWARN;
@@ -3591,8 +3557,7 @@ enum ast_bridge_result ast_rtp_bridge(struct ast_channel *c0, struct ast_channel
 
 		/* In order to do Packet2Packet bridging both sides must be in the same rawread/rawwrite */
 		if (c0->rawreadformat != c1->rawwriteformat || c1->rawreadformat != c0->rawwriteformat) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Cannot packet2packet bridge - raw formats are incompatible\n");
+			ast_debug(1, "Cannot packet2packet bridge - raw formats are incompatible\n");
 			ast_channel_unlock(c0);
 			ast_channel_unlock(c1);
 			return AST_BRIDGE_FAILED_NOWARN;
diff --git a/main/say.c b/main/say.c
index c11ac72182bfc8a44da307b907cd30cdd3cea0d3..7dce69a5c1b4f5e5415a6e1f841b5b2dc9c7d6a1 100644
--- a/main/say.c
+++ b/main/say.c
@@ -508,8 +508,7 @@ static int ast_say_number_full_en(struct ast_channel *chan, int num, const char
 						num = num % 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
-						if (option_debug)
-							ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
 					}
 				}
@@ -738,8 +737,7 @@ static int ast_say_number_full_da(struct ast_channel *chan, int num, const char
 							snprintf(fn, sizeof(fn), "digits/millions");
 						num = num % 1000000;
 					} else {
-						if (option_debug)
-							ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
 					}
 				}
@@ -874,8 +872,7 @@ static int ast_say_number_full_de(struct ast_channel *chan, int num, const char
 				snprintf(fn, sizeof(fn), "digits/milliards");
 			}
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 		if (!res) {
@@ -960,8 +957,7 @@ static int ast_say_number_full_en_GB(struct ast_channel *chan, int num, const ch
 				if (num && num < 100)
 					playa++;
 		} else {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+				ast_debug(1, "Number '%d' is too big for me\n", num);
 				res = -1;
 		}
 		
@@ -1062,8 +1058,7 @@ static int ast_say_number_full_es(struct ast_channel *chan, int num, const char
 						}
 						num = num % 1000000;
 					} else {
-						if (option_debug)
-							ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
 					}
 				}
@@ -1159,8 +1154,7 @@ static int ast_say_number_full_fr(struct ast_channel *chan, int num, const char
 			snprintf(fn, sizeof(fn), "digits/million");
 			num = num % 1000000;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 		if (!res) {
@@ -1309,8 +1303,7 @@ static int ast_say_number_full_he(struct ast_channel *chan, int num,
 			snprintf(fn, sizeof(fn), "digits/million");
 			num = num % 1000000;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 		if (!res) {
@@ -1541,8 +1534,7 @@ static int ast_say_number_full_it(struct ast_channel *chan, int num, const char
 							else
 								snprintf(fn, sizeof(fn), "digits/millions");
 						} else {
-							if (option_debug)
-								ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+							ast_debug(1, "Number '%d' is too big for me\n", num);
 							res = -1;
 						}
 					}
@@ -1618,8 +1610,7 @@ static int ast_say_number_full_nl(struct ast_channel *chan, int num, const char
 						num = num % 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
-						if (option_debug)
-							ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
 					}
 				}
@@ -1714,8 +1705,7 @@ static int ast_say_number_full_no(struct ast_channel *chan, int num, const char
 				if (num && num < 100)
 					playa++;
 		} else {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+				ast_debug(1, "Number '%d' is too big for me\n", num);
 				res = -1;
 		}
 		
@@ -1766,8 +1756,7 @@ static void pl_odtworz_plik(struct ast_channel *chan, const char *language, int
 {    
 	char file_name[255] = "digits/";
 	strcat(file_name, fn);
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Trying to play: %s\n", file_name);
+	ast_debug(1, "Trying to play: %s\n", file_name);
 	if (!ast_streamfile(chan, file_name, language)) {
 		if ((audiofd > -1) && (ctrlfd > -1))
 			ast_waitstream_full(chan, ints, audiofd, ctrlfd);
@@ -2180,8 +2169,7 @@ static int ast_say_number_full_se(struct ast_channel *chan, int num, const char
 						num = num % 1000000;
 						snprintf(fn, sizeof(fn), "digits/million");
 					} else {
-						if (option_debug)
-							ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+						ast_debug(1, "Number '%d' is too big for me\n", num);
 						res = -1;
 					}
 				}
@@ -2246,8 +2234,7 @@ static int ast_say_number_full_tw(struct ast_channel *chan, int num, const char
 							num = num % 1000000;
 							snprintf(fn, sizeof(fn), "digits/million");
 						} else {
-							if (option_debug)
-								ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+							ast_debug(1, "Number '%d' is too big for me\n", num);
 							res = -1;
 						}
 					}
@@ -2356,8 +2343,7 @@ static int ast_say_number_full_ru(struct ast_channel *chan, int num, const char
 			}
 			num %= 1000000;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 		if (!res) {
@@ -2471,8 +2457,7 @@ static int ast_say_enumeration_full_en(struct ast_channel *chan, int num, const
 			snprintf(fn, sizeof(fn), "digits/h-last");
 			num = 0;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 
@@ -2625,8 +2610,7 @@ static int ast_say_enumeration_full_da(struct ast_channel *chan, int num, const
 			snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
 			num = 0;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 
@@ -2789,8 +2773,7 @@ static int ast_say_enumeration_full_de(struct ast_channel *chan, int num, const
 			snprintf(fn, sizeof(fn), "digits/h-last%s", gender);
 			num = 0;
 		} else {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+			ast_debug(1, "Number '%d' is too big for me\n", num);
 			res = -1;
 		}
 
@@ -3127,8 +3110,7 @@ int ast_say_date_with_format_en(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -3370,8 +3352,7 @@ int ast_say_date_with_format_da(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -3576,8 +3557,7 @@ int ast_say_date_with_format_de(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -3807,8 +3787,7 @@ int ast_say_date_with_format_he(struct ast_channel *chan, time_t time,
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -3990,8 +3969,7 @@ int ast_say_date_with_format_es(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -4183,8 +4161,7 @@ int ast_say_date_with_format_fr(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -4382,8 +4359,7 @@ int ast_say_date_with_format_it(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -4616,8 +4592,7 @@ int ast_say_date_with_format_nl(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -4823,8 +4798,7 @@ int ast_say_date_with_format_pl(struct ast_channel *chan, time_t thetime, const
 
 	for (offset = 0 ; format[offset] != '\0' ; offset++) {
 		int remainder;
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -5042,8 +5016,7 @@ int ast_say_date_with_format_pt(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -5341,8 +5314,7 @@ int ast_say_date_with_format_tw(struct ast_channel *chan, time_t time, const cha
 	ast_localtime(&time,&tm,timezone);
 
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 			case '\'':
@@ -6424,8 +6396,7 @@ static int ast_say_number_full_gr(struct ast_channel *chan, int num, const char
 					num = num % 1000000;
 					snprintf(fn, sizeof(fn), "digits/millions");
 				} else {
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Number '%d' is too big for me\n", num);
+					ast_debug(1, "Number '%d' is too big for me\n", num);
 					res = -1;
 				}
 			}
@@ -6590,8 +6561,7 @@ static int ast_say_date_with_format_gr(struct ast_channel *chan, time_t time, co
 	ast_localtime(&time,&tm,timezone);
 	
 	for (offset=0 ; format[offset] != '\0' ; offset++) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
+		ast_debug(1, "Parsing %c (offset %d) in %s\n", format[offset], offset, format);
 		switch (format[offset]) {
 			/* NOTE:  if you add more options here, please try to be consistent with strftime(3) */
 		case '\'':
diff --git a/main/sched.c b/main/sched.c
index 9aac2cde7e9d4c9965f67558c008781da7a0b48e..1dd73334f786cd16289b89a5e495753fc6ed93f3 100644
--- a/main/sched.c
+++ b/main/sched.c
@@ -149,7 +149,7 @@ int ast_sched_wait(struct sched_context *con)
 {
 	int ms;
 
-	DEBUG(ast_log(LOG_DEBUG, "ast_sched_wait()\n"));
+	DEBUG(ast_debug(1, "ast_sched_wait()\n"));
 
 	ast_mutex_lock(&con->lock);
 	if (AST_LIST_EMPTY(&con->schedq)) {
@@ -201,8 +201,7 @@ static int sched_settime(struct timeval *tv, int when)
 		*tv = now;
 	*tv = ast_tvadd(*tv, ast_samp2tv(when, 1000));
 	if (ast_tvcmp(*tv, now) < 0) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Request to schedule in the past?!?!\n");
+		ast_debug(1, "Request to schedule in the past?!?!\n");
 		*tv = now;
 	}
 	return 0;
@@ -216,7 +215,7 @@ int ast_sched_add_variable(struct sched_context *con, int when, ast_sched_cb cal
 {
 	struct sched *tmp;
 	int res = -1;
-	DEBUG(ast_log(LOG_DEBUG, "ast_sched_add()\n"));
+	DEBUG(ast_debug(1, "ast_sched_add()\n"));
 	if (!when) {
 		ast_log(LOG_NOTICE, "Scheduled event in 0 ms?\n");
 		return -1;
@@ -260,7 +259,7 @@ int ast_sched_del(struct sched_context *con, int id)
 {
 	struct sched *s;
 
-	DEBUG(ast_log(LOG_DEBUG, "ast_sched_del()\n"));
+	DEBUG(ast_debug(1, "ast_sched_del()\n"));
 	
 	ast_mutex_lock(&con->lock);
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&con->schedq, s, list) {
@@ -281,8 +280,7 @@ int ast_sched_del(struct sched_context *con, int id)
 	ast_mutex_unlock(&con->lock);
 
 	if (!s) {
-		if (option_debug)
-			ast_log(LOG_DEBUG, "Attempted to delete nonexistent schedule entry %d!\n", id);
+		ast_debug(1, "Attempted to delete nonexistent schedule entry %d!\n", id);
 #ifdef DO_CRASH
 		CRASH;
 #endif
@@ -298,11 +296,9 @@ void ast_sched_dump(const struct sched_context *con)
 	struct sched *q;
 	struct timeval tv = ast_tvnow();
 #ifdef SCHED_MAX_CACHE
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt);
+	ast_debug(1, "Asterisk Schedule Dump (%d in Q, %d Total, %d Cache)\n", con->schedcnt, con->eventcnt - 1, con->schedccnt);
 #else
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Asterisk Schedule Dump (%d in Q, %d Total)\n", con->schedcnt, con->eventcnt - 1);
+	ast_debug(1, "Asterisk Schedule Dump (%d in Q, %d Total)\n", con->schedcnt, con->eventcnt - 1);
 #endif
 
 	if (option_debug) {
@@ -333,7 +329,7 @@ int ast_sched_runq(struct sched_context *con)
 	int numevents;
 	int res;
 
-	DEBUG(ast_log(LOG_DEBUG, "ast_sched_runq()\n"));
+	DEBUG(ast_debug(1, "ast_sched_runq()\n"));
 		
 	ast_mutex_lock(&con->lock);
 
@@ -387,7 +383,7 @@ long ast_sched_when(struct sched_context *con,int id)
 {
 	struct sched *s;
 	long secs = -1;
-	DEBUG(ast_log(LOG_DEBUG, "ast_sched_when()\n"));
+	DEBUG(ast_debug(1, "ast_sched_when()\n"));
 
 	ast_mutex_lock(&con->lock);
 	AST_LIST_TRAVERSE(&con->schedq, s, list) {
diff --git a/main/translate.c b/main/translate.c
index b80c280de192785b71e2864154fb15e60048f0cb..463b0e52fa03758b238edf6af69ffadeab40ed9b 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -423,8 +423,7 @@ static void rebuild_matrix(int samples)
 	int y;      /* intermediate format index */
 	int z;      /* destination format index */
 
-	if (option_debug)
-		ast_log(LOG_DEBUG, "Resetting translation matrix\n");
+	ast_debug(1, "Resetting translation matrix\n");
 
 	bzero(tr_matrix, sizeof(tr_matrix));
 
@@ -478,8 +477,7 @@ static void rebuild_matrix(int samples)
 					tr_matrix[x][z].step = tr_matrix[x][y].step;
 					tr_matrix[x][z].cost = newcost;
 					tr_matrix[x][z].multistep = 1;
-					if (option_debug)
-						ast_log(LOG_DEBUG, "Discovered %d cost path from %s to %s, via %d\n", tr_matrix[x][z].cost, ast_getformatname(x), ast_getformatname(z), y);
+					ast_debug(1, "Discovered %d cost path from %s to %s, via %d\n", tr_matrix[x][z].cost, ast_getformatname(x), ast_getformatname(z), y);
 					changed++;
 				}
 			}
diff --git a/main/udptl.c b/main/udptl.c
index 34b5b872f6bbb615b77121db2dbe191e49a6d452..ef0707bdb519d4f06d5c920eb81b042c2046f4e5 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -697,8 +697,7 @@ struct ast_frame *ast_udptl_read(struct ast_udptl *udptl)
 		if ((udptl->them.sin_addr.s_addr != sin.sin_addr.s_addr) ||
 			(udptl->them.sin_port != sin.sin_port)) {
 			memcpy(&udptl->them, &sin, sizeof(udptl->them));
-			if (option_debug)
-				ast_log(LOG_DEBUG, "UDPTL NAT: Using address %s:%d\n", ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
+			ast_debug(1, "UDPTL NAT: Using address %s:%d\n", ast_inet_ntoa(udptl->them.sin_addr), ntohs(udptl->them.sin_port));
 		}
 	}
 
@@ -1066,8 +1065,7 @@ int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags,
 		if ((c0->tech_pvt != pvt0) ||
 			(c1->tech_pvt != pvt1) ||
 			(c0->masq || c0->masqr || c1->masq || c1->masqr)) {
-				if (option_debug)
-					ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n");
+				ast_debug(1, "Oooh, something is weird, backing out\n");
 				/* Tell it to try again later */
 				return -3;
 		}
@@ -1075,27 +1073,22 @@ int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags,
 		ast_udptl_get_peer(p1, &t1);
 		ast_udptl_get_peer(p0, &t0);
 		if (inaddrcmp(&t1, &ac1)) {
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n", 
-					c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n", 
-					c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
-			}
+			ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
+				c1->name, ast_inet_ntoa(t1.sin_addr), ntohs(t1.sin_port));
+			ast_debug(1, "Oooh, '%s' was %s:%d\n", 
+				c1->name, ast_inet_ntoa(ac1.sin_addr), ntohs(ac1.sin_port));
 			memcpy(&ac1, &t1, sizeof(ac1));
 		}
 		if (inaddrcmp(&t0, &ac0)) {
-			if (option_debug) {
-				ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d\n", 
-					c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
-				ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d\n", 
-					c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
-			}
+			ast_debug(1, "Oooh, '%s' changed end address to %s:%d\n", 
+				c0->name, ast_inet_ntoa(t0.sin_addr), ntohs(t0.sin_port));
+			ast_debug(1, "Oooh, '%s' was %s:%d\n", 
+				c0->name, ast_inet_ntoa(ac0.sin_addr), ntohs(ac0.sin_port));
 			memcpy(&ac0, &t0, sizeof(ac0));
 		}
 		who = ast_waitfor_n(cs, 2, &to);
 		if (!who) {
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Ooh, empty read...\n");
+			ast_debug(1, "Ooh, empty read...\n");
 			/* check for hangup / whentohangup */
 			if (ast_check_hangup(c0) || ast_check_hangup(c1))
 				break;
@@ -1105,8 +1098,7 @@ int ast_udptl_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags,
 		if (!f) {
 			*fo = f;
 			*rc = who;
-			if (option_debug)
-				ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
+			ast_debug(1, "Oooh, got a %s\n", f ? "digit" : "hangup");
 			/* That's all we needed */
 			return 0;
 		} else {