MXS-2050 Use global counter to detect log rotation request
Modules need to check the number regularly to detect a new log rotation.
This commit is contained in:
@ -16,6 +16,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <cinttypes>
|
||||
|
||||
#include <maxbase/log.hh>
|
||||
@ -28,6 +29,12 @@
|
||||
namespace
|
||||
{
|
||||
|
||||
struct ThisUnit
|
||||
{
|
||||
std::atomic<int> rotation_count {0};
|
||||
};
|
||||
ThisUnit this_unit;
|
||||
|
||||
const char* LOGFILE_NAME = "maxscale.log";
|
||||
|
||||
size_t mxs_get_context(char* buffer, size_t len)
|
||||
@ -129,3 +136,18 @@ json_t* mxs_logs_to_json(const char* host)
|
||||
|
||||
return mxs_json_resource(host, MXS_JSON_API_LOGS, data);
|
||||
}
|
||||
|
||||
bool mxs_log_rotate()
|
||||
{
|
||||
bool rotated = mxb_log_rotate();
|
||||
if (rotated)
|
||||
{
|
||||
this_unit.rotation_count.fetch_add(1, std::memory_order_relaxed);
|
||||
}
|
||||
return rotated;
|
||||
}
|
||||
|
||||
int mxs_get_log_rotation_count()
|
||||
{
|
||||
return this_unit.rotation_count.load(std::memory_order_relaxed);
|
||||
}
|
Reference in New Issue
Block a user