From ab9e7fede8743d1aa47c9d46cf830239d63fc1e0 Mon Sep 17 00:00:00 2001
From: Don Armstrong <don@donarmstrong.com>
Date: Fri, 29 Dec 2017 14:04:26 -0800
Subject: [PATCH] abstract out output, use string::escape

---
 src/logger.pl | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/src/logger.pl b/src/logger.pl
index 66c925a..03252af 100644
--- a/src/logger.pl
+++ b/src/logger.pl
@@ -170,39 +170,34 @@ sub compress {
     return 1;
 }
 
+sub __output {
+    my ($what,$color,$message) = @_;
+    my (undef,undef,$line,$subroutine,undef) = caller(2);
+    use String::Escape qw();
+    status("$color!$what!$ob ".$subroutine.'['.$line.'] '.String::Escape::backslash($message));
+}
+
 sub DEBUG {
     return unless ( &IsParam('DEBUG') );
-    my (undef,undef,$line,$subroutine,undef) = caller(1);
-
-    &status("${b_green}!DEBUG!$ob ".$subroutine.'['.$line."] ".quotemeta($_[0]));
+    __output($b_green,'DEBUG',$_[0]);
 }
 
 sub ERROR {
-    my (undef,undef,$line,$subroutine,undef) = caller(1);
-
-    &status("${b_red}!ERROR!$ob ".$subroutine.'['.$line."] ".quotemeta($_[0]));
+    __output($b_red,'ERROR',$_[0]);
 }
 
 sub WARN {
     return unless ( &IsParam('WARN') );
-
     return if ( $_[0] =~ /^PERL: Subroutine \S+ redefined at/ );
-
-    my ($package,$filename,$line,$subroutine,undef) = caller(1);
-
-    &status("${b_yellow}!WARN!$ob ".$subroutine.'['.$line."] ".quotemeta($_[0]));
+    __output($b_yellow,'WARN',$_[0]);
 }
 
 sub FIXME {
-    my ($package,$filename,$line,$subroutine,undef) = caller(1);
-
-    &status("${b_cyan}!FIXME!$ob ".$subroutine.'['.$line."] ".quotemeta($_[0]));
+    __output($b_cyan,'FIXME',$_[0]);
 }
 
 sub TODO {
-    my ($package,$filename,$line,$subroutine,undef) = caller(1);
-
-    &status("${b_cyan}!TODO!$ob ".$subroutine.'['.$line."] ".quotemeta($_[0]));
+    __output($b_cyan,'TODO',$_[0]);
 }
 
 sub VERB {
-- 
2.39.5