Skip to content

Commit e1339fa

Browse files
committed
fix: Make _periond non-static
1 parent 2fc72f0 commit e1339fa

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

example/efp_logger_example.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ int main() {
99
Logger::set_log_level(LogLevel::Trace);
1010

1111
// Optional log period setting. Default is 200ms
12-
// Logger::set_log_period(std::chrono::milliseconds(1000));
12+
// Logger::set_log_period(std::chrono::milliseconds(1000));`
1313

1414
// Optional log output setting. // default is stdout
1515
// Logger::set_output("./efp_logger_test.log");

include/efp/logger.hpp

+9-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#define EFP_LOG_TIME_STAMP true
1818
#define EFP_LOG_BUFFER_SIZE 256
1919
// todo Maybe compile time log-level
20-
// todo Processing period configuration
2120

2221
namespace efp {
2322
enum class LogLevel : char {
@@ -388,10 +387,12 @@ namespace efp {
388387
}
389388

390389
static inline void set_log_period(std::chrono::milliseconds period) {
391-
_period = period;
390+
instance()._period = period;
392391
}
393392

394-
static inline std::chrono::milliseconds get_log_period() { return _period; }
393+
static inline std::chrono::milliseconds get_log_period() {
394+
return instance()._period;
395+
}
395396

396397
static void
397398
set_output(FILE* output_file) {
@@ -451,9 +452,9 @@ namespace efp {
451452
protected:
452453
private:
453454
Logger()
454-
: // with_time_stamp(true),
455-
_run(true),
456-
_thread([&]() {
455+
: _period{200},
456+
_run{true},
457+
_thread{[&]() {
457458
while (_run.load()) {
458459
const auto start_time_point = std::chrono::steady_clock::now();
459460
#if EFP_LOG_TIME_STAMP == true
@@ -470,22 +471,16 @@ namespace efp {
470471
std::this_thread::sleep_for(_period - elapsed_time);
471472
}
472473
}
473-
}) {
474+
}} {
474475
}
475476

476-
static std::chrono::milliseconds _period;
477-
478-
LogLevel _log_level;
477+
std::chrono::milliseconds _period;
479478

480479
detail::LogBuffer _log_buffer;
481480
std::atomic<bool> _run;
482481
std::thread _thread;
483482
};
484483

485-
std::chrono::milliseconds Logger::_period = std::chrono::milliseconds(200);
486-
487-
// LogLevel Logger::instance().log_level = LogLevel::Debug;
488-
489484
namespace detail {
490485

491486
template <typename... Args>

0 commit comments

Comments
 (0)