-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Item10637: Implement an obfuscating logger
This implements http://foswiki.org/Development/SupportStrippingIPsFromLogfiles. git-svn-id: http://svn.foswiki.org/branches/Release01x01@12651 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
- Loading branch information
GeorgeClark
authored and
GeorgeClark
committed
Sep 29, 2011
1 parent
7cf0a5b
commit 2018f03
Showing
2 changed files
with
128 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# See bottom of file for license and copyright information | ||
package Foswiki::Logger::PlainFile::Obfuscating; | ||
|
||
use strict; | ||
use warnings; | ||
use Assert; | ||
|
||
use Foswiki::Logger (); | ||
use Foswiki::Logger::PlainFile (); | ||
use Foswiki::Configure::Load; | ||
use Digest::MD5 qw( md5_hex ); | ||
|
||
our @ISA = ('Foswiki::Logger::PlainFile'); | ||
|
||
=begin TML | ||
---+ package Foswiki::Logger::PlainFile | ||
Plain file implementation of the Foswiki Logger interface. Mostly | ||
compatible with TWiki (and Foswiki 1.0.0) log files, except that dates | ||
are recorded using ISO format, and include the time, and it dies when | ||
a log can't be written (rather than printing a warning). | ||
This logger implementation maps groups of levels to a single logfile, viz. | ||
* =debug= messages are output to $Foswiki::cfg{Log}{Dir}/debug.log | ||
* =info= messages are output to $Foswiki::cfg{Log}{Dir}/events.log | ||
* =warning=, =error=, =critical=, =alert=, =emergency= messages are | ||
output to $Foswiki::cfg{Log}{Dir}/error.log. | ||
* =error=, =critical=, =alert=, and =emergency= messages are also | ||
written to standard error (the webserver log file, usually) | ||
=cut | ||
|
||
sub new { | ||
my $class = shift; | ||
return bless( {}, $class ); | ||
} | ||
|
||
=begin TML | ||
---++ ObjectMethod log($level, @fields) | ||
See Foswiki::Logger for the interface. | ||
=cut | ||
|
||
sub log { | ||
|
||
#my ( $this, $level, @fields ) = @_; | ||
my $this = shift; | ||
|
||
#foreach my $field ( @_ ) { | ||
# print STDERR "field $field \n"; | ||
# } | ||
|
||
unless ( $_[4] =~ /^AUTHENTICATION FAILURE/ ) { | ||
|
||
if ( $Foswiki::cfg{Log}{Obfuscating}{MaskIP} ) { | ||
$_[5] = 'x.x.x.x'; | ||
} | ||
else { | ||
my $md5hex = md5_hex( $_[5] ); | ||
$_[5] = | ||
hex( substr( $md5hex, 0, 2 ) ) . '.' | ||
. hex( substr( $md5hex, 2, 2 ) ) . '.' | ||
. hex( substr( $md5hex, 4, 2 ) ) . '.' | ||
. hex( substr( $md5hex, 6, 2 ) ); | ||
} | ||
} | ||
|
||
$this->SUPER::log(@_); | ||
} | ||
|
||
=begin TML | ||
---++ StaticMethod eachEventSince($time, $level) -> $iterator | ||
See Foswiki::Logger for the interface. | ||
This logger implementation maps groups of levels to a single logfile, viz. | ||
* =info= messages are output together. | ||
* =warning=, =error=, =critical=, =alert=, =emergency= messages are | ||
output together. | ||
This method cannot | ||
=cut | ||
|
||
sub eachEventSince { | ||
|
||
#my ( $this, $time, $level ) = @_; | ||
my $this = shift; | ||
$this->SUPER::eachEventSince(@_); | ||
} | ||
|
||
1; | ||
__END__ | ||
Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/ | ||
Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors | ||
are listed in the AUTHORS file in the root of this distribution. | ||
NOTE: Please extend that file, not this notice. | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
as published by the Free Software Foundation; either version 2 | ||
of the License, or (at your option) any later version. For | ||
more details read LICENSE in the root of this distribution. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
As per the GPL, removal of this notice is prohibited. |