php service

"gulikoza" <[email protected]>
Newsgroups gmane.comp.log.logwatch.devel
Message-ID <[email protected]>
Hello,

PHP service does not find any logs on my Centos6 machine. There's a couple
of problems:

 - it is only configured to search for php logfile group (httpd/php_log,
apache2/php_error_log, ...) so the administrator needs to configure php to
use the same logfiles, while http-error service will specifically ignore all
PHP related errors in http-error log group ("skip PHP messages (have a
separate script)")

 - while both scripts have similar structure, php is using a different time
format and skips all messages on my machine.

There's also a minor formatting issue, where Outlook will remove "extra line
breaks" and compress the outputs of both php and http-error to a single
line. This can be avoided by having a space printed before every message
line.

Attached patch changes date_format to the same format as http-error and adds
http-error LogFile to php.conf.
Additionally it adds a new "Parse Errors" category and prints those as well
and begins every message line with a space to avoid Outlook removing "extra
break lines" (this same modification could be applied to http-error, the
code is identical).

Regarding Parse Errors category, I've placed it below warnings but it could
as well be placed above it. Detail < 5 will skip last 2 categories, I can't
really decide which 2 those should be or if another Detail level should be
added...

Regards,
gulikoza

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk

_______________________________________________
Logwatch-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/logwatch-devel
php.diff (application/octet-stream, 2.2 KB)
Index: conf/services/php.conf
===================================================================
--- conf/services/php.conf	(revision 175)
+++ conf/services/php.conf	(working copy)
@@ -21,6 +21,7 @@
 
 # Which logfile group...
 LogFile = php
+LogFile = http-error
 
 # PHP notices should be fixed
 Detail = High
Index: scripts/services/php
===================================================================
--- scripts/services/php	(revision 175)
+++ scripts/services/php	(working copy)
@@ -36,7 +36,7 @@
 use Time::Local;
 use POSIX qw(strftime);
 
-my $date_format = '%d-%b-%Y %H:%M:%S';
+my $date_format = '... %b %d %H:%M:%S %Y';
 my $filter = TimeFilter($date_format);
 my $detail = exists $ENV{'LOGWATCH_DETAIL_LEVEL'} ? $ENV{'LOGWATCH_DETAIL_LEVEL'} : 0;
 
@@ -51,6 +51,7 @@
 # third element: anonymous hash ref (stores message  counts)
 my @message_categories = (['Fatal errors', qr/\] PHP Fatal error: (.*)$/o, {}],
 			  ['Warnings', qr/\] PHP Warning: (.*)$/o, {}],
+			  ['Parse Errors', qr/\] PHP Parse error: (.*)$/o, {}],
 			  ['Notices', qr/\] PHP Notice: (.*)$/o, {}]);
 
 # skipping categories depending on detail level
@@ -63,13 +64,13 @@
     my $line = $_;
     # skipping messages that are not within the requested range
     next unless $line =~ /^\[($filter)\]/o;
-    $1 =~ /(\d+)-(\w+)-(\d+) (\d+):(\d+):(\d+)/;
+    $1 =~ /(\w+) (\w+) (\d+) (\d+):(\d+):(\d+) (\d+)/;
     my $time;
 
     {
 	# timelocal is quite chatty
 	local $SIG{'__WARN__'}  = sub {};
-	$time = timelocal($6, $5, $4, $1, $month2num{$2}, $3-1900);
+	$time = timelocal($6, $5, $4, $3, $month2num{$2}, $7-1900);
     }
 
     foreach my $cur_cat (@message_categories) {
@@ -105,7 +106,7 @@
 
     foreach my $msg (@sorted_msgs) {
 	# grouping messages by number of occurrence
-	print "\n", $msgs->{$msg}->{'count'}, " times:\n" unless $last_count == $msgs->{$msg}->{'count'};
+	print "\n", $msgs->{$msg}->{'count'}, " times:\n " unless $last_count == $msgs->{$msg}->{'count'};
 	my $rms = 0;
 
 
@@ -140,7 +141,7 @@
 	    print strftime($date_format, localtime($msgs->{$msg}->{'first_occurrence'}));
 	}
 
-	print '] ', $msg, "\n";
+	print '] ', $msg, "\n ";
 	$last_count = $msgs->{$msg}->{'count'};
     }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.