From 0bb4f114674a8a7701a7e13ec633d039734a218f Mon Sep 17 00:00:00 2001 From: Evan Adam Date: Tue, 26 Nov 2024 10:55:54 +0100 Subject: [PATCH] tests(gorgone): use gorgone log format to fix automated tests Refs:MON-106121 --- gorgone/tests/robot/resources/LogResearch.py | 2 +- gorgone/tests/robot/resources/resources.resource | 2 +- perl-libs/lib/centreon/common/logger.pm | 10 ++++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gorgone/tests/robot/resources/LogResearch.py b/gorgone/tests/robot/resources/LogResearch.py index de32f9f8e0e..fe272a870c0 100644 --- a/gorgone/tests/robot/resources/LogResearch.py +++ b/gorgone/tests/robot/resources/LogResearch.py @@ -129,7 +129,7 @@ def ctn_find_in_log(log: str, date, content, regex=False): def ctn_extract_date_from_log(line: str): - p = re.compile(r"^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\]") + p = re.compile(r"^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})") m = p.match(line) if m is None: return None diff --git a/gorgone/tests/robot/resources/resources.resource b/gorgone/tests/robot/resources/resources.resource index e585dcca14b..bfe0d68a562 100644 --- a/gorgone/tests/robot/resources/resources.resource +++ b/gorgone/tests/robot/resources/resources.resource @@ -189,7 +189,7 @@ Wait Until Port Is Bind Ctn Check No Error In Logs [Arguments] ${gorgone_id} - ${cmd}= Set Variable grep -vP '^\\[\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}\\] ' /var/log/centreon-gorgone/${gorgone_id}/gorgoned.log + ${cmd}= Set Variable grep -vP '^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2} ' /var/log/centreon-gorgone/${gorgone_id}/gorgoned.log Log To Console \n\n${cmd}\n\n ${log_line_wrong} RUN ${cmd} diff --git a/perl-libs/lib/centreon/common/logger.pm b/perl-libs/lib/centreon/common/logger.pm index f3faaaca1d9..db5441e006a 100644 --- a/perl-libs/lib/centreon/common/logger.pm +++ b/perl-libs/lib/centreon/common/logger.pm @@ -234,12 +234,14 @@ sub writeLog($$$%) { # do nothing if the configured severity does not imply logging this message return if ($self->{severity} < $severity); + if (length($msg) > 20000) { + $msg = substr($msg, 0, 20000) . '...'; + } + $msg = ($self->withpid()) ? "$$ - $msg" : $msg; - $msg = ($self->withpid()) ? "[$$] $msg" : $msg; - - my $datedmsg = "[" . $human_severities{$severity} . "] " . $msg . "\n"; + my $datedmsg = $human_severities{$severity} . " - " . $msg . "\n"; if ($self->withdate()) { - $datedmsg = "[" . $self->get_date . "] " . $datedmsg; + $datedmsg = $self->get_date . " - " . $datedmsg; } if ($self->{log_mode} == 1 and defined($self->{filehandler})) { print {$self->{filehandler}} $datedmsg;