|
Teamcenter C++ API Reference
2312
|
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) |
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:
Definition in file emh_log.hxx.
| 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
| file_name | The src file name logging a message. |
| line_number | The line number from which a call to log a message called. |
| severity | #EMH_severity_error, #EMH_severity_warning, or #EMH_severity_information |
| ifail | Code of the error being stored |
| logger | The logger which log the input msg in the syslog. |
| msg | The formatted message via std::format to log. |
| s1 | Character string being substituted into the internationalized message associated with this ifail code |
| s2 | Character string being substituted into the internationalized message associated with this ifail code |
| s3 | Character string being substituted into the internationalized message associated with this ifail code |
| s4 | Character string being substituted into the internationalized message associated with this ifail code |
| s5 | Character string being substituted into the internationalized message associated with this ifail code |
| s6 | Character string being substituted into the internationalized message associated with this ifail code |
| s7 | Character string being substituted into the internationalized message associated with this ifail code |