Slightly more efficient logPrint. Don't create the message string unless it is going to be used

This commit is contained in:
Isaac Connor 2018-06-08 14:18:38 -04:00
parent d589d31f74
commit 5cdbc85dcc
1 changed files with 21 additions and 21 deletions

View File

@ -529,29 +529,29 @@ sub logPrint {
if ( $level <= $this->{effectiveLevel} ) {
$string =~ s/[\r\n]+$//g;
my $code = $codes{$level};
if ( $level <= $this->{syslogLevel} ) {
syslog($priorities{$level}, $codes{$level}.' [%s]', $string);
}
my ($seconds, $microseconds) = gettimeofday();
my $message = sprintf(
'%s.%06d %s[%d].%s [%s]'
, strftime('%x %H:%M:%S', localtime($seconds))
, $microseconds
, $this->{id}
, $$
, $code
, $string
);
if ( $this->{trace} ) {
$message = Carp::shortmess($message);
} else {
$message = $message."\n";
if ( $level <= $this->{fileLevel} or $level <= $this->{termLevel} ) {
my $message = sprintf(
'%s.%06d %s[%d].%s [%s]'
, strftime('%x %H:%M:%S', localtime($seconds))
, $microseconds
, $this->{id}
, $$
, $codes{$level}
, $string
);
if ( $this->{trace} ) {
$message = Carp::shortmess($message);
} else {
$message = $message."\n";
}
print($LOGFILE $message) if $level <= $this->{fileLevel};
print(STDERR $message) if $level <= $this->{termLevel};
}
if ( $level <= $this->{syslogLevel} ) {
syslog($priorities{$level}, $code.' [%s]', $string);
}
print($LOGFILE $message) if $level <= $this->{fileLevel};
print(STDERR $message) if $level <= $this->{termLevel};
if ( $level <= $this->{databaseLevel} ) {
if ( ! ( $this->{dbh} and $this->{dbh}->ping() ) ) {
@ -575,7 +575,7 @@ sub logPrint {
, $this->{id}
, $$
, $level
, $code
, $codes{$level}
, $string
, $this->{fileName}
);