ANNA Suite  2020b
Multipurpose development suite for Telco applications
Public Member Functions | List of all members
anna::tracing::TraceLevelChecker Class Reference

#include <TraceLevelChecker.hpp>

Public Member Functions

 TraceLevelChecker (const char *contextData=NULL)
 
 ~TraceLevelChecker ()
 
virtual bool changeLevelCondition (const std::string &contextData, anna::Logger::Level &targetLevel) const
 
bool load (const char *contextData=NULL)
 
bool restore (void)
 

Detailed Description

Helper class used for selective tracing

Constructor & Destructor Documentation

◆ TraceLevelChecker()

anna::tracing::TraceLevelChecker::TraceLevelChecker ( const char *  contextData = NULL)
inline

Constructs one class instance providing the context data to be compared with current configuration trigger references. Depending on changeLevelCondition(), certain trace level will be assigned. Trace level is preconfigured on global Configuration class for each trigger item, but changeLevelCondition() re-implementation could modify this behaviour (i.e. fix to debug level for all situations). That easy... just like that: build instance wherever you want to check context to decide a trace level change.

Is possible to detect several concepts with a little imagination. For example, if you want to change trace level when MSISDN is 609555555 and ServiceId is greater than 3, you could do something like this:

   1) Set the trigger (usually this is done at general configuration, oam commands, etc):
   (Configuration::instantiate()).activateTraceTrigger("609555555#3"); // only one trigger item (more didactic)
   Triggers are strings, then multi-concept contexts requires token management or something similar.
   2) Create the child class with specific condition method:
   2.1) MyTraceLevelChecker_WithMsisdnAndserviceIdLessThanValue inherit from TraceLevelChecker
   2.2) MyTraceLevelChecker_WithMsisdnAndserviceIdLessThanValue::changeLevelCondition() reimplementation:
         Tokenize ('#' separator) both context data and reference trigger item:
         a) extract 'contextMSISDN' from 'contextData'
         b) extract 'contextSERVICEID' from 'contextData'
         c) extract 'MSISDNreference' (see Configuration::getTraceTriggerMap())
         d) extract 'SERVICEIDreference' (idem)
         e) Return condition: (contextMSISDN == MSISDNreference) && (atoi(contextSERVICEID) > atoi(SERVICEIDreference))
   3) Plan selective trace on application handler (data receive, context expiration, etc.):
   std::string contextChain = msisdn; contextChain += "#"; contextChain += anna::functions::asString(serviceId);
   MyTraceLevelChecker_WithMsisdnAndserviceIdLessThanValue tlc (contextChain);
   Normally, only one concept like MSISDN is compared, and the list of triggers references has only one item.
Parameters
contextDataString to be compared. If NULL provided, no checkings will be done now (use load() instead) and empty string will be prepared for future load() calls without context data specification.
See also
load()
77  {
78  a_previousLevel = anna::Logger::getLevel(); // protection (si por error no se usara el load() nunca, el destructor podria alterar el nivel de traceo del proceso)
79  a_contextData = contextData ? contextData : "";
80 
81  if(contextData) load(contextData);
82  }
bool load(const char *contextData=NULL)
static Level getLevel()
Definition: Logger.hpp:143
Here is the call graph for this function:

◆ ~TraceLevelChecker()

anna::tracing::TraceLevelChecker::~TraceLevelChecker ( )
inline

Destructor restores initial context trace level

This apply when application finish the execution scope or when exceptions are launched anywhere.

See also
restore()
Here is the call graph for this function:

Member Function Documentation

◆ changeLevelCondition()

virtual bool anna::tracing::TraceLevelChecker::changeLevelCondition ( const std::string &  contextData,
anna::Logger::Level targetLevel 
) const
virtual

Defines the condition between the context information and global Configuration class trigger references. Target trace level when condition is true, is preconfigured for each trigger reference, but this method could be reimplemented to fix to debug level ignoring global Configuration class trigger preferences.

Default implementation check incoming context data to be the same as any of the global Configuration class trigger references registered. Specific implementation could check that context data contains any of the trigger reference, or perhaps use regular expressions to be more flexible.

Parameters
contextDataString to be compared
targetLevelDesired target level configured for each trigger item at global Configuration class

◆ load()

bool anna::tracing::TraceLevelChecker::load ( const char *  contextData = NULL)

Performs trace level checkings for context data provided. Gives higher control over the funtionality: using with restore(), application can fix tracing zones, but in most cases constructor & destructor are enough for normal behaviour (more simply and secure).

Multiple calls to this method could provide OR operation regarding trace level changes with context data strings loaded, but this is unusual because implies assume same nature for different context indicators. Then, be careful if data passed is not sure to be the same when application manage different tracing zones with restore().

Parameters
contextDataString to be compared. If NULL provided (default-missing parameter call), last valid assignment (within constructor or former load() call) will be used.
Returns
Boolean about trace level change because of condition result

◆ restore()

bool anna::tracing::TraceLevelChecker::restore ( void  )

Do the same than destructor. Gives higher control over the funtionality: using with load(), application can fix tracing zones, but in most cases constructor & destructor are enough for normal behaviour.

Returns
Boolean about Trace level change because restore proceed

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