Hi, Am 2017-01-14 um 16:48 schrieb Mike Tremaine: > >> 0002-Use-pager-on-stdout-output-to-terminal.patch >> >> Use pager less if output is on terminal. This should address the issues >> associated with escape sequences in logs that may mess with your >> terminal. Less seems to be good at filtering these escape sequences. > > > Sounds good, but I’d make it a config switch and leave the default as is. > Some “lazy” destro's let cron handle terminal output to mail directly… :/
But, then "-t STDOUT" is false (see patch) - in this case, the pager will not be invoked. I also made the pager configurable and it can be set to am empty string to disable). I updated the help text in the second patch to document that better. Willi
>From 162f8b2e7fae134e65761dc64e0a8d29c9c172d4 Mon Sep 17 00:00:00 2001 From: Willi Mann <wi...@wm1.at> Date: Sat, 14 Jan 2017 15:32:39 +0100 Subject: [PATCH 1/2] Add outputencoding parameter --- conf/logwatch.conf | 8 ++++++++ scripts/logwatch.pl | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/conf/logwatch.conf b/conf/logwatch.conf index 2b61ec6..0d0e31b 100644 --- a/conf/logwatch.conf +++ b/conf/logwatch.conf @@ -126,4 +126,12 @@ mailer = "/usr/sbin/sendmail -t" # #HostLimit = myhost +# +# With this option, the output encoding for mail headers can be set. It +# defaults to utf-8. Be aware that the default value may change to autodetect +# (take the system's encoding). Note that the configured value will be +# upper-cased. +# +# OutputEncoding = utf-8 + # vi: shiftwidth=3 tabstop=3 et diff --git a/scripts/logwatch.pl b/scripts/logwatch.pl index 0167755..0cff511 100755 --- a/scripts/logwatch.pl +++ b/scripts/logwatch.pl @@ -90,6 +90,7 @@ $Config{'pathtobzcat'} = "bzcat"; $Config{'output'} = "stdout"; #8.0 $Config{'format'} = "text"; #8.0 $Config{'encode'} = "none"; #8.0 +$Config{'outputencoding'} = "utf-8"; $Config{'hostformat'} = "none"; #8.0 $Config{'html_wrap'} = 80; $Config{'supress_ignores'} = 0; @@ -1160,11 +1161,12 @@ sub initprint { } else { $out_mime .= "Content-Transfer-Encoding: 7bit\n"; } - #Config{output} html + #Config{output} html, Config{outputenconding} + my $encoding = uc($Config{outputencoding}); if ( $Config{'format'} eq "html" ) { - $out_mime .= "Content-Type: text/html; charset=\"UTF-8\"\n\n"; + $out_mime .= "Content-Type: text/html; charset=\"$encoding\"\n\n"; } else { - $out_mime .= "Content-Type: text/plain; charset=\"UTF-8\"\n\n"; + $out_mime .= "Content-Type: text/plain; charset=\"$encoding\"\n\n"; } if ($Config{'hostformat'} eq "split") { #8.0 check hostlimit also? or ne none? -- 2.1.4
>From 0f52b6b4a35e8aa33d2827f90d515491c15a3d41 Mon Sep 17 00:00:00 2001 From: Willi Mann <wi...@wm1.at> Date: Sat, 14 Jan 2017 16:25:30 +0100 Subject: [PATCH 2/2] Use pager on stdout output to terminal --- conf/logwatch.conf | 5 +++++ scripts/logwatch.pl | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/conf/logwatch.conf b/conf/logwatch.conf index 0d0e31b..c46b5d6 100644 --- a/conf/logwatch.conf +++ b/conf/logwatch.conf @@ -134,4 +134,9 @@ mailer = "/usr/sbin/sendmail -t" # # OutputEncoding = utf-8 +# +# For output type stdout, logwatch uses the pager Pager if STDOUT is a terminal. +# Am empty string disables the pager. +#Pager = /usr/bin/less + # vi: shiftwidth=3 tabstop=3 et diff --git a/scripts/logwatch.pl b/scripts/logwatch.pl index 0cff511..f053cb3 100755 --- a/scripts/logwatch.pl +++ b/scripts/logwatch.pl @@ -88,6 +88,7 @@ $Config{'pathtocat'} = "cat"; $Config{'pathtozcat'} = "zcat"; $Config{'pathtobzcat'} = "bzcat"; $Config{'output'} = "stdout"; #8.0 +$Config{'pager'} = "/usr/bin/less"; #8.0 $Config{'format'} = "text"; #8.0 $Config{'encode'} = "none"; #8.0 $Config{'outputencoding'} = "utf-8"; @@ -1127,7 +1128,11 @@ sub initprint { $OStitle = "Solaris" if ($OSname eq "SunOS" && $release >= 2); if ($Config{'output'} eq "stdout") { #8.0 start with others? - *OUTFILE = *STDOUT; + if($Config{'pager'} and -t STDOUT) { + open(OUTFILE,"|$Config{'pager'}") or die "could not open pager: $Config{'pager'} $!"; + } else { + *OUTFILE = *STDOUT; + } } elsif ($Config{'output'} eq "file") { open(OUTFILE,">>" . $Config{'filename'}) or die "Can't open output file: $Config{'filename'} $!\n"; } else { -- 2.1.4