17 #define THIS_FILE "ftaerr.cpp"
19 #define MESSAGE_DIR "/am/ncbiapdata/errmsg"
118 const char*
months[] = {
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec" };
120 thread_local unique_ptr<FtaMsgPost>
bmp;
126 if (strsevcode.empty())
130 {
"SEV_WARNING", 2 },
133 {
"SEV_FATAL", 5 } };
135 if (
auto it = sStringToInt.
find(strsevcode);
136 it != sStringToInt.
end()) {
145 const char* module,
int code,
int subcode,
string& strcode,
string& strsubcode,
int& sevcode)
161 for (got_mod =
false, bmmfp =
bmp->bmmf; bmmfp; bmmfp = bmmfp->
next) {
162 if (bmmfp->
modname != module) {
167 for (bmmtp = bmmfp->
bmmt; bmmtp; bmmtp = bmmtp->
next) {
172 for (bmctxp = bmmtp->
bmctx; bmctxp; bmctxp = bmctxp->
next) {
190 fd = fopen(
buf.c_str(),
"r");
193 fd = fopen(
buf.c_str(),
"r");
208 while (fgets(s, 2047, fd)) {
209 if (s[0] !=
'$' || (s[1] !=
'^' && s[1] !=
'$'))
216 for (p = s + 2; *p ==
' ' || *p ==
'\t'; p++) {}
217 for (q = p; *p && *p !=
','; p++) {}
224 for (*p++ =
','; *p ==
' ' || *p ==
'\t'; p++) {}
225 for (q = p; *p >=
'0' && *p <=
'9'; p++) {}
240 if (s[1] ==
'^' && ch ==
',') {
241 for (p++; *p ==
' ' || *p ==
'\t'; p++) {}
243 *p && *p !=
' ' && *p !=
'\t' && *p !=
'\n' && *p !=
',';
248 if (!
strcmp(q,
"SEV_INFO") || !
strcmp(q,
"SEV_WARNING") ||
249 !
strcmp(q,
"SEV_ERROR") || !
strcmp(q,
"SEV_REJECT") ||
250 !
strcmp(q,
"SEV_FATAL")) {
265 if (val2 ==
code && strcode.empty())
271 if (! bmmfp->
bmmt || ! bmmtp) {
278 bmmtp->
bmctx = bmctxp;
284 if (val2 == subcode && strsubcode.empty() && ! strcode.empty()) {
305 bmp->hook_only =
false;
321 if (! name || *name ==
'\0')
325 bmp->prefix_accession = name;
328 bmp->prefix_locus = name;
332 strcpy(
tmp,
"FEAT=");
333 strncat(
tmp, name, 20);
339 bmp->prefix_feature =
tmp;
347 bmp->prefix_accession.clear();
350 bmp->prefix_locus.clear();
353 bmp->prefix_feature.clear();
364 if (! logfile || ! *logfile)
370 if (
bmp->logfile.empty()) {
371 bmp->logfile = logfile;
374 if (!
bmp->lfd && !
bmp->logfile.empty()) {
376 tm = localtime(&now);
377 i = tm->tm_hour % 12;
381 bmp->lfd = fopen(
bmp->logfile.c_str(),
"a");
383 "\n========================[ %s %d, %d %2d:%02d %s ]========================\n",
389 (tm->tm_hour >= 12) ?
"PM" :
"AM");
407 bmp->show_msg_codes =
true;
409 bmp->show_log_codes =
true;
411 bmp->show_msg_codeline =
true;
413 bmp->show_log_codeline =
true;
424 if (!
str ||
str[0] ==
'\0')
430 fprintf(
bmp->lfd,
"%s",
str);
475 switch (c_severity) {
496 return (cxx_severity);
513 char fpiBuffer[1024];
519 int fpiIntcode = lev1;
520 int fpiIntsubcode = lev2;
523 string fpiStrsubcode;
533 if (fpiModule && *fpiModule)
534 FtaErrGetMsgCodes(fpiModule, fpiIntcode, fpiIntsubcode, fpiStrcode, fpiStrsubcode, fpiSevcode);
539 fpiSevcode = (
int)sev;
541 if (
bmp->appname.empty())
544 stringstream textStream;
545 if (! fpiStrcode.empty()) {
546 textStream <<
"[" << fpiStrcode.c_str();
547 if (! fpiStrsubcode.empty()) {
548 textStream <<
"." << fpiStrsubcode.c_str();
553 if (
bmp->show_log_codeline) {
554 textStream <<
"{" << fpiFname <<
", line " << fpiLine;
556 if (!
bmp->prefix_locus.empty()) {
557 textStream <<
bmp->prefix_locus <<
": ";
559 if (!
bmp->prefix_accession.empty()) {
560 textStream <<
bmp->prefix_accession <<
": ";
562 if (!
bmp->prefix_feature.empty()) {
563 textStream <<
bmp->prefix_feature <<
" ";
565 textStream << fpiBuffer;
575 .
Report(fpiModule ? fpiModule :
"",
576 sSeverityMap.at(
static_cast<ErrSev>(fpiSevcode)),
static CFlatFileMessageReporter & GetInstance()
void Report(const string &module, EDiagSev severity, int code, int subcode, const string &text, int lineNum=-1)
const_iterator end() const
const_iterator find(const key_type &key) const
static const char location[]
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
bool ErrSetLog(const char *logfile)
void Nlm_ErrPostStr(ErrSev sev, int lev1, int lev2, const char *str)
ErrSev ErrSetLogLevel(ErrSev sev)
void FtaDeletePrefix(int prefix)
void FtaErrGetMsgCodes(const char *module, int code, int subcode, string &strcode, string &strsubcode, int &sevcode)
void Nlm_ErrSetContext(const char *module, const char *fname, int line)
thread_local unique_ptr< FtaMsgPost > bmp
void ErrSetFatalLevel(ErrSev sev)
void ErrSetOptFlags(int flags)
ErrSev ErrSetMessageLevel(ErrSev sev)
EDiagSev ErrCToCxxSeverity(int c_severity)
static int FtaStrSevToIntSev(const string &strsevcode)
void ErrLogPrintStr(const char *str)
void Nlm_ErrPostEx(ErrSev sev, int lev1, int lev2, const char *fmt,...)
void FtaInstallPrefix(int prefix, const char *name, const char *location)
static string GetAppName(EAppNameType name_type=eBaseName, int argc=0, const char *const *argv=NULL)
EDiagSev
Severity level for the posted diagnostics.
@ eDiag_Trace
Trace message.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
@ eDiag_Critical
Critical error message.
static char GetPathSeparator(void)
Get path separator symbol specific for the current platform.
static string GetCwd(void)
Get the current working directory.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
unsigned int
A callback function used to compare two keys in a database.
int strcmp(const char *str1, const char *str2)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
static const char * prefix[]
static const char * str(char *buf, int n)