Sunshine master
Self-hosted game stream host for Moonlight.
logging::min_max_avg_periodic_logger< T > Class Template Reference

A helper class for tracking and logging numerical values across a period of time. More...

#include <src/logging.h>

Public Member Functions

void collect_and_log (const T &value)
 Collect a metric sample and write it to the periodic log when due.
 
void collect_and_log (std::function< T()> func)
 Collect a metric sample and write it to the periodic log when due.
 
bool is_enabled () const
 Check whether this periodic logger should emit at the configured severity.
 
 min_max_avg_periodic_logger (boost::log::sources::severity_logger< int > &severity, std::string_view message, std::string_view units, std::chrono::seconds interval_in_seconds=std::chrono::seconds(20))
 Construct a periodic logger that reports min, max, and average samples.
 
void reset ()
 Reset the object to its initial empty state.
 

Detailed Description

template<typename T>
class logging::min_max_avg_periodic_logger< T >

A helper class for tracking and logging numerical values across a period of time.

*Examples**

min_max_avg_periodic_logger<int> logger(debug, "Test time value", "ms", 5s);
logger.collect_and_log(1);
// ...
logger.collect_and_log(2);
// after 5 seconds
logger.collect_and_log(3);
// In the log:
// [2024:01:01:12:00:00]: Debug: Test time value (min/max/avg): 1ms/3ms/2.00ms
A helper class for tracking and logging numerical values across a period of time.
Definition logging.h:114
bl::sources::severity_logger< int > debug
Follow what is happening.
Definition logging.cpp:41

Constructor & Destructor Documentation

◆ min_max_avg_periodic_logger()

template<typename T >
logging::min_max_avg_periodic_logger< T >::min_max_avg_periodic_logger ( boost::log::sources::severity_logger< int > & severity,
std::string_view message,
std::string_view units,
std::chrono::seconds interval_in_seconds = std::chrono::seconds(20) )
inline

Construct a periodic logger that reports min, max, and average samples.

Parameters
severitySeverity level associated with the log message.
messageMessage text to log or report.
unitsUnit label appended to tracked numeric values.
interval_in_secondsInterval in seconds.

Member Function Documentation

◆ collect_and_log() [1/2]

template<typename T >
void logging::min_max_avg_periodic_logger< T >::collect_and_log ( const T & value)
inline

Collect a metric sample and write it to the periodic log when due.

Parameters
valueNumeric sample to include in the next periodic aggregate.

◆ collect_and_log() [2/2]

template<typename T >
void logging::min_max_avg_periodic_logger< T >::collect_and_log ( std::function< T()> func)
inline

Collect a metric sample and write it to the periodic log when due.

Parameters
funcCallable used to calculate the tracked sample value.

◆ is_enabled()

template<typename T >
bool logging::min_max_avg_periodic_logger< T >::is_enabled ( ) const
inline

Check whether this periodic logger should emit at the configured severity.

Returns
True when the logger severity is enabled and sampling should continue.

The documentation for this class was generated from the following file: