diff --git a/modsec_logger.go b/modsec_logger.go
index 29e3f2bd064564868b4c33fbc7fcc8e813ea30ab..2965091289bbfbd7ba48d624123da2099bdaf916 100644
--- a/modsec_logger.go
+++ b/modsec_logger.go
@@ -1,6 +1,5 @@
 // Tool to rewrite mod_security2 logs (very difficult to parse
 // although they are in semi-structured format) to JSON.
-//
 package main
 
 import (
@@ -9,6 +8,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"io"
+	"log"
 	"os"
 	"regexp"
 )
@@ -52,15 +52,24 @@ func parseModSec(w io.Writer, line []byte) bool {
 	return true
 }
 
+func writeLine(w io.Writer, line byte) error {
+	if _, err := w.Write(line); err != nil {
+		return err
+	}
+	return io.WriteString(w, "\n")
+}
+
 func main() {
 	outw := os.Stdout
 
 	scanner := bufio.NewScanner(os.Stdin)
 	for scanner.Scan() {
 		line := scanner.Bytes()
-		if !parseModSec(outw, line) {
-			outw.Write(line)
-			io.WriteString(outw, "\n")
+		if parseModSec(outw, line) {
+			continue
+		}
+		if err := writeLine(outw, line); err != nil {
+			log.Fatal(err)
 		}
 	}
 }