@@ -86,8 +86,8 @@ namespace efp {
86
86
LogLevel level;
87
87
};
88
88
89
- constexpr uint8_t stl_string_data_capacity = sizeof (FormatedMessage);
90
- constexpr uint8_t stl_string_head_capacity = stl_string_data_capacity - sizeof (size_t );
89
+ constexpr size_t stl_string_data_capacity = sizeof (FormatedMessage);
90
+ constexpr size_t stl_string_head_capacity = stl_string_data_capacity - sizeof (size_t );
91
91
92
92
// Data structure for std::string preventing each char takes size of full Enum;
93
93
struct StlStringHead {
@@ -380,15 +380,21 @@ namespace efp {
380
380
}
381
381
382
382
static inline void set_log_level (LogLevel log_level) {
383
-
384
383
instance ()._log_buffer .set_log_level (log_level);
385
384
}
386
385
387
386
static inline LogLevel get_log_level () {
388
387
return instance ()._log_buffer .get_log_level ();
389
388
}
390
389
391
- static void set_output (FILE* output_file) {
390
+ static inline void set_log_period (std::chrono::milliseconds period) {
391
+ _period = period;
392
+ }
393
+
394
+ static inline std::chrono::milliseconds get_log_period () { return _period; }
395
+
396
+ static void
397
+ set_output (FILE* output_file) {
392
398
instance ()._log_buffer .set_output_file (output_file);
393
399
}
394
400
@@ -449,25 +455,35 @@ namespace efp {
449
455
_run (true ),
450
456
_thread ([&]() {
451
457
while (_run.load ()) {
458
+ const auto start_time_point = std::chrono::steady_clock::now ();
452
459
#if EFP_LOG_TIME_STAMP == true
453
460
process_with_time ();
454
461
#else
455
462
process ();
456
463
#endif
457
- // todo periodic
458
- std::this_thread::sleep_for (std::chrono::milliseconds{1 });
464
+ const auto end_time_point = std::chrono::steady_clock::now ();
465
+ const auto elapsed_time =
466
+ std::chrono::duration_cast<std::chrono::milliseconds>(
467
+ end_time_point - start_time_point);
468
+
469
+ if (elapsed_time < _period) {
470
+ std::this_thread::sleep_for (_period - elapsed_time);
471
+ }
459
472
}
460
473
}) {
461
474
}
462
475
476
+ static std::chrono::milliseconds _period;
477
+
463
478
LogLevel _log_level;
464
479
465
480
detail::LogBuffer _log_buffer;
466
-
467
481
std::atomic<bool > _run;
468
482
std::thread _thread;
469
483
};
470
484
485
+ std::chrono::milliseconds Logger::_period = std::chrono::milliseconds(200 );
486
+
471
487
// LogLevel Logger::instance().log_level = LogLevel::Debug;
472
488
473
489
namespace detail {
0 commit comments