PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PTrace::ThrottleBase Class Reference

Class to reduce noise level for some logging. More...

#include <object.h>

Inheritance diagram for PTrace::ThrottleBase:
Collaboration diagram for PTrace::ThrottleBase:

Public Member Functions

 ThrottleBase (unsigned lowLevel, unsigned interval=60000, unsigned highLevel=6, unsigned maxShown=1)
 
 ThrottleBase (const ThrottleBase &other)
 
ThrottleBaseoperator= (const ThrottleBase &other)
 
bool CanTrace (int64_t now=0)
 
 operator unsigned () const
 
__inline unsigned GetLowLevel () const
 
__inline unsigned GetHighLevel () const
 
__inline unsigned GetCurrentLevel () const
 
__inline unsigned GetHiddenCount () const
 

Protected Attributes

unsigned m_interval
 
unsigned m_lowLevel
 
unsigned m_highLevel
 
unsigned m_maxShown
 
atomic< unsigned > m_currentLevel
 
atomic< int64_t > m_nextLog
 
atomic< unsigned > m_repeatCount
 
atomic< unsigned > m_hiddenCount
 

Friends

ostream & operator<< (ostream &strm, const ThrottleBase &throttle)
 

Detailed Description

Class to reduce noise level for some logging.

A log is emitted at the lowLevel every interval milliseconds. All logs within the time interval are emitted at highLevel.

An optional log output of the count of times the log occurred during may achived by simply including the throttle instance at the end of the log, e.g.


  PTRACE_THROTTLE_STATIC(m_throttleIt, 2, 2000);
  PTRACE(m_throttleIt, "A very frequent log" << m_throttleIt);

The maxShown parameter indicates the maximum number of trace outputs that can occur in the time interval.

Additional note: the "repeated" count optionally output is not 100% accurate in multi-threaded usage.

Constructor & Destructor Documentation

PTrace::ThrottleBase::ThrottleBase ( unsigned  lowLevel,
unsigned  interval = 60000,
unsigned  highLevel = 6,
unsigned  maxShown = 1 
)
Parameters
lowLevelLevel at which low frequency logs made
intervalTime between low frequency logs
highLevelLevel for high frequency (every) logs
maxShownMax shown messages in time interval
PTrace::ThrottleBase::ThrottleBase ( const ThrottleBase other)

Member Function Documentation

bool PTrace::ThrottleBase::CanTrace ( int64_t  now = 0)
__inline unsigned PTrace::ThrottleBase::GetCurrentLevel ( ) const
inline
__inline unsigned PTrace::ThrottleBase::GetHiddenCount ( ) const
inline
__inline unsigned PTrace::ThrottleBase::GetHighLevel ( ) const
inline
__inline unsigned PTrace::ThrottleBase::GetLowLevel ( ) const
inline
PTrace::ThrottleBase::operator unsigned ( ) const
inline
ThrottleBase& PTrace::ThrottleBase::operator= ( const ThrottleBase other)

Friends And Related Function Documentation

ostream& operator<< ( ostream &  strm,
const ThrottleBase throttle 
)
friend

Member Data Documentation

atomic<unsigned> PTrace::ThrottleBase::m_currentLevel
protected
atomic<unsigned> PTrace::ThrottleBase::m_hiddenCount
protected
unsigned PTrace::ThrottleBase::m_highLevel
protected
unsigned PTrace::ThrottleBase::m_interval
protected
unsigned PTrace::ThrottleBase::m_lowLevel
protected
unsigned PTrace::ThrottleBase::m_maxShown
protected
atomic<int64_t> PTrace::ThrottleBase::m_nextLog
protected
atomic<unsigned> PTrace::ThrottleBase::m_repeatCount
protected

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