-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enh(log_v2): new logging engine in centengine
enh(engine/log_v2): new possibility to enable/disabled old/new logs enh(log_v2): add broker sink log and unit test for new loggers enh(log_v2): change some logs info on debug enh(log_v2): duplicate hold log with new loggers enh(log_v2): add new test robot REFS: MON-11583 REFS: MON-11866 REFS: MON-11867
- Loading branch information
Showing
98 changed files
with
6,770 additions
and
2,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
67
centreon-engine/inc/com/centreon/engine/logging/broker_sink.hh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.