Skip to content

Commit

Permalink
Item12023: Update for utf8 core
Browse files Browse the repository at this point in the history
"use utf8" is completely unnecessary.

Read the logfile using utf8 encoding.

Still needs some work for backwards compatibility with non-utf8 core.
  • Loading branch information
gac410 committed Jun 13, 2015
1 parent f91337b commit e2db6dc
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 16 deletions.
12 changes: 7 additions & 5 deletions lib/Foswiki/Logger/LogDispatch.pm
Expand Up @@ -3,7 +3,6 @@ package Foswiki::Logger::LogDispatch;

use strict;
use warnings;
use utf8;

use Assert;

Expand Down Expand Up @@ -301,10 +300,13 @@ sub _flattenLog {

$message =~ s/\001EXT\001/$extra/g;

unless ( utf8::is_utf8($message) ) {
require Encode;
$message = Encode::decode( 'utf-8', $message, 0 );
}
#SMELL: This code isn't right for backwards compatibility.
#
# unless ($Foswiki::UNICODE) {
# unless ( utf8::is_utf8($message) ) {
# require Encode;
# $message = Encode::decode( 'utf-8', $message, 0 );
# }

print STDERR "FLAT MESSAGE: ($message) \n" if TRACE;
return $message;
Expand Down
3 changes: 1 addition & 2 deletions lib/Foswiki/Logger/LogDispatch/EventIterator.pm
Expand Up @@ -3,7 +3,6 @@ package Foswiki::Logger::LogDispatch::EventIterator;

use strict;
use warnings;
use utf8;
use Assert;
use Fcntl qw(:flock);
use Foswiki::Time qw(-nofoswiki);
Expand Down Expand Up @@ -34,7 +33,7 @@ sub hasNext {
next unless scalar(@line) && defined $line[0];
if (
$line[0] =~ s/\s+$this->{_level}\s*$// # test the level
# accept a plain 'old' format date with no level only if reading info (statistics)
# accept a plain 'old' format date with no level only if reading info (statistics)
|| $line[0] =~ /^\d{1,2} [a-z]{3} \d{4}/i
&& $this->{_level} eq 'info'
)
Expand Down
4 changes: 1 addition & 3 deletions lib/Foswiki/Logger/LogDispatch/File.pm
Expand Up @@ -2,7 +2,6 @@
package Foswiki::Logger::LogDispatch::File::EventIterator;
use strict;
use warnings;
use utf8;
use Assert;

use Fcntl qw(:flock);
Expand All @@ -24,7 +23,6 @@ package Foswiki::Logger::LogDispatch::File;

use strict;
use warnings;
use utf8;
use Assert;

=begin TML
Expand Down Expand Up @@ -196,7 +194,7 @@ sub eachEventSince() {
}

my $fh;
if ( open( $fh, '<', $log ) ) {
if ( open( $fh, '<:encoding(utf-8)', $log ) ) {
my $logIt =
new Foswiki::Logger::LogDispatch::File::EventIterator( $fh, $time,
$level );
Expand Down
4 changes: 1 addition & 3 deletions lib/Foswiki/Logger/LogDispatch/FileRolling.pm
Expand Up @@ -2,7 +2,6 @@
package Foswiki::Logger::LogDispatch::FileRolling::EventIterator;
use strict;
use warnings;
use utf8;
use Assert;

use Fcntl qw(:flock);
Expand All @@ -24,7 +23,6 @@ package Foswiki::Logger::LogDispatch::FileRolling;

use strict;
use warnings;
use utf8;
use Assert;

=begin TML
Expand Down Expand Up @@ -259,7 +257,7 @@ sub eachEventSince() {
foreach my $logfile (@logs) {
next unless -r $logfile;
my $fh;
if ( open( $fh, '<', $logfile ) ) {
if ( open( $fh, '<:encoding(utf-8)', $logfile ) ) {
my $logIt =
new Foswiki::Logger::LogDispatch::FileRolling::EventIterator( $fh,
$time, $level );
Expand Down
1 change: 0 additions & 1 deletion lib/Foswiki/Logger/LogDispatch/FileUtil.pm
Expand Up @@ -3,7 +3,6 @@ package Foswiki::Logger::LogDispatch::FileUtil;

use strict;
use warnings;
use utf8;
use Assert;

=begin TML
Expand Down
1 change: 0 additions & 1 deletion lib/Foswiki/Logger/LogDispatch/Screen.pm
Expand Up @@ -3,7 +3,6 @@ package Foswiki::Logger::LogDispatch::Screen;

use strict;
use warnings;
use utf8;
use Assert;

=begin TML
Expand Down
1 change: 0 additions & 1 deletion lib/Foswiki/Logger/LogDispatch/Syslog.pm
Expand Up @@ -3,7 +3,6 @@ package Foswiki::Logger::LogDispatch::Syslog;

use strict;
use warnings;
use utf8;
use Assert;

=begin TML
Expand Down

0 comments on commit e2db6dc

Please sign in to comment.