MT#59478 improve MSG, LOG log string data storing

* $c->error array now contains the $message as the first element
  instead, so that it's possible to obtain all the error data in
  the code when fetching it from @{$c->error}. the first element
  is not logged in the error log.
* api_response $c->response_body part is now stored in MSG= and
  possible errors / other log data is now stored in LOG= to:
  - reduce amount of log lines when an API error response occurs
    from 2 to 1
  - the message part usually contains either HTTP response
    message (e.g. Internal Server Error) or a validation message
    string, so it belongs to the MSG= part of the log line, where
    as the internal log data is more related to the LOG= part
  - both MSG= and LOG= parts are escaped for GDPR related obfuscation
* Utils::Messag::info(): $msg is now also obfuscated if it's detected
  as a reference (also because logging is moved for the API part to
  $msg), as well as truncated for possible new-line char and
  white-spaces.

Change-Id: I3b670b2251ec3060037ed6863f18d95975120b8d
mr12.4
Kirill Solomko 1 year ago
parent 9dbd6b0e88
commit 9d598d4502

@ -354,7 +354,7 @@ sub error {
# message -> returned as HTTP message in the reply
# errors -> contain errors for internal logging, last element often contains a DBIx exception
$c->error(['', @errors]);
$c->error([$message, @errors]);
$c->response->content_type('application/json');
$c->response->status($code);
@ -1060,15 +1060,9 @@ sub log_response {
$c->response->content_type('')
if $c->response->content_type =~ qr'text/html'; # stupid RenderView getting in the way
my $rc = '';
my $errors = '';
if ($c->has_errors) {
my $msg = join ', ', splice @{$c->error}, 1;
if ($msg) {
$rc = NGCP::Panel::Utils::Message::error(
c => $c,
type => 'api_response',
log => $msg,
);
}
$errors = join ', ', splice @{$c->error}, 1;
$c->clear_errors;
}
my ($response_body, $params_data) = $self->filter_log_response(
@ -1079,7 +1073,8 @@ sub log_response {
NGCP::Panel::Utils::Message::info(
c => $c,
type => 'api_response',
log => $c->qs($response_body),
desc => $c->qs($response_body),
log => $c->qs($errors // ''),
data => $params_data,
);
}

@ -224,6 +224,17 @@ sub info {
my $usr_type = 'info';
my $usr_text = $desc;
if (defined $msg) {
if (ref($msg)) {
$msg = $c->qs(Data::Dumper->new([ obfuscate_password_fields($c,$log) ])
->Terse(1)
->Maxdepth(1)
->Dump);
}
$msg =~ s/\n//g;
$msg =~ s/\s+/ /g;
}
if (defined $log) {
if (ref($log)) {
$log_msg = $c->qs(Data::Dumper->new([ obfuscate_password_fields($c,$log) ])

Loading…
Cancel
Save