-
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.
fix(common/log_v2): When apply() called, the log file is reopened (#1610
) * fix(common/log_v2): the otel logger becomes the otl logger * fix(tests/engine): new test on Engine reload and log reopened * cleanup(common/log_v2): new comment to explain the new file This reopen is needed because of the log rotate that moves the log file into the archives directory and then reloads centengine. But since centengine did not reopen the file, it still wrote in it instead of opening a new one. REFS: MON-146682
- Loading branch information
Showing
9 changed files
with
163 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Copyright(c) 2015-present, Gabi Melman & spdlog contributors. | ||
* Distributed under the MIT License (http://opensource.org/licenses/MIT) | ||
* | ||
* This file is copied from basic_file_sink{-inl.h,.h} | ||
* The goal here is just to add a method `reopen()` using the file_helper mutex. | ||
*/ | ||
#pragma once | ||
|
||
#include <spdlog/common.h> | ||
#include <spdlog/details/file_helper.h> | ||
#include <spdlog/details/null_mutex.h> | ||
#include <spdlog/details/os.h> | ||
#include <spdlog/details/synchronous_factory.h> | ||
#include <spdlog/sinks/base_sink.h> | ||
|
||
#include <mutex> | ||
#include <string> | ||
|
||
namespace spdlog { | ||
namespace sinks { | ||
/* | ||
* Trivial file sink with single file as target | ||
*/ | ||
template <typename Mutex> | ||
class centreon_file_sink final : public base_sink<Mutex> { | ||
public: | ||
explicit centreon_file_sink(const filename_t& filename, | ||
bool truncate = false, | ||
const file_event_handlers& event_handlers = {}); | ||
const filename_t& filename() const; | ||
void reopen(); | ||
|
||
protected: | ||
void sink_it_(const details::log_msg& msg) override; | ||
void flush_() override; | ||
|
||
private: | ||
details::file_helper file_helper_; | ||
}; | ||
|
||
using centreon_file_sink_mt = centreon_file_sink<std::mutex>; | ||
using centreon_file_sink_st = centreon_file_sink<details::null_mutex>; | ||
|
||
template <typename Mutex> | ||
SPDLOG_INLINE centreon_file_sink<Mutex>::centreon_file_sink( | ||
const filename_t& filename, | ||
bool truncate, | ||
const file_event_handlers& event_handlers) | ||
: file_helper_{event_handlers} { | ||
file_helper_.open(filename, truncate); | ||
} | ||
|
||
template <typename Mutex> | ||
SPDLOG_INLINE const filename_t& centreon_file_sink<Mutex>::filename() const { | ||
return file_helper_.filename(); | ||
} | ||
|
||
template <typename Mutex> | ||
SPDLOG_INLINE void centreon_file_sink<Mutex>::reopen() { | ||
std::lock_guard<Mutex> lock(base_sink<Mutex>::mutex_); | ||
file_helper_.reopen(false); | ||
} | ||
|
||
template <typename Mutex> | ||
SPDLOG_INLINE void centreon_file_sink<Mutex>::sink_it_( | ||
const details::log_msg& msg) { | ||
memory_buf_t formatted; | ||
base_sink<Mutex>::formatter_->format(msg, formatted); | ||
file_helper_.write(formatted); | ||
} | ||
|
||
template <typename Mutex> | ||
SPDLOG_INLINE void centreon_file_sink<Mutex>::flush_() { | ||
file_helper_.flush(); | ||
} | ||
} // namespace sinks | ||
|
||
// | ||
// factory functions | ||
// | ||
template <typename Factory = spdlog::synchronous_factory> | ||
inline std::shared_ptr<logger> basic_logger_mt( | ||
const std::string& logger_name, | ||
const filename_t& filename, | ||
bool truncate = false, | ||
const file_event_handlers& event_handlers = {}) { | ||
return Factory::template create<sinks::centreon_file_sink_mt>( | ||
logger_name, filename, truncate, event_handlers); | ||
} | ||
|
||
template <typename Factory = spdlog::synchronous_factory> | ||
inline std::shared_ptr<logger> basic_logger_st( | ||
const std::string& logger_name, | ||
const filename_t& filename, | ||
bool truncate = false, | ||
const file_event_handlers& event_handlers = {}) { | ||
return Factory::template create<sinks::centreon_file_sink_st>( | ||
logger_name, filename, truncate, event_handlers); | ||
} | ||
|
||
} // namespace spdlog |
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
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,39 @@ | ||
*** Settings *** | ||
Documentation Centreon Engine forced checks tests | ||
Resource ../resources/import.resource | ||
|
||
Suite Setup Ctn Clean Before Suite | ||
Suite Teardown Ctn Clean After Suite | ||
Test Setup Ctn Stop Processes | ||
|
||
|
||
*** Test Cases *** | ||
ERL | ||
[Documentation] Engine is started and writes logs in centengine.log. | ||
... Then we remove the log file. The file disappears but Engine is still writing into it. | ||
... Engine is reloaded and the centengine.log should appear again. | ||
[Tags] engine log-v2 MON-146682 | ||
Ctn Config Engine ${1} | ||
Ctn Engine Config Set Value ${0} log_legacy_enabled ${0} | ||
Ctn Engine Config Set Value ${0} log_v2_enabled ${1} | ||
Ctn Engine Config Set Value ${0} log_level_events info | ||
Ctn Engine Config Set Value ${0} log_flush_period 0 | ||
|
||
Ctn Clear Retention | ||
Ctn Clear Db hosts | ||
${start} Ctn Get Round Current Date | ||
Ctn Start Engine | ||
Ctn Wait For Engine To Be Ready ${start} ${1} | ||
|
||
File Should Exist ${VarRoot}/log/centreon-engine/config0/centengine.log | ||
|
||
Remove File ${VarRoot}/log/centreon-engine/config0/centengine.log | ||
|
||
Sleep 5s | ||
|
||
File Should Not Exist ${VarRoot}/log/centreon-engine/config0/centengine.log | ||
Ctn Reload Engine | ||
|
||
Wait Until Created ${VarRoot}/log/centreon-engine/config0/centengine.log timeout=30s | ||
Ctn Stop Engine |
99d0ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Hostgroups
99d0ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Hostgroups
99d0ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Servicegroups
99d0ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Bench
99d0ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Robot Results
Failed Tests
Hostgroups