diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 0feefb60c..ff072fe23 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.5.21 + - improved debug messages for sql queries - fixed: Custom library directories don't override WebGUI core modules - Changed update() so that it only updates fields passed in, and the defaults for assets are processed in addRevision() instead. diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 52749f09a..9058bf7b5 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -301,6 +301,19 @@ sub getId { #------------------------------------------------------------------- +=head2 hasSettings + +Checks if the settings have been initialized yet + +=cut + +sub hasSettings { + my $self = shift; + return exists $self->{_setting}; +} + +#------------------------------------------------------------------- + =head2 http ( ) Returns a reference to the WebGUI::Session::Http object. diff --git a/lib/WebGUI/Session/ErrorHandler.pm b/lib/WebGUI/Session/ErrorHandler.pm index 19a5820c3..1e94545bf 100644 --- a/lib/WebGUI/Session/ErrorHandler.pm +++ b/lib/WebGUI/Session/ErrorHandler.pm @@ -110,6 +110,7 @@ Returns true if the user meets the condition to see debugging information and de sub canShowDebug { my $self = shift; + return 0 unless ($self->session->hasSettings); return 0 unless ($self->session->setting->get("showDebug")); return 0 unless (substr($self->session->http->getMimeType(),0,9) eq "text/html"); return $self->canShowBasedOnIP('debugIp'); @@ -324,21 +325,28 @@ A sql statement string. sub query { my $self = shift; + return unless $self->canShowDebug || $self->getLogger->is_debug; my $query = shift; my $placeholders = shift; $self->{_queryCount}++; my $plac; if (defined $placeholders and ref $placeholders eq "ARRAY" && scalar(@{$placeholders})) { - $plac = "\n with placeholders: [" . join(', ', map { - defined $_ ? "'$_'" : 'undef'; - } @$placeholders) . ']'; + $plac = "\n with placeholders: " . JSON->new->encode($placeholders); } else { $plac = ''; } - local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1; + my $depth = 0; + while (my ($caller) = caller(++$depth)) { + last + unless $caller eq __PACKAGE__ || $caller =~ /^WebGUI::SQL:?/; + } + $query =~ s/^/ /gms; - $self->debug("query ".$self->{_queryCount}.":\n" . $query . $plac); + $self->{_debug_debug} .= sprintf "query %d - %s(%s) :\n%s%s\n", + $self->{_queryCount}, (caller($depth + 1))[3,2], $query, $plac; + local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + $depth + 1; + $self->getLogger->debug("query $self->{_queryCount}:\n$query$plac"); } @@ -387,7 +395,7 @@ errors, sql queries and form data. sub showDebug { my $self = shift; - my $output = '