improved debug messages for sql queries
This commit is contained in:
parent
ce230795aa
commit
00fcdf40df
3 changed files with 29 additions and 7 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
7.5.21
|
7.5.21
|
||||||
|
- improved debug messages for sql queries
|
||||||
- fixed: Custom library directories don't override WebGUI core modules
|
- fixed: Custom library directories don't override WebGUI core modules
|
||||||
- Changed update() so that it only updates fields passed in, and the defaults
|
- Changed update() so that it only updates fields passed in, and the defaults
|
||||||
for assets are processed in addRevision() instead.
|
for assets are processed in addRevision() instead.
|
||||||
|
|
|
||||||
|
|
@ -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 ( )
|
=head2 http ( )
|
||||||
|
|
||||||
Returns a reference to the WebGUI::Session::Http object.
|
Returns a reference to the WebGUI::Session::Http object.
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,7 @@ Returns true if the user meets the condition to see debugging information and de
|
||||||
|
|
||||||
sub canShowDebug {
|
sub canShowDebug {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
return 0 unless ($self->session->hasSettings);
|
||||||
return 0 unless ($self->session->setting->get("showDebug"));
|
return 0 unless ($self->session->setting->get("showDebug"));
|
||||||
return 0 unless (substr($self->session->http->getMimeType(),0,9) eq "text/html");
|
return 0 unless (substr($self->session->http->getMimeType(),0,9) eq "text/html");
|
||||||
return $self->canShowBasedOnIP('debugIp');
|
return $self->canShowBasedOnIP('debugIp');
|
||||||
|
|
@ -324,21 +325,28 @@ A sql statement string.
|
||||||
|
|
||||||
sub query {
|
sub query {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
return unless $self->canShowDebug || $self->getLogger->is_debug;
|
||||||
my $query = shift;
|
my $query = shift;
|
||||||
my $placeholders = shift;
|
my $placeholders = shift;
|
||||||
$self->{_queryCount}++;
|
$self->{_queryCount}++;
|
||||||
my $plac;
|
my $plac;
|
||||||
if (defined $placeholders and ref $placeholders eq "ARRAY" && scalar(@{$placeholders})) {
|
if (defined $placeholders and ref $placeholders eq "ARRAY" && scalar(@{$placeholders})) {
|
||||||
$plac = "\n with placeholders: [" . join(', ', map {
|
$plac = "\n with placeholders: " . JSON->new->encode($placeholders);
|
||||||
defined $_ ? "'$_'" : 'undef';
|
|
||||||
} @$placeholders) . ']';
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$plac = '';
|
$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;
|
$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 {
|
sub showDebug {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $output = '<div style="text-align: left;color: #000000; white-space: pre; float: left;">';
|
my $output = '<div class="webgui-debug" style="text-align: left;color: #000000; white-space: pre; float: left">';
|
||||||
my $text = $self->{_debug_error};
|
my $text = $self->{_debug_error};
|
||||||
$text = encode_entities($text);
|
$text = encode_entities($text);
|
||||||
$output .= '<div style="background-color: #800000;color: #ffffff">'.$text."</div>";
|
$output .= '<div style="background-color: #800000;color: #ffffff">'.$text."</div>";
|
||||||
|
|
@ -402,7 +410,7 @@ sub showDebug {
|
||||||
if exists $form{password};
|
if exists $form{password};
|
||||||
$form{identifier} = "*******"
|
$form{identifier} = "*******"
|
||||||
if exists $form{identifier};
|
if exists $form{identifier};
|
||||||
$text = JSON->new->utf8->pretty->encode(\%form);
|
$text = JSON->new->pretty->encode(\%form);
|
||||||
$text = encode_entities($text);
|
$text = encode_entities($text);
|
||||||
$output .= '<div style="background-color: #aaaaee">'.$text."</div>";
|
$output .= '<div style="background-color: #aaaaee">'.$text."</div>";
|
||||||
$text = $self->{_debug_debug};
|
$text = $self->{_debug_debug};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue