Teamcenter C++ API Reference  2312
Functions
emh_log.hxx File Reference

EMH ITK to store error, and log additional message in the syslog. More...

#include <tc/emh.h>
#include <mld/logging/Logger.hxx>
#include <tc/libtc_exports.h>
#include <tc/libtc_undef.h>

Go to the source code of this file.

Functions

int EMH_store_error_and_log (const char *file_name, int line_number, int severity, int ifail, Teamcenter::Logging::Logger *logger, const std::string &msg, const char *s1=0, const char *s2=0, const char *s3=0, const char *s4=0, const char *s5=0, const char *s6=0, const char *s7=0)
 

Detailed Description

EMH ITK to store error, and log additional message in the syslog.

This new EMH method supports logging msg in syslog in addition to storing error on error store. It can be used to log error message at one place where error actually originates and avoid logging error messages at multiple levels for same error. This also helps in logging with the same log level as error severity is and maintaining consistency in log priority for a particular error. Consider below example:

int function1() { ResultStatus stat; try { int ifail = error_func() if( ifail != ITK_ok ) { stat = EMH_store_error( EMH_severity_error, ifail ); } } catch(const IFail& ex) { logger()->error( ex.ifail(), "Error occured in function1" ); } }

void function2() { try { ResultStatus stat = function1(); } catch(const IFail& ex) { logger()->error( ex.ifail(), "Error occured in function2" ); } }

The issue here is that error message is logged twice for the same error code. In addition to that we need to call two different API for achieving it and there is a possibility that log level may mismatch for error store and syslog if correct method is not called. To avoid these concerns we can simple use like below:

int function1()
{
try
{
int ifail = error_func()
if( ifail != ITK_ok )
{
stat = EMH_store_error_and_log( __FILE__, ERROR_line, EMH_severity_error, ifail, Logger::getLogger(), "Error in error_func " );
}
}
catch(const IFail& ex)
{
return ex.ifail();
}
}
void function2()
{
try
{
ResultStatus stat = function1();
}
catch(const IFail& ex)
{
//appropriate action
}
}

Definition in file emh_log.hxx.

Function Documentation

int EMH_store_error_and_log ( const char *  file_name,
int  line_number,
int  severity,
int  ifail,
Teamcenter::Logging::Logger logger,
const std::string &  msg,
const char *  s1 = 0,
const char *  s2 = 0,
const char *  s3 = 0,
const char *  s4 = 0,
const char *  s5 = 0,
const char *  s6 = 0,
const char *  s7 = 0 
)

Adds the specified error code to the top of the error store. It also logs the given msg for the corresponding severity along with file_name and line_number to the syslog

Parameters
file_nameThe src file name logging a message.
line_numberThe line number from which a call to log a message called.
severity#EMH_severity_error, #EMH_severity_warning, or #EMH_severity_information
ifailCode of the error being stored
loggerThe logger which log the input msg in the syslog.
msgThe formatted message via std::format to log.
s1Character string being substituted into the internationalized message associated with this ifail code
s2Character string being substituted into the internationalized message associated with this ifail code
s3Character string being substituted into the internationalized message associated with this ifail code
s4Character string being substituted into the internationalized message associated with this ifail code
s5Character string being substituted into the internationalized message associated with this ifail code
s6Character string being substituted into the internationalized message associated with this ifail code
s7Character string being substituted into the internationalized message associated with this ifail code