56 #include <unordered_set>
59 #if defined(NCBI_OS_UNIX)
61 # include <sys/utsname.h>
64 #if defined(NCBI_OS_MSWIN)
66 #elif defined (NCBI_OS_DARWIN)
67 # include <crt_externs.h>
68 # define environ (*_NSGetEnviron())
70 extern char** environ;
74 #define NCBI_USE_ERRCODE_X Corelib_Diag
95 bool diag_unlocked = s_DiagMutex.TryLock();
101 "Cannot switch diagnostic to RW-lock - mutex is locked.");
103 s_DiagMutex.Unlock();
110 if (!diag_unlocked) {
113 "Cannot switch diagnostic to mutex - RW-lock is locked.");
147 s_DiagPostMutex.Lock();
161 s_DiagPostMutex.Unlock();
164 s_DiagMutex.Unlock();
235 #if defined(NCBI_POSIX_THREADS) && defined(HAVE_PTHREAD_ATFORK)
240 static void s_NcbiDiagPreFork(
void)
244 static void s_NcbiDiagPostFork(
void)
246 s_DiagMutex.Unlock();
259 DIAG_OLD_POST_FORMAT);
266 DIAG_AUTOWRITE_CONTEXT);
272 DIAG_PRINT_SYSTEM_TID);
280 DIAG_ASSERT_ON_ABORT);
285 DIAG_LOG_SIZE_LIMIT);
291 DIAG_MAX_LINE_LENGTH);
326 lim.
Set(NStr::StringToNumeric<CLogRateLimit::TValue>(s));
346 DIAG_APPLOG_RATE_PERIOD);
358 DIAG_ERRLOG_RATE_PERIOD);
370 DIAG_TRACELOG_RATE_PERIOD);
421 DIAG_LOG_ENVIRONMENT);
434 DIAG_DISABLE_APPLOG_MESSAGES);
534 x_Init(print_severity, collect_severity, action);
551 psev = CDiagBuffer::sm_PostSeverity;
555 ? psev : print_severity;
557 ? csev : collect_severity;
615 str_rev_str(
const char* begin_str,
const char* end_str,
const char* str_search)
617 if (begin_str ==
NULL)
621 if (str_search ==
NULL)
624 const char* search_char = str_search + strlen(str_search);
625 const char* cur_char = end_str;
631 }
while(*cur_char != *search_char && cur_char != begin_str);
632 if (*cur_char != *search_char)
635 while (search_char != str_search);
657 const char* curr_funct,
662 m_CurrFunctName(curr_funct),
680 const string& curr_funct,
681 const string& module)
700 const char* cur_extension = strrchr(
m_File,
'.');
701 if (cur_extension ==
NULL)
704 if (*(cur_extension + 1) !=
'\0') {
710 return strcmp(cur_extension,
"cpp") == 0 ||
711 strcmp(cur_extension,
"C") == 0 ||
712 strcmp(cur_extension,
"c") == 0 ||
713 strcmp(cur_extension,
"cxx") == 0;
771 if (*(stop - 1) != rsep)
return stop;
773 const char* pos = stop - 2;
774 for (; pos > start; pos--) {
778 else if (*pos == lsep) {
779 if (--balance == 0)
break;
782 return (pos <= start) ?
NULL : pos;
812 const char* start_str =
NULL;
815 const char* start_str_tmp =
817 bool has_class = start_str_tmp !=
NULL;
818 if (start_str_tmp !=
NULL) {
819 start_str = start_str_tmp + 2;
822 if (start_str_tmp !=
NULL) {
823 start_str = start_str_tmp + 1;
827 const char* cur_funct_name =
829 while (cur_funct_name && *cur_funct_name &&
830 (*cur_funct_name ==
'*' || *cur_funct_name ==
'&')) {
833 size_t cur_funct_name_len = end_str - cur_funct_name;
840 const char* cur_class_name =
842 while (cur_class_name && *cur_class_name &&
843 (*cur_class_name ==
'*' || *cur_class_name ==
'&')) {
846 size_t cur_class_name_len = end_str - cur_class_name;
860 #if defined(NCBI_POSIX_THREADS) && defined(HAVE_PTHREAD_ATFORK)
861 pthread_atfork(s_NcbiDiagPreFork,
906 #define USE_TLS_DATA_CACHE
907 #ifdef USE_TLS_DATA_CACHE
919 : m_DiagBuffer(new CDiagBuffer),
921 m_ThreadPostNumber(0),
922 m_DiagCollectionSize(0)
932 #ifdef USE_TLS_DATA_CACHE
971 #ifdef USE_TLS_DATA_CACHE
982 switch (thread_data_state) {
991 cerr <<
"FATAL ERROR: inappropriate recursion initializing NCBI"
992 " diagnostic framework." << endl;
1001 cerr <<
"FATAL ERROR: NCBI diagnostic framework no longer"
1002 " initialized." << endl;
1027 #ifdef USE_TLS_DATA_CACHE
1068 "Using the same CRequestContext in multiple threads is unsafe!"
1096 TCollectGuards::iterator itg = find(
1103 unique_ptr<CDiagLock> lock;
1109 if (itc->m_ThrPost >= start
1111 itc->m_Severity = cap;
1122 if (lock.get() ==
nullptr) {
1138 if (itc->m_Severity ==
eDiag_Trace && !allow_trace) {
1141 if (itc->m_Severity < post_sev) {
1147 if (discarded > 0) {
1149 " messages due to collection limit. Set "
1150 "DIAG_COLLECT_LIMIT to increase the limit.");
1213 "NS",
"PB",
"P",
"PE",
"RB",
"R",
"RE"
1303 m_AppNameSet(
false),
1304 m_LoggedHitId(
false),
1306 m_ExitCodeSet(
false),
1312 GetLogRate_Limit(eLogRate_App),
1313 CTimeSpan((long)GetLogRate_Period(eLogRate_App)),
1318 GetLogRate_Limit(eLogRate_Err),
1319 CTimeSpan((long)GetLogRate_Period(eLogRate_Err)),
1324 GetLogRate_Limit(eLogRate_Trace),
1325 CTimeSpan((long)GetLogRate_Period(eLogRate_Trace)),
1329 m_AppLogSuspended(
false),
1330 m_ErrLogSuspended(
false),
1331 m_TraceLogSuspended(
false)
1479 bool approved =
true;
1493 switch (
msg.m_Severity ) {
1548 Print(
"action",
"fork").
1549 Print(
"parent_guid",
ctx.GetStringUID(old_uid)).
1618 return (TUID(base) << 48) |
1619 ((TUID(pid) & 0xFFFF) << 32) |
1620 ((TUID(
t) & 0xFFFFFFF) << 4) |
1627 const string& host =
GetHost();
1628 for (
auto c : host) {
1641 #if defined(NCBI_OS_UNIX)
1644 if (uname(&
buf) >= 0) {
1645 const char* s =
buf.nodename;
1679 int hi =
int((uid >> 32) & 0xFFFFFFFF);
1680 int lo =
int(uid & 0xFFFFFFFF);
1681 snprintf(
buf, buflen,
"%08X%08X", hi, lo);
1709 uid &= ~((
TUID)0xFFFFFFF << 4);
1711 return uid | ((
TUID(
t) & 0xFFFFFFF) << 4);
1732 if ( !is_default ) {
1736 rid = ((
Uint8)0xFFFFFF) << 16;
1739 Uint8 lo = tid | rid | us;
1743 snprintf(
buf, 33,
"%08X%08X%08X%08X", b3, b2, b1, b0);
1769 if ( !
m_Host->IsEmpty() ) {
1770 return m_Host->GetOriginalString();
1778 if (ncbi_host && *ncbi_host) {
1780 return m_Host->GetOriginalString();
1783 #if defined(NCBI_OS_UNIX)
1787 if (uname(&
buf) >= 0) {
1789 return m_Host->GetOriginalString();
1794 #if defined(NCBI_OS_MSWIN)
1797 if ( compname && *compname ) {
1799 return m_Host->GetOriginalString();
1805 if ( servaddr && *servaddr ) {
1808 return m_Host->GetOriginalString();
1814 if ( !
m_Host->IsEmpty() ) {
1815 return m_Host->GetEncodedString();
1822 return m_Host->GetEncodedString();
1828 return m_Host->GetOriginalString();
1834 return m_Host->GetEncodedString();
1888 ERR_POST(
"Application name cannot be changed.");
1895 ERR_POST(
"Illegal characters in application name: '" << app_name <<
1896 "', using URL-encode.");
1932 const string&
value,
1979 if ( !
value.empty() ) {
2090 gprop->first +
"=" + gprop->second);
2102 static const char* kCloudIdFile =
"/etc/ncbi/cloudid";
2103 CFile cloudid(kCloudIdFile);
2104 if ( cloudid.
Exists() ) {
2107 while (!
in.eof() &&
in.good()) {
2110 size_t sep = s.find(
'\t');
2111 if (sep ==
NPOS)
continue;
2113 string value = s.substr(sep + 1);
2123 for (
char **
env = environ; *
env; ++
env) {
2132 f.LogFields(env_map);
2149 ctx.x_LogHitID(
true);
2169 : m_EventType(event_type),
2171 m_Counter(new
int(1)),
2176 m_AllowBadNames(
false)
2186 m_Counter(new
int(1)),
2188 m_PerfStatus(status),
2189 m_PerfTime(timespan),
2191 m_AllowBadNames(
false)
2193 if (args.empty())
return;
2203 m_Typed(args.m_Typed),
2204 m_PerfStatus(args.m_PerfStatus),
2205 m_PerfTime(args.m_PerfTime),
2206 m_Flushed(args.m_Flushed),
2207 m_AllowBadNames(args.m_AllowBadNames)
2228 if ( !role.empty() ) {
2229 Print(
"ncbi_role", role);
2231 if ( !loc.empty() ) {
2232 Print(
"ncbi_location", loc);
2252 Print(
"ncbi_app_package_version", pkv);
2256 initializer_list<SBuildInfo::EExtra> bi_num = {
2265 if (!
value.empty()) {
2271 #if defined(NCBI_TEAMCITY_PROJECT_NAME)
2274 #if defined(NCBI_TEAMCITY_BUILDCONF_NAME)
2277 #if defined(NCBI_TEAMCITY_BUILD_NUMBER)
2280 #if defined(NCBI_TEAMCITY_BUILD_ID)
2305 initializer_list<SBuildInfo::EExtra> bi_num =
2311 if (!
value.empty()) {
2317 #if defined(NCBI_PRODUCTION_VER)
2318 Print(
"ncbi_app_prod_version", NStr::NumericToString<Uint8>(NCBI_PRODUCTION_VER));
2319 #elif defined(NCBI_DEVELOPMENT_VER)
2322 #if defined(NCBI_SC_VERSION)
2323 Print(
"ncbi_app_sc_version", NStr::NumericToString<Uint8>(NCBI_SC_VERSION));
2325 #if defined(NCBI_SUBVERSION_REVISION)
2356 bool app_state_updated =
false;
2361 app_state_updated =
true;
2368 app_state_updated =
true;
2397 if ( app_state_updated ) {
2421 if (
this != &args) {
2449 "Attempt to set request start/stop arguments after flushing");
2483 "exec_time_msec_bit",
2495 "geo_latitude_hundredths",
2496 "geo_longitude_hundredths",
2497 "session_pageviews",
2502 "time_to_last_ping",
2509 "self_url_file_ext",
2510 "self_url_top_level_dir",
2511 "self_url_directory",
2523 "has_duplicate_nexus",
2524 "has_duplicate_phid",
2528 "has_multiple_phid",
2535 "multiple_session_hit",
2536 "multiple_session_ip",
2537 "ncbi_phid_first_render",
2538 "phid_from_other_request",
2539 "phid_stack_ambiguous_relationship",
2540 "phid_stack_has_fake_child",
2541 "phid_stack_has_fake_parent",
2542 "phid_stack_missing_child",
2543 "phid_stack_missing_parent",
2544 "phid_stack_multivalued",
2546 "session_bot_by_ip",
2547 "session_bot_by_rate",
2548 "session_bot_by_user_agent",
2553 "browser_major_version",
2562 "applog_db_size_hit_fraction",
2563 "applog_db_machine",
2566 "applog_db_date_tag",
2567 "applog_db_date_range",
2569 "applog_db_create_time",
2570 "applog_db_modify_time",
2573 "applog_db_agent_host",
2574 "applog_db_agent_pid",
2575 "applog_db_agent_tid",
2576 "applog_db_volume_served_time",
2577 "phid_stack_missing_parent",
2578 "phid_stack_missing_child",
2579 "phid_stack_has_fake_child",
2580 "phid_stack_has_fake_parent",
2581 "phid_stack_ambiguous_relationship",
2582 "phid_stack_multivalued",
2583 "ncbi_phid_first_render",
2584 "multiple_session_hit",
2587 "has_duplicate_nexus",
2589 "has_multiple_phid",
2591 "session_bot_by_rate",
2592 "session_bot_by_user_agent",
2594 "session_bot_by_ip",
2596 "multiple_session_ip",
2609 for (
int i = 0;
i < sz; ++
i) {
2638 if (kw.find(name) == kw.end()) {
2639 m_Args->rbegin()->first.assign(name);
2642 string renamed =
"auto_renamed_applog_keyword__" + name;
2643 m_Args->rbegin()->first.assign(renamed);
2645 <<
"' is a reserved NCBI AppLog keyword, so it has been renamed to "
2682 #if !NCBI_INT8_IS_LONG
2693 #elif SIZEOF_LONG_LONG
2765 bool app_state_updated =
false;
2769 app_state_updated =
true;
2772 if ( app_state_updated ) {
2781 bool app_state_updated =
false;
2784 app_state_updated =
true;
2787 if ( app_state_updated ) {
2863 NCBI_LOG_SESSION_ID);
2883 if ( sid.empty() ) {
2928 NCBI_LOG_CLIENT_IP);
3013 if ( !phid.empty() ) {
3014 const char* c_env_job_id = getenv(
"JOB_ID");
3015 string env_job_id = c_env_job_id ?
string(c_env_job_id):
"";
3016 const char* c_env_task_id = getenv(
"SGE_TASK_ID");
3017 string env_task_id = c_env_task_id ?
string(c_env_task_id) :
"";
3018 if (env_task_id.find_first_not_of(
"0123456789") !=
NPOS) {
3023 if (!env_job_id.empty() && !env_task_id.empty()) {
3030 string jid =
".000" + env_job_id;
3031 string tid =
".00" + env_task_id;
3032 size_t jid_pos = phid.find(jid);
3033 if (jid_pos ==
NPOS) {
3039 if (phid.find(tid, jid_pos + jid.size()) ==
NPOS) {
3096 unique_ptr<string> role(
new string);
3098 if (env_role && *env_role) {
3116 unique_ptr<string> loc(
new string);
3118 if (env_loc && *env_loc) {
3168 const string& host =
msg.GetHost();
3170 string session =
msg.GetSession();
3171 const string& app =
msg.GetAppName();
3175 ostr << setfill(
'0') << setw(
kDiagW_PID) <<
msg.m_PID <<
'/'
3179 << setfill(
' ') << setw(
kDiagW_AppState) << setiosflags(IOS_BASE::left)
3180 << app_state << resetiosflags(IOS_BASE::left)
3181 <<
' ' << setw(0) << setfill(
' ') << uid <<
' '
3182 << setfill(
'0') << setw(
kDiagW_SN) <<
msg.m_ProcPost <<
'/'
3185 << setfill(
' ') << setiosflags(IOS_BASE::left)
3192 << resetiosflags(IOS_BASE::left) << setw(0)
3201 if (
ctx.IsRunning() ) {
3205 "Duplicate request-start or missing request-stop");
3209 if ( !
ctx.IsSetExplicitClientIP() ) {
3211 if ( !
ip.empty() ) {
3212 ctx.SetClientIP(
ip);
3225 string log_args = s_LogEnvironment->
Get();
3226 if ( !log_args.empty() ) {
3227 list<string> log_args_list;
3231 extra.
Print(
"LogEnvironment",
"true");
3239 ITERATE(list<string>, it, log_args_list) {
3240 const string&
val =
env.Get(*it);
3248 log_args = s_LogRegistry->
Get();
3249 if ( !log_args.empty() ) {
3250 list<string> log_args_list;
3254 extra.
Print(
"LogRegistry",
"true");
3261 ITERATE(list<string>, it, log_args_list) {
3262 string section, name;
3264 const string&
val = reg.
Get(section, name);
3275 const string& message)
3282 bool need_space =
false;
3303 if ( !
ctx.IsRunning() ) {
3307 "Duplicate request-stop or missing request-start");
3309 str.append(to_string(
ctx.GetRequestStatus())).append(1,
' ')
3310 .append(
ctx.GetRequestTimer().AsString()).append(1,
' ')
3311 .append(to_string(
ctx.GetBytesRd())).append(1,
' ')
3312 .append(to_string(
ctx.GetBytesWr()));
3319 if ( !message.empty() ) {
3323 str.append(message);
3336 CDiagBuffer::DiagHandler(mess);
3433 size_t min_pos = exe_path.length();
3437 if (!it->empty() && (*it)[0] !=
'/') {
3439 string mask =
"/" + *it;
3440 if (
mask[
mask.length() - 1] !=
'/') {
3443 size_t pos = exe_path.find(
mask);
3444 if (pos < min_pos) {
3451 if (exe_path.substr(0, it->length()) == *it) {
3457 if ( !web_dir.empty() ) {
3471 return TLogTruncateParam::GetDefault();
3477 TLogTruncateParam::SetDefault(
value);
3483 if ( !logname.empty() ) {
3514 return config->GetString(
"LOG", name, defval);
3516 string envname =
"NCBI_CONFIG__LOG__";
3529 return config->GetBool(
"LOG", name, defval);
3531 string envname =
"NCBI_CONFIG__LOG__";
3548 const char* cmd_logfile)
3560 CDiagBuffer::GetSeverityChangeEnabledFirstTime();
3569 ctx.InitMessages(
size_t(-1));
3594 bool log_set =
false;
3595 bool to_applog =
false;
3596 string old_log_name;
3597 string new_log_name;
3600 if ( old_handler ) {
3605 if ( config_logfile.empty() ) {
3615 if (cmdline_first && cmd_logfile) {
3618 new_log_name = cmd_logfile;
3623 if (!log_set && !applog_first && !config_logfile.empty()) {
3626 new_log_name = config_logfile;
3630 if (!log_set && !cmdline_first && cmd_logfile &&
3634 new_log_name = cmd_logfile;
3659 ctx.InitMessages(
size_t(-1));
3699 #if defined(NCBI_OS_UNIX)
3711 if ( !log_base.empty() ) {
3715 if ( !def_log_dir.empty() ) {
3719 new_log_name = log_name;
3728 new_log_name = log_name;
3736 new_log_name = config_logfile;
3743 new_log_name = log_name;
3753 new_log_name = log_name;
3757 _TRACE_X(3,
"Failed to set log file to " +
3761 if (!log_set && !cmdline_first && cmd_logfile) {
3764 new_log_name = cmd_logfile;
3770 if (!log_set && log_base.empty()) {
3774 new_log_name = default_fallback;
3778 _TRACE_X(4,
"Failed to set log file to " <<
3781 const char* log_name = TTeeToStderr::GetDefault() ?
3783 if (!log_set && old_log_name != log_name) {
3788 new_log_name = log_name;
3802 ctx.SetOldPostFormat(
false);
3818 if (log_set && new_handler && new_handler->
GetLogName() == old_log_name) {
3826 if ( log_set && new_handler ) {
3827 ctx.FlushMessages(*new_handler);
3833 if ( log_set && new_handler ) {
3834 ctx.FlushMessages(*new_handler);
3838 ctx.DiscardMessages();
3842 ctx.ResetLogRates();
3852 s_ProcessPostCount.
Add(1) : s_ProcessPostCount.
Get());
3882 return s_DiagContext.
Get();
3889 #ifdef NCBI_LOG_FIELDS_CUSTOM
3893 typedef NCBI_PARAM_TYPE(Log, Ncbi_Log_Fields_Custom) TCustomLogFields;
3907 #ifdef NCBI_LOG_FIELDS_CUSTOM
3908 string custom_fields = TCustomLogFields::GetDefault();
3924 if ( it->empty() )
continue;
3965 return sx_GetPostFlags();
3971 bool CDiagBuffer::sm_IgnoreToDie =
false;
3975 bool CDiagBuffer::sm_TraceEnabled;
3978 const char* CDiagBuffer::sm_SeverityName[
eDiag_Trace+1] = {
3979 "Info",
"Warning",
"Error",
"Critical",
"Fatal",
"Trace" };
3997 DEBUG_STACK_TRACE_LEVEL);
4004 static bool s_DiagInitialized =
false;
4005 if (!s_DiagInitialized) {
4007 #ifdef NCBI_OS_MSWIN
4015 s_DiagInitialized =
true;
4036 bool CDiagBuffer::sm_CanDeleteHandler =
true;
4038 bool CDiagBuffer::sm_CanDeleteErrCodeInfo =
false;
4044 static bool s_DefaultDiagHandlerInitialized =
false;
4045 if ( !s_DefaultDiagHandlerInitialized ) {
4046 s_DefaultDiagHandlerInitialized =
true;
4048 if ( TTeeToStderr::GetDefault() ) {
4072 CDiagBuffer::CDiagBuffer(
void)
4074 m_InitialStreamFlags(m_Stream->
flags()),
4080 CDiagBuffer::~CDiagBuffer(
void)
4083 if (m_Diag || m_Stream->pcount())
4098 if ( CDiagBuffer::sm_Handler ) {
4100 if ( CDiagBuffer::sm_Handler ) {
4103 bool show_warning =
false;
4106 mess.
m_Prefix = diag_buf.m_PostPrefix.empty() ?
4107 0 : diag_buf.m_PostPrefix.c_str();
4115 if (
ctx.ApproveMessage(mess, &show_warning) ) {
4137 CDiagBuffer::sm_Handler->
Post(phid_msg);
4139 CDiagBuffer::sm_Handler->
Post(mess);
4141 span->PostEvent(mess);
4144 else if ( show_warning ) {
4148 string limit_name =
"error";
4152 limit_name =
"applog";
4157 limit_name =
"trace";
4160 string txt =
"Maximum logging rate for " + limit_name +
" ("
4164 +
" sec) exceeded, suspending the output.";
4167 txt.c_str(), txt.length(),
4172 err_code_x::eErrCodeX_Corelib_Diag,
4178 CDiagBuffer::sm_Handler->
Post(err_msg);
4188 bool CDiagBuffer::SeverityDisabled(
EDiagSev sev)
4194 bool allow_trace = GetTraceEnabled();
4205 return (sev < post_sev) && (sev < sm_DieSeverity || sm_IgnoreToDie);
4210 bool CDiagBuffer::SeverityPrintable(
EDiagSev sev)
4216 bool allow_trace = GetTraceEnabled();
4227 return !((sev < post_sev) && (sev < sm_DieSeverity || sm_IgnoreToDie));
4231 bool CDiagBuffer::SetDiag(
const CNcbiDiag& diag)
4233 if ( m_InUse || !m_Stream ) {
4239 if (!is_console && SeverityDisabled(sev)) {
4243 if (m_Diag != &diag) {
4266 static bool Check();
4281 #ifndef NCBI_THREADS
4282 thread::id stored_thread_id;
4283 thread::id this_thread_id = this_thread::get_id();
4286 if (
sm_ThreadID.compare_exchange_strong(stored_thread_id, this_thread_id))
return false;
4289 if (stored_thread_id == this_thread_id)
return false;
4291 bool reported =
false;
4294 if (
sm_Reported.compare_exchange_strong(reported,
true))
return true;
4309 const auto msg =
"Detected different threads using C++ Toolkit built in single thread mode."sv;
4328 void CDiagBuffer::Flush(
void)
4330 if ( m_InUse || !m_Diag ) {
4331 if ( !m_InUse && m_Stream && !
IsOssEmpty(*m_Stream) ) {
4334 m_Stream->rdbuf()->PUBSEEKOFF(0, IOS_BASE::beg,
IOS_BASE::out);
4341 EDiagSev sev = m_Diag->GetSeverity();
4342 bool is_console = (m_Diag->GetPostFlags() &
eDPF_IsConsole) != 0;
4343 bool is_disabled = SeverityDisabled(sev);
4346 if (!is_console && is_disabled) {
4354 flags |= sm_TraceFlags;
4361 if ( m_Diag->CheckFilters() ) {
4367 m_Diag->GetErrorCode(),
4368 m_Diag->GetErrorSubCode(),
4370 m_Diag->GetModule(),
4372 m_Diag->GetFunction());
4373 PrintMessage(mess, *m_Diag);
4379 PrintMessage(mess, *m_Diag);
4382 #if defined(NCBI_COMPILER_KCC)
4389 m_Stream->flags(m_InitialStreamFlags);
4390 # ifdef NCBI_SHUN_OSTRSTREAM
4398 if (sev >= sm_DieSeverity && sev !=
eDiag_Trace && !sm_IgnoreToDie) {
4401 #ifdef NCBI_COMPILER_MSVC
4403 int old_mode = _set_error_mode(_OUT_TO_MSGBOX);
4405 _set_error_mode(old_mode);
4420 if (!SeverityPrintable(sev)) {
4425 bool is_disabled = SeverityDisabled(sev);
4426 if (!is_disabled || (is_console && can_collect)) {
4443 bool CDiagBuffer::GetTraceEnabledFirstTime(
void)
4452 sm_TraceEnabled = (sm_TraceDefault ==
eDT_Enable);
4453 return sm_TraceEnabled;
4457 bool CDiagBuffer::GetSeverityChangeEnabledFirstTime(
void)
4473 void CDiagBuffer::UpdatePrefix(
void)
4475 m_PostPrefix.erase();
4476 ITERATE(TPrefixList, prefix, m_PrefixList) {
4477 if (prefix != m_PrefixList.begin()) {
4478 m_PostPrefix +=
"::";
4480 m_PostPrefix += *prefix;
4490 const char*
buf,
size_t len,
4491 const char*
file,
size_t line,
4493 int err_code,
int err_subcode,
4494 const char* err_text,
4497 const char*
function)
4498 : m_Event(eEvent_Start),
4499 m_TypedExtra(
false),
4501 m_PrintStackTrace(
false),
4503 m_Format(eFormat_Auto),
4504 m_AllowBadExtraNames(
false)
4526 switch (app_state) {
4562 m_Event(eEvent_Start),
4563 m_TypedExtra(
false),
4565 m_PrintStackTrace(
false),
4567 m_Format(eFormat_Auto),
4568 m_AllowBadExtraNames(
false)
4604 m_Event(eEvent_Start),
4605 m_TypedExtra(
false),
4607 m_PrintStackTrace(
false),
4609 m_Format(eFormat_Auto),
4610 m_AllowBadExtraNames(
false)
4618 if (&message !=
this) {
4688 if (pos >= message.length()) {
4690 "Failed to parse diagnostic message");
4694 if (message[pos + width] != sep) {
4696 "Missing separator after integer");
4700 width = message.find(sep, pos);
4701 if (width ==
NPOS) {
4703 "Missing separator after integer");
4717 bool optional =
false)
4719 if (pos >= message.length()) {
4721 "Failed to parse diagnostic message");
4724 pos = message.find(sep, pos1);
4728 "Failed to parse diagnostic message");
4733 if ( pos == pos1 + 1 && !optional ) {
4736 "Failed to parse diagnostic message");
4740 pos = message.find_first_not_of(sep, pos);
4742 pos = message.length();
4744 return CTempString(message.c_str() + pos1, pos2 - pos1);
4749 "%00",
"%01",
"%02",
"%03",
"%04",
"%05",
"%06",
"%07",
4750 "%08",
"%09",
"%0A",
"%0B",
"%0C",
"%0D",
"%0E",
"%0F",
4751 "%10",
"%11",
"%12",
"%13",
"%14",
"%15",
"%16",
"%17",
4752 "%18",
"%19",
"%1A",
"%1B",
"%1C",
"%1D",
"%1E",
"%1F",
4753 "+",
"!",
"\"",
"#",
"$",
"%25",
"%26",
"'",
4754 "(",
")",
"*",
"%2B",
",",
"-",
".",
"/",
4755 "0",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
4756 "8",
"9",
":",
";",
"<",
"%3D",
">",
"?",
4757 "@",
"A",
"B",
"C",
"D",
"E",
"F",
"G",
4758 "H",
"I",
"J",
"K",
"L",
"M",
"N",
"O",
4759 "P",
"Q",
"R",
"S",
"T",
"U",
"V",
"W",
4760 "X",
"Y",
"Z",
"[",
"\\",
"]",
"^",
"_",
4761 "`",
"a",
"b",
"c",
"d",
"e",
"f",
"g",
4762 "h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
4763 "p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
4764 "x",
"y",
"z",
"{",
"|",
"}",
"~",
"%7F",
4765 "%80",
"%81",
"%82",
"%83",
"%84",
"%85",
"%86",
"%87",
4766 "%88",
"%89",
"%8A",
"%8B",
"%8C",
"%8D",
"%8E",
"%8F",
4767 "%90",
"%91",
"%92",
"%93",
"%94",
"%95",
"%96",
"%97",
4768 "%98",
"%99",
"%9A",
"%9B",
"%9C",
"%9D",
"%9E",
"%9F",
4769 "%A0",
"%A1",
"%A2",
"%A3",
"%A4",
"%A5",
"%A6",
"%A7",
4770 "%A8",
"%A9",
"%AA",
"%AB",
"%AC",
"%AD",
"%AE",
"%AF",
4771 "%B0",
"%B1",
"%B2",
"%B3",
"%B4",
"%B5",
"%B6",
"%B7",
4772 "%B8",
"%B9",
"%BA",
"%BB",
"%BC",
"%BD",
"%BE",
"%BF",
4773 "%C0",
"%C1",
"%C2",
"%C3",
"%C4",
"%C5",
"%C6",
"%C7",
4774 "%C8",
"%C9",
"%CA",
"%CB",
"%CC",
"%CD",
"%CE",
"%CF",
4775 "%D0",
"%D1",
"%D2",
"%D3",
"%D4",
"%D5",
"%D6",
"%D7",
4776 "%D8",
"%D9",
"%DA",
"%DB",
"%DC",
"%DD",
"%DE",
"%DF",
4777 "%E0",
"%E1",
"%E2",
"%E3",
"%E4",
"%E5",
"%E6",
"%E7",
4778 "%E8",
"%E9",
"%EA",
"%EB",
"%EC",
"%ED",
"%EE",
"%EF",
4779 "%F0",
"%F1",
"%F2",
"%F3",
"%F4",
"%F5",
"%F6",
"%F7",
4780 "%F8",
"%F9",
"%FA",
"%FB",
"%FC",
"%FD",
"%FE",
"%FF"
4802 size_t len =
str.length();
4805 "Empty name in extra-arg", 0);
4809 for (
size_t p = 0; p <
len; dst++) {
4814 "Inavild char in extra arg", p);
4818 if (n1 < 0 || n2 < 0) {
4820 "Inavild char in extra arg", p);
4822 str[dst] = char((n1 << 4) | n2);
4834 "Unencoded special char in extra arg", p);
4916 size_t sl_pos = message.find(
'/', pos);
4917 size_t sp_pos = message.find(
' ', pos);
4918 if (sl_pos < sp_pos) {
4942 static const char* s_TimeFormats[4] = {
4948 else if (
tmp.find(
'.') ==
NPOS) {
4982 bool have_severity =
false;
4983 size_t severity_pos = pos;
4985 if ( !
tmp.empty() ) {
4987 size_t sev_pos =
NPOS;
4988 if (
tmp.length() == 10 &&
tmp.find(
"Message[") == 0) {
4991 else if (
tmp.length() == 7 &&
tmp.find(
"Note[") == 0) {
4995 if (sev_pos !=
NPOS) {
4997 switch (
tmp[sev_pos] ) {
5020 have_severity =
true;
5027 if ( have_severity ) {
5028 pos = message.find_first_not_of(
' ', pos);
5030 pos = message.length();
5037 if (
tmp.empty() && severity_pos < message.length()) {
5039 pos = message.length();
5049 if (pos < message.length()) {
5051 pos = message.length();
5060 if (pos < message.length()) {
5062 pos = message.length();
5068 if (pos < message.length()) {
5071 size_t msg_end = message.find_first_not_of(
' ', pos);
5072 msg_end = message.find_first_of(
' ', msg_end);
5073 msg_end = message.find_first_not_of(
' ', msg_end);
5074 msg_end = message.find_first_of(
' ', msg_end);
5075 size_t extra_pos = message.find_first_not_of(
' ', msg_end);
5077 substr(0, msg_end - pos);
5082 pos = message.length();
5091 if (pos < message.length()) {
5102 size_t sep_pos = message.find(
" --- ", pos);
5105 if (pos < sep_pos && message[pos] !=
'"') {
5106 size_t mod_pos = pos;
5108 size_t lbr =
tmp.find(
"(");
5110 if (
tmp[
tmp.length() - 1] !=
')') {
5113 while (open_br > 0 && pos < message.length()) {
5114 if (message[pos] ==
'(') {
5117 else if (message[pos] ==
')') {
5122 if (message[pos] !=
' ' || pos >= message.length()) {
5127 pos = message.find_first_not_of(
' ', pos);
5129 pos = message.length();
5134 size_t dot_pos =
tmp.find(
'.');
5135 if (dot_pos !=
NPOS) {
5160 if (pos < sep_pos && message[pos] ==
'"') {
5166 if (
CTempString(message.c_str() + pos, 7) !=
", line ") {