Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mon 11583 logv2 engine #114

Merged
merged 31 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
73e23f5
fix(broker/core): global_lock no more used
bouda1 Oct 26, 2021
10cf681
cleanup(engine): logger changed into engine_logger
bouda1 Oct 15, 2021
b01a701
enh(log_v2): new logging engine in centengine
bouda1 Oct 16, 2021
246a84f
enh(engine::main): first new log_v2 implementation
bouda1 Oct 16, 2021
b0f4201
enh(engine/log_v2): new log class for engine
bouda1 Oct 16, 2021
2fa6a56
wip(log_v2): work on engine new logger
bouda1 Oct 20, 2021
c8939eb
enh(engine/log_v2): new possibility to enable/disabled old/new logs
bouda1 Oct 27, 2021
bda780f
enh(engine/log_v2): debug log first step
bouda1 Oct 27, 2021
0ae8843
enh(engine/log_v2): a little more far in new logs
bouda1 Oct 29, 2021
90b5772
enh(engine::main): first new log_v2 implementation
bouda1 Oct 16, 2021
03ba03d
enh(engine/log_v2): new log class for engine
bouda1 Oct 16, 2021
8a2fd7a
wip(log_v2): work on engine new logger
bouda1 Oct 20, 2021
b177c33
enh(engine/log_v2): new possibility to enable/disabled old/new logs
bouda1 Oct 27, 2021
5976c33
enh(engine/log_v2): debug log first step
bouda1 Oct 27, 2021
f5b480c
enh(engine/log_v2): a little more far in new logs
bouda1 Oct 29, 2021
fcfff6a
wip(log_v2): work on send log to broker
rem31 Dec 7, 2021
e5c9bdc
enh(log_v2): add broker sink log and unit test for new loggers
rem31 Dec 9, 2021
293324e
enh(log_v2): add broker sink log and unit test for new loggers
rem31 Dec 9, 2021
9ab488c
fix(tests): update the test to work on CI
rem31 Dec 9, 2021
d8ba3fe
enh(log_v2): duplicate hold log with new loggers
rem31 Dec 23, 2021
b2f45b8
revert(build): enable subdirectory conf
rem31 Dec 23, 2021
55e0f40
enh(log_v2): add new test robot
rem31 Jan 5, 2022
0ea6ea2
enh(log_v2): change some logs info on debug
rem31 Jan 5, 2022
db4d3ca
Merge branch 'develop' into MON-11583-logv2-engine
rem31 Jan 8, 2022
0aeddf3
enh(log_v2): change for comments
rem31 Jan 8, 2022
d78289d
enh(log_v2): change for comments
rem31 Jan 11, 2022
9f778af
enh(log_v2): change for comments
rem31 Jan 12, 2022
02d599f
enh(log_v2): new test check all log are duplicate in tables logs
rem31 Jan 13, 2022
4aae018
enh(log_v2): change for comments
rem31 Jan 13, 2022
d4e2df8
enh(log_v2): new test check all log are duplicate in logfile
rem31 Jan 17, 2022
d3ee5d4
enh(log_v2): change for comments
rem31 Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions centreon-clib/test/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,10 @@ TEST(ClibLogging, TempLoggerCtor) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(0, 0) << "Centreon Clib test";
ASSERT_EQ(obj->get_nb_call(), 0);
ASSERT_EQ(obj->get_nb_call(), 0u);

temp_logger(1, 0) << "Centreon Clib test";
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand Down Expand Up @@ -524,7 +524,7 @@ TEST(ClibLogging, TempLoggerLogChar) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << 'c';
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -534,7 +534,7 @@ TEST(ClibLogging, TempLoggerLogDouble) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << double(42.42);
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -544,7 +544,7 @@ TEST(ClibLogging, TempLoggerLogInt) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << int(42);
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -554,7 +554,7 @@ TEST(ClibLogging, TempLoggerLogLong) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << 42L;
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -564,7 +564,7 @@ TEST(ClibLogging, TempLoggerLogLongLong) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << 42LL;
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -574,7 +574,7 @@ TEST(ClibLogging, TempLoggerLogPVoid) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << obj.get();
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -584,7 +584,7 @@ TEST(ClibLogging, TempLoggerLogStdString) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << std::string("Centreon Clib test");
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -594,7 +594,7 @@ TEST(ClibLogging, TempLoggerLogString) {
auto id = e.add(obj.get(), 3, 0);

temp_logger(1, 0) << "Centreon Clib test";
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -605,7 +605,7 @@ TEST(ClibLogging, TempLoggerLogUint) {

unsigned int ui(42);
temp_logger(1, 0) << ui;
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -616,7 +616,7 @@ TEST(ClibLogging, TempLoggerLogULong) {

unsigned long ul(42);
temp_logger(1, 0) << ul;
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}

Expand All @@ -627,6 +627,6 @@ TEST(ClibLogging, TempLoggerLogULongLong) {

unsigned long long ull(42);
temp_logger(1, 0) << ull;
ASSERT_EQ(obj->get_nb_call(), 1);
ASSERT_EQ(obj->get_nb_call(), 1u);
e.remove(id);
}
3 changes: 3 additions & 0 deletions centreon-engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ set(
"${SRC_DIR}/hostdependency.cc"
"${SRC_DIR}/hostescalation.cc"
"${SRC_DIR}/hostgroup.cc"
"${SRC_DIR}/log_v2.cc"
"${SRC_DIR}/macros.cc"
"${SRC_DIR}/nebmods.cc"
"${SRC_DIR}/notification.cc"
Expand Down Expand Up @@ -485,6 +486,7 @@ set(
"${INC_DIR}/com/centreon/engine/hostdependency.hh"
"${INC_DIR}/com/centreon/engine/hostescalation.hh"
"${INC_DIR}/com/centreon/engine/hostgroup.hh"
"${INC_DIR}/com/centreon/engine/log_v2.hh"
"${INC_DIR}/com/centreon/engine/logging.hh"
"${INC_DIR}/com/centreon/engine/macros.hh"
"${INC_DIR}/com/centreon/engine/nebcallbacks.hh"
Expand Down Expand Up @@ -544,6 +546,7 @@ target_link_libraries(cce_core ${nlohmann_json_LIBS}
${SOCKET_LIBRARIES}
centreon_clib
${fmt_LIBRARIES}
${spdlog_LIBS}
)

# centengine target.
Expand Down
52 changes: 50 additions & 2 deletions centreon-engine/inc/com/centreon/engine/configuration/state.hh
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,38 @@ class state {
void use_setpgid(bool value);
bool use_syslog() const noexcept;
void use_syslog(bool value);
bool log_v2_enabled() const noexcept;
void log_v2_enabled(bool value);
bool log_legacy_enabled() const noexcept;
void log_legacy_enabled(bool value);
std::string const& log_v2_logger() const noexcept;
void log_v2_logger(std::string const& value);
std::string const& log_level_functions() const noexcept;
void log_level_functions(std::string const& value);
std::string const& log_level_config() const noexcept;
void log_level_config(std::string const& value);
std::string const& log_level_events() const noexcept;
void log_level_events(std::string const& value);
std::string const& log_level_checks() const noexcept;
void log_level_checks(std::string const& value);
std::string const& log_level_notifications() const noexcept;
void log_level_notifications(std::string const& value);
std::string const& log_level_eventbroker() const noexcept;
void log_level_eventbroker(std::string const& value);
std::string const& log_level_external_command() const noexcept;
void log_level_external_command(std::string const& value);
std::string const& log_level_commands() const noexcept;
void log_level_commands(std::string const& value);
std::string const& log_level_downtimes() const noexcept;
void log_level_downtimes(std::string const& value);
std::string const& log_level_comments() const noexcept;
void log_level_comments(std::string const& value);
std::string const& log_level_macros() const noexcept;
void log_level_macros(std::string const& value);
std::string const& log_level_process() const noexcept;
void log_level_process(std::string const& value);
std::string const& log_level_runtime() const noexcept;
void log_level_runtime(std::string const& value);
std::string const& use_timezone() const noexcept;
void use_timezone(std::string const& value);
bool use_true_regexp_matching() const noexcept;
Expand Down Expand Up @@ -449,7 +481,7 @@ class state {
return (false);
(obj.*ptr)(val);
} catch (std::exception const& e) {
logger(logging::log_config_error, logging::basic) << e.what();
engine_logger(logging::log_config_error, logging::basic) << e.what();
return (false);
}
return (true);
Expand All @@ -462,7 +494,7 @@ class state {
try {
(obj.*ptr)(value);
} catch (std::exception const& e) {
logger(logging::log_config_error, logging::basic) << e.what();
engine_logger(logging::log_config_error, logging::basic) << e.what();
return (false);
}
return (true);
Expand Down Expand Up @@ -604,6 +636,22 @@ class state {
bool _use_retained_scheduling_info;
bool _use_setpgid;
bool _use_syslog;
bool _log_v2_enabled;
bool _log_legacy_enabled;
std::string _log_v2_logger;
std::string _log_level_functions;
std::string _log_level_config;
std::string _log_level_events;
std::string _log_level_checks;
std::string _log_level_notifications;
std::string _log_level_eventbroker;
std::string _log_level_external_command;
std::string _log_level_commands;
std::string _log_level_downtimes;
std::string _log_level_comments;
std::string _log_level_macros;
std::string _log_level_process;
std::string _log_level_runtime;
std::string _use_timezone;
bool _use_true_regexp_matching;
};
Expand Down
6 changes: 0 additions & 6 deletions centreon-engine/inc/com/centreon/engine/contact.hh
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,6 @@ std::shared_ptr<com::centreon::engine::contact> add_contact(
int retain_status_information,
int retain_nonstatus_information);

// bool operator==(
// com::centreon::engine::contact const& obj1,
// com::centreon::engine::contact const& obj2) throw ();
// bool operator!=(
// com::centreon::engine::contact const& obj1,
// com::centreon::engine::contact const& obj2) throw ();
std::ostream& operator<<(std::ostream& os,
com::centreon::engine::contact const& obj);
std::ostream& operator<<(std::ostream& os, contact_map_unsafe const& obj);
Expand Down
71 changes: 71 additions & 0 deletions centreon-engine/inc/com/centreon/engine/log_v2.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
** Copyright 2021 Centreon
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
**
** For more information : contact@centreon.com
*/
#ifndef CCE_LOG_V2_HH
#define CCE_LOG_V2_HH

#include <spdlog/common.h>
#include <spdlog/spdlog.h>

#include <array>
#include <map>
#include <memory>

#include "com/centreon/engine/configuration/state.hh"
#include "com/centreon/engine/namespace.hh"

CCE_BEGIN()
class log_v2 {
std::string _log_name;
std::shared_ptr<spdlog::logger> _config_log;
std::shared_ptr<spdlog::logger> _functions_log;
std::shared_ptr<spdlog::logger> _events_log;
std::shared_ptr<spdlog::logger> _checks_log;
std::shared_ptr<spdlog::logger> _notifications_log;
std::shared_ptr<spdlog::logger> _eventbroker_log;
std::shared_ptr<spdlog::logger> _external_command_log;
std::shared_ptr<spdlog::logger> _commands_log;
std::shared_ptr<spdlog::logger> _downtimes_log;
std::shared_ptr<spdlog::logger> _comments_log;
std::shared_ptr<spdlog::logger> _macros_log;
std::shared_ptr<spdlog::logger> _process_log;
std::shared_ptr<spdlog::logger> _runtime_log;

log_v2();
~log_v2() noexcept = default;

public:
void apply(const configuration::state& config);
static bool contains_level(const std::string& level_name);
static log_v2& instance();
static std::shared_ptr<spdlog::logger> functions();
static std::shared_ptr<spdlog::logger> config();
static std::shared_ptr<spdlog::logger> events();
static std::shared_ptr<spdlog::logger> checks();
static std::shared_ptr<spdlog::logger> notifications();
static std::shared_ptr<spdlog::logger> eventbroker();
static std::shared_ptr<spdlog::logger> external_command();
static std::shared_ptr<spdlog::logger> commands();
static std::shared_ptr<spdlog::logger> downtimes();
static std::shared_ptr<spdlog::logger> comments();
static std::shared_ptr<spdlog::logger> macros();
static std::shared_ptr<spdlog::logger> process();
static std::shared_ptr<spdlog::logger> runtime();
};
CCE_END()

#endif /* !CCE_LOG_V2_HH */
67 changes: 67 additions & 0 deletions centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
** Copyright 2011-2021 Centreon
**
** This file is part of Centreon Engine.
**
** Centreon Engine is free software: you can redistribute it and/or
** modify it under the terms of the GNU General Public License version 2
** as published by the Free Software Foundation.
**
** Centreon Engine is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with Centreon Engine. If not, see
** <http://www.gnu.org/licenses/>.
*/
#ifndef CCE_LOGGING_BROKER_SINK_HH
#define CCE_LOGGING_BROKER_SINK_HH
#include <spdlog/details/fmt_helper.h>
#include <spdlog/sinks/base_sink.h>
#include <mutex>
#include "com/centreon/engine/broker.hh"
#include "com/centreon/engine/logging/broker.hh"
#include "com/centreon/engine/logging/logger.hh"
#include "com/centreon/engine/namespace.hh"
#include "com/centreon/engine/nebstructs.hh"
#include "com/centreon/unique_array_ptr.hh"
#include "spdlog/details/null_mutex.h"
CCE_BEGIN()

namespace logging {
template <typename Mutex>
class broker_sink : public spdlog::sinks::base_sink<Mutex> {
protected:
void sink_it_(const spdlog::details::log_msg& msg) override {
// log_msg is a struct containing the log entry info like level, timestamp,
// thread id etc. msg.raw contains pre formatted log

// If needed (very likely but not mandatory), the sink formats the message
// before sending it to its final destination:
if (this->should_log(msg.level)) {
std::string message{fmt::to_string(msg.payload)};
nebstruct_log_data ds{.type = NEBTYPE_LOG_DATA,
.flags = NEBFLAG_NONE,
.attr = NEBATTR_NONE,
.timestamp = get_broker_timestamp(nullptr),
.entry_time = time(nullptr),
.data_type = logging::log_all,
.data = message.c_str()};

// Make callbacks.
neb_make_callbacks(NEBCALLBACK_LOG_DATA, &ds);
}
}

void flush_() override {}
};

using broker_sink_mt = broker_sink<std::mutex>;
using broker_sink_st = broker_sink<spdlog::details::null_mutex>;

} // namespace logging
CCE_END()

#endif // !CCE_LOGGING_BROKER_SINK_HH
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ enum verbosity_level { basic = 0u, more = 1u, most = 2u };

CCE_END()

#define logger(type, verbose) \
#define engine_logger(type, verbose) \
for (unsigned int __com_centreon_engine_logging_define_ui(0); \
!__com_centreon_engine_logging_define_ui && \
com::centreon::logging::engine::instance().is_log(type, verbose); \
Expand Down
2 changes: 1 addition & 1 deletion centreon-engine/inc/com/centreon/engine/nebstructs.hh
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ typedef struct nebstruct_log_struct {

time_t entry_time;
int data_type;
char* data;
const char* data;
} nebstruct_log_data;

/* Module data structure. */
Expand Down
Loading