diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h
index a23f0344cc53845b45ee745d36ff1d8eef6dfe5c..a4005d7ca255515b2b576563899ceb243d2e6b9c 100644
--- a/include/asterisk/lock.h
+++ b/include/asterisk/lock.h
@@ -1556,6 +1556,7 @@ static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *t, const char *name,
 {
 	int res;
 	struct ast_lock_track *lt = &t->track;
+	int canlog = strcmp(filename, "logger.c") & t->tracking;
 #ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
 #endif
@@ -1614,6 +1615,7 @@ static inline int _ast_rwlock_trywrlock(ast_rwlock_t *t, const char *name,
 {
 	int res;
 	struct ast_lock_track *lt= &t->track;
+	int canlog = strcmp(filename, "logger.c") & t->tracking;
 #ifdef HAVE_BKTR
 	struct ast_bt *bt = NULL;
 #endif