I encountered an issue where my firmware would get stuck in NRF_LOG_FLUSH();, and the same logs would be sent over RTT repeatedly. Pausing the debugger showed that the read offset was far in advance of the write offset. I am not sure what the conditions for this are, but it happened when lots of logs were being produced. I looked at the implementation and noticed that rd_idx gets masked every time it is used, however when checking if the read offset matches the write offset I noticed it is not masked (nrf_log_frontend.c):
bool buffer_is_empty(void) { return m_log_data.rd_idx == m_log_data.wr_idx; }
I believe the code should be changed to:
bool buffer_is_empty(void) { return ((m_log_data.rd_idx & m_buffer_mask) == (m_log_data.wr_idx & m_buffer_mask)); }
After making this change, the problem no longer occurs.