https://www.mediawiki.org/wiki/Special:Code/MediaWiki/115410
Revision: 115410
Author: hashar
Date: 2012-05-21 15:17:22 +0000 (Mon, 21 May 2012)
Log Message:
-----------
split messages per bugzilla product
Given the X-Bugzilla-Product, a hardcoded hash map the product name to a
filename. The default directory logs are written to is /var/wikibugs
which can be overridden using --dir.
The 'default' product is the fallback and will log to a new file named
mediawiki.log. The old wikibugs.log filename is no more used.
Please note that the ircecho installation on mchenry will need to be
updated to read from the new log files.
With --stdout, message will be printed to you the Product name being
prefixed and separated with a pipe '|'.
Modified Paths:
--------------
trunk/tools/wikibugs/wikibugs
Modified: trunk/tools/wikibugs/wikibugs
===================================================================
--- trunk/tools/wikibugs/wikibugs 2012-05-21 15:17:20 UTC (rev 115409)
+++ trunk/tools/wikibugs/wikibugs 2012-05-21 15:17:22 UTC (rev 115410)
@@ -23,25 +23,28 @@
=head1 SYNOPSIS
-wikibugs [options]
+wikibugs [--dir|--stdout] [other options]
Options:
--help brief help message
+ --dir Directory to write logfiles to
+
+ --stdout Write every message to stdout instead of to files,
+ messages will be prefixed with Bugzilla product name.
+ Takeover --dir.
+
--debug Write to STDERR some debugging messages
- --stdout Write every message to stdout instead of files
- usefull for debugging purposes.
-
=cut
# Array holding command line options
my %opt = (
- 'to' => '/var/wikibugs/wikibugs.log',
+ 'dir' => '/var/wikibugs',
'debug' => 0,
);
-GetOptions( \%opt, 'debug', 'help', 'stdout' ) or pod2usage(2);
+GetOptions( \%opt, 'debug', 'help', 'dir=s', 'stdout' ) or pod2usage(2);
pod2usage(1) if $opt{'help'};
$/ = undef;
@@ -71,6 +74,21 @@
'REMIND' => "\00306(REMIND)\003"
};
+# Map Products to a log file https://bugzilla.wikimedia.org/enter_bug.cgi
+# The special 'default' product is where message will be written to if no
+# product is found.
+# Whenever adding a new file here, you will have to update puppet configuration
+# so the wikibugs ircecho script read from them and send the message to the
+# appropriate channel.
+my $logFile = {
+ 'Wikimedia Labs' => $opt{'dir'} . '/wikimedia-labs.log',
+ 'Wikimedia Mobile' => $opt{'dir'} . '/wikimedia-mobile.log',
+ 'Wikipedia App' => $opt{'dir'} . '/wikimedia-mobile.log',
+ 'Wiktionary App' => $opt{'dir'} . '/wikimedia-mobile.log',
+
+ 'default' => $opt{'dir'} . '/mediawiki.log',
+};
+
# Parse a received email
use Email::MIME;
my $mail = Email::MIME->new( $contents );
@@ -202,11 +220,19 @@
if ($output) {
if( $opt{'stdout'} ) {
- print $output;
+ print $product . "|" . $output;
} else {
- open (OUT, ">>/var/wikibugs/wikibugs.log");
- print OUT $output;
- close OUT;
+ if( exists $logFile->{$product} ) {
+ open (OUT, '>>' . $logFile->{$product} )
+ or print STDERR "Failed to open for writing
'$logFile->{$product}'\n";
+ }
+ unless( fileno OUT ) {
+ open (OUT, '>>' . $logFile->{'default'} )
+ or print STDERR "Failed to open for writing
'$logFile->{'default'}'\n";
+ }
+
+ print OUT $output;
+ close OUT;
}
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs