ANNA Suite
2020b
Multipurpose development suite for Telco applications
|
#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) |
Helper class used for selective tracing
|
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.
contextData | String 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. |
|
inline |
Destructor restores initial context trace level
This apply when application finish the execution scope or when exceptions are launched anywhere.
|
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.
contextData | String to be compared |
targetLevel | Desired target level configured for each trigger item at global Configuration class |
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().
contextData | String to be compared. If NULL provided (default-missing parameter call), last valid assignment (within constructor or former load() call) will be used. |
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.