0a6acb
diff --git a/log.c b/log.c
0a6acb
index 34a013b..1aca728 100644
0a6acb
--- a/log.c
0a6acb
+++ b/log.c
0a6acb
@@ -377,10 +377,13 @@ output_msg:
0a6acb
 				filtered_fwrite(f, convbuf, outbuf.len, 0);
0a6acb
 				outbuf.len = 0;
0a6acb
 			}
0a6acb
-			if (!ierrno || ierrno == E2BIG)
0a6acb
-				continue;
0a6acb
-			fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++));
0a6acb
-			inbuf.len--;
0a6acb
+			/* Log one byte of illegal/incomplete sequence and continue with
0a6acb
+			 * the next character. Check that the buffer is non-empty for the
0a6acb
+			 * sake of robustness. */
0a6acb
+			if ((ierrno == EILSEQ || ierrno == EINVAL) && inbuf.len) {
0a6acb
+				fprintf(f, "\\#%03o", CVAL(inbuf.buf, inbuf.pos++));
0a6acb
+				inbuf.len--;
0a6acb
+			}
0a6acb
 		}
0a6acb
 	} else
0a6acb
 #endif