From 072caebf05b59b8b74f7f5699d99129834bab616 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 5 Jan 2017 12:55:31 +0100 Subject: [PATCH] =?utf8?q?LXDebug:=20Flag=20SHOW=5FCALLER=20f=C3=BCr=20Aus?= =?utf8?q?gabe=20Dateiname:Zeilennummer=20bei=20message()=20&=20dump()?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/LXDebug.pm | 20 +++++++++++++++++--- config/kivitendo.conf.default | 2 ++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/SL/LXDebug.pm b/SL/LXDebug.pm index d3ab1e53a..b62b2da0f 100644 --- a/SL/LXDebug.pm +++ b/SL/LXDebug.pm @@ -11,7 +11,8 @@ use constant REQUEST_TIMER => 1 << 6; use constant REQUEST => 1 << 7; use constant WARN => 1 << 8; use constant TRACE2 => 1 << 9; -use constant ALL => (1 << 10) - 1; +use constant SHOW_CALLER => 1 << 10; +use constant ALL => (1 << 11) - 1; use constant DEVEL => INFO | DEBUG1 | QUERY | TRACE | BACKTRACE_ON_ERROR | REQUEST_TIMER; use constant FILE_TARGET => 0; @@ -144,7 +145,10 @@ sub message { no warnings; my ($self, $level, $message) = @_; - $self->_write(level2string($level), $message) if (($self->{"level"} | $global_level) & $level || !$level); + my $show_caller = ($level | $global_level) & SHOW_CALLER(); + $level &= ~SHOW_CALLER(); + + $self->_write(level2string($level), $message, show_caller => $show_caller) if (($self->{"level"} | $global_level) & $level || !$level); } sub warn { no warnings; @@ -260,7 +264,17 @@ sub is_tracing_enabled { sub _write { no warnings; - my ($self, $prefix, $message) = @_; + my ($self, $prefix, $message, %options) = @_; + + my @prefixes = ($prefix); + + if ($options{show_caller}) { + my ($package, $filename, $line, $subroutine) = caller(1); + push @prefixes, "${filename}:${line}"; + } + + $prefix = join ' ', grep { $_ } @prefixes; + my @now = gettimeofday(); my $date = strftime("%Y-%m-%d %H:%M:%S." . sprintf('%03d', int($now[1] / 1000)) . " $$ [" . getpid() . "] ${prefix}: ", localtime($now[0])); local *FILE; diff --git a/config/kivitendo.conf.default b/config/kivitendo.conf.default index 99d1ea3c1..7f5b626b0 100644 --- a/config/kivitendo.conf.default +++ b/config/kivitendo.conf.default @@ -294,6 +294,8 @@ dbix_log4perl_config = log4perl.logger = FATAL, LOGFILE # REQUEST - Log each request. Careful! Passwords get filtered, but # there may be confidential information being logged here # WARN - warnings +# SHOW_CALLER - include the file name & line number from where a call +# to "message" or "dump" was called # ALL - all possible debug messages # # DEVEL - sames as "INFO QUERY TRACE BACKTRACE_ON_ERROR REQUEST_TIMER" -- 2.20.1