1 #ifndef CORELIB___NCBIDIAG__HPP
2 #define CORELIB___NCBIDIAG__HPP
74 const char* curr_funct =
NULL,
75 const char* module =
NULL);
79 const string& curr_funct,
80 const string& module);
131 #if defined(__GNUC__) || (defined(__MWERKS__) && (__MWERKS__ >= 0x3000)) || (defined(__ICC) && (__ICC >= 600))
132 # define NCBI_CURRENT_FUNCTION __PRETTY_FUNCTION__
133 #elif defined(__FUNCSIG__)
134 # define NCBI_CURRENT_FUNCTION __FUNCSIG__
135 #elif (defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 600)) || (defined(__IBMCPP__) && (__IBMCPP__ >= 500))
136 # define NCBI_CURRENT_FUNCTION __FUNCTION__
137 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x550)
138 # define NCBI_CURRENT_FUNCTION __FUNC__
139 #elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901)
140 # define NCBI_CURRENT_FUNCTION __func__
142 # define NCBI_CURRENT_FUNCTION NCBI_NS_NCBI::g_DiagUnknownFunction()
149 #define NCBI_MAKE_MODULE(module) NCBI_AS_STRING(module)
170 #define DIAG_COMPILE_INFO \
171 NCBI_NS_NCBI::CDiagCompileInfo(__FILE__, \
173 NCBI_CURRENT_FUNCTION, \
174 NCBI_MAKE_MODULE(NCBI_MODULE))
186 #define ERR_POST(message) \
187 ( NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO).GetRef() \
189 << NCBI_NS_NCBI::Endm )
196 #define SEVERITY_POST(severity, message) \
197 do if (NCBI_NS_NCBI::IsVisibleDiagPostLevel(NCBI_NS_NCBI::eDiag_##severity)) \
198 ERR_POST(severity << message); \
200 #define WARNING_POST(message) SEVERITY_POST(Warning, message)
201 #define INFO_POST(message) SEVERITY_POST(Info, message)
202 #define TRACE_POST(message) SEVERITY_POST(Trace, message)
203 #define SEVERITY_POST_X(severity, subcode, message) \
204 do if (NCBI_NS_NCBI::IsVisibleDiagPostLevel(NCBI_NS_NCBI::eDiag_##severity)) \
205 ERR_POST_X(subcode, severity << message); \
207 #define WARNING_POST_X(subcode, message) SEVERITY_POST_X(Warning, subcode, message)
208 #define INFO_POST_X(subcode, message) SEVERITY_POST_X(Info, subcode, message)
209 #define TRACE_POST_X(subcode, message) SEVERITY_POST_X(Trace, subcode, message)
210 #define SEVERITY_POST_EX(severity, errcode, subcode, message) \
211 do if (NCBI_NS_NCBI::IsVisibleDiagPostLevel(NCBI_NS_NCBI::eDiag_##severity)) \
212 ERR_POST_EX(errcode, subcode, severity << message); \
214 #define WARNING_POST_EX(errcode, subcode, message) SEVERITY_POST_EX(Warning, errcode, subcode, message)
215 #define INFO_POST_EX(errcode, message) SEVERITY_POST_EX(Info, errcode, subcode, message)
216 #define TRACE_POST_EX(errcode, message) SEVERITY_POST_EX(Trace, errcode, subcode, message)
226 #define LOG_POST(message) \
227 ( NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO, \
228 NCBI_NS_NCBI::eDiag_Error, \
229 NCBI_NS_NCBI::eDPF_Log | NCBI_NS_NCBI::eDPF_IsNote).GetRef() \
231 << NCBI_NS_NCBI::Endm )
240 #define ERR_FATAL(message) \
241 NCBI_NS_NCBI::EndmFatal(NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO, \
242 NCBI_NS_NCBI::eDiag_Fatal).GetRef() << message )
252 #define ERR_POST_EX(err_code, err_subcode, message) \
253 ( NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO).GetRef() \
254 << NCBI_NS_NCBI::ErrCode( (err_code), (err_subcode) ) \
256 << NCBI_NS_NCBI::Endm )
258 #define LOG_POST_EX(err_code, err_subcode, message) \
259 ( NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO, \
260 NCBI_NS_NCBI::eDiag_Error, \
261 NCBI_NS_NCBI::eDPF_Log | NCBI_NS_NCBI::eDPF_IsNote).GetRef() \
262 << NCBI_NS_NCBI::ErrCode( (err_code), (err_subcode) ) \
264 << NCBI_NS_NCBI::Endm )
266 #define ERR_FATAL_EX(err_code, err_subcode, message) \
267 NCBI_NS_NCBI::EndmFatal(NCBI_NS_NCBI::CNcbiDiag(DIAG_COMPILE_INFO, \
268 NCBI_NS_NCBI::eDiag_Fatal).GetRef() << \
269 NCBI_NS_NCBI::ErrCode( (err_code), (err_subcode) ) << message )
297 #define NCBI_DEFINE_ERRCODE_X(name, err_code, max_err_subcode) \
298 namespace err_code_x { \
300 eErrCodeX_##name = err_code, \
301 eErrCodeX_Max_##name = max_err_subcode \
303 template <bool dummy> \
304 struct SErrCodeX_Max_##name { \
306 value = max_err_subcode, \
307 dumm_dumm = int(dummy) \
311 NCBI_EAT_SEMICOLON(err_code)
333 #define NCBI_DEFINE_ERR_SUBCODE_X(max_err_subcode) \
334 NCBI_DEFINE_ERR_SUBCODE_XX(NCBI_USE_ERRCODE_X, max_err_subcode)
354 #define NCBI_DEFINE_ERR_SUBCODE_XX(name, max_err_subcode) \
355 NCBI_CHECK_ERRCODE_USAGE(name) \
356 namespace err_code_x { \
358 struct NCBI_NAME2(SErrCodeX_Max_, name)<true> { \
360 value = max_err_subcode \
369 #define NCBI_ERRCODE_X_NAME(name) \
370 NCBI_NS_NCBI::err_code_x::NCBI_NAME2(eErrCodeX_, name)
376 #define NCBI_ERRCODE_X NCBI_ERRCODE_X_NAME(NCBI_USE_ERRCODE_X)
381 #define NCBI_MAX_ERR_SUBCODE_X_NAME(name) \
382 NCBI_NS_NCBI::err_code_x::NCBI_NAME2(SErrCodeX_Max_, name)<true>::value
387 #define NCBI_MAX_ERR_SUBCODE_X \
388 NCBI_MAX_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X)
402 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode,
bool isWrong>
407 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode>
409 <errorCode, errorSubcode, maxErrorSubcode,
false> {
419 template <
int errorCode,
bool isWrong>
425 template <
int errorCode>
432 #define NCBI_CHECK_ERRCODE_USAGE(name) \
433 inline void NCBI_NAME2(s_ErrCodeCheck_, name) ( \
434 NCBI_NS_NCBI::WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO < \
435 NCBI_ERRCODE_X_NAME(name), \
436 NCBI_NS_NCBI::err_code_x::eErrCodeX_Max_##name != 0> \
452 #define NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode) \
453 NCBI_NS_NCBI::CheckErrSubcodeX( \
454 (int)sizeof(NCBI_NS_NCBI::WRONG_ERROR_SUBCODE_IN_POST_MACRO< \
455 NCBI_ERRCODE_X_NAME(name), subcode, \
456 NCBI_MAX_ERR_SUBCODE_X_NAME(name), \
457 ((unsigned int)subcode > \
458 (unsigned int)NCBI_MAX_ERR_SUBCODE_X_NAME(name)) \
464 #define NCBI_CHECK_ERR_SUBCODE_X(subcode) \
465 NCBI_CHECK_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X, subcode)
468 #define NCBI_ERR_SUBCODE_X_NAME(name, subcode) \
469 (NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode), subcode)
472 #define NCBI_ERR_SUBCODE_X(subcode) \
473 (NCBI_CHECK_ERR_SUBCODE_X(subcode), subcode)
475 #if defined(NCBI_COMPILER_ICC) || defined(NCBI_COMPILER_MIPSPRO)
480 struct WRONG_ERROR_SUBCODE_IN_POST_MACRO_2;
488 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode>
490 <errorCode, errorSubcode, maxErrorSubcode,
true> {
491 typedef char t[
sizeof(WRONG_ERROR_SUBCODE_IN_POST_MACRO_2<errorCode>)];
497 struct WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO_2;
505 template <
int errorCode>
507 typedef char t[
sizeof(
508 WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO_2<errorCode>)];
550 #define ERR_POST_X(err_subcode, message) \
551 ERR_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
553 #define LOG_POST_X(err_subcode, message) \
554 LOG_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
556 #define ERR_FATAL_X(err_subcode, message) \
557 ERR_FATAL_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
564 #define ERR_POST_XX(error_name, err_subcode, message) \
565 ERR_POST_EX(NCBI_ERRCODE_X_NAME(error_name), \
566 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
569 #define LOG_POST_XX(error_name, err_subcode, message) \
570 LOG_POST_EX(NCBI_ERRCODE_X_NAME(error_name), \
571 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
574 #define ERR_FATAL_XX(error_name, err_subcode, message) \
575 ERR_FATAL_EX(NCBI_ERRCODE_X_NAME(error_name), \
576 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
582 #define NCBI_REPEAT_POST_N_TIMES(post_macro, count, params) \
584 static atomic<int> sx_to_show(count); \
585 int to_show = sx_to_show; \
586 if ( to_show > 0 ) { \
587 sx_to_show = to_show - 1; \
594 #define ERR_POST_N_TIMES(count, message) \
595 NCBI_REPEAT_POST_N_TIMES( ERR_POST, count, (message) )
597 #define LOG_POST_N_TIMES(count, message) \
598 NCBI_REPEAT_POST_N_TIMES( LOG_POST, count, (message) )
602 #define ERR_POST_ONCE(message) ERR_POST_N_TIMES(1, message)
604 #define LOG_POST_ONCE(message) LOG_POST_N_TIMES(1, message)
611 #define ERR_POST_X_N_TIMES(count, err_subcode, message) \
612 NCBI_REPEAT_POST_N_TIMES( ERR_POST_X, count, (err_subcode, message) )
614 #define LOG_POST_X_N_TIMES(count, err_subcode, message) \
615 NCBI_REPEAT_POST_N_TIMES( LOG_POST_X, count, (err_subcode, message) )
621 #define ERR_POST_X_ONCE(err_subcode, message) \
622 ERR_POST_X_N_TIMES(1, err_subcode, message)
624 #define LOG_POST_X_ONCE(err_subcode, message) \
625 LOG_POST_X_N_TIMES(1, err_subcode, message)
631 #define ERR_POST_XX_N_TIMES(count, error_name, err_subcode, message) \
632 NCBI_REPEAT_POST_N_TIMES( ERR_POST_XX, count, \
633 (error_name, err_subcode, message) )
635 #define LOG_POST_XX_N_TIMES(count, error_name, err_subcode, message) \
636 NCBI_REPEAT_POST_N_TIMES( LOG_POST_XX, count, \
637 (error_name, err_subcode, message) )
643 #define ERR_POST_XX_ONCE(error_name, err_subcode, message) \
644 ERR_POST_XX_N_TIMES(1, error_name, err_subcode, message)
646 #define LOG_POST_XX_ONCE(error_name, err_subcode, message) \
647 LOG_POST_XX_N_TIMES(1, error_name, err_subcode, message)
721 #if defined(NCBI_THREADS)
949 template<
class X>
const CNcbiDiag&
Put(
const volatile void*,
const X& x)
const;
955 typedef IOS_BASE& (*FIosbaseManip)(IOS_BASE&);
974 template<
class X>
inline
979 template<
class X>
inline
1005 const NCBI_NS_NCBI::SetPostFlags&
flags)
const;
1013 return manip(*
this);
1017 return manip(*
this);
1165 const char* message);
1169 const char* message =
NULL);
1174 const char* expression,
1175 const char* message =
NULL);
1181 const char* expression,
1182 const char* message =
NULL);
1187 const char* expression,
1188 const char* message);
1331 EAction action = eDiscard);
1346 void SetPrintSeverity(
EDiagSev sev);
1352 void SetCollectSeverity(
EDiagSev sev);
1373 void Release(EAction action);
1376 void x_Init(
EDiagSev print_severity,
1447 #define DIAG_POST_LEVEL "DIAG_POST_LEVEL"
1537 extern void Abort(
void);
1540 #define DIAG_TRACE "DIAG_TRACE"
1609 const char*
file = 0,
size_t line = 0,
1611 int err_code = 0,
int err_subcode = 0,
1612 const char* err_text = 0,
1613 const char* module = 0,
1614 const char* nclass = 0,
1615 const char*
function = 0);
1632 bool ParseMessage(
const string& message);
1649 static string GetEventName(EEventType event);
1690 string FormatExtraMessage(
void)
const;
1693 TUID GetUID(
void)
const;
1695 CTime GetTime(
void)
const;
1717 const string&
GetHost(
void)
const;
1718 string GetClient(
void)
const;
1719 string GetSession(
void)
const;
1720 const string& GetAppName(
void)
const;
1725 string x_GetModule(
void)
const;
1728 static void s_UnescapeNewlines(
string&
buf);
1736 bool x_ParseExtraArgs(
const string&
str,
size_t pos);
1744 bool x_IsSetOldFormat(
void)
const;
1748 void x_InitData(
void)
const;
1750 void x_SaveContextData(
void)
const;
1763 return mess.
Write(os);
1823 template<
class TKey,
class TStorage>
class CStrictId;
1844 #if !NCBI_INT8_IS_LONG
1847 #elif SIZEOF_LONG_LONG
1856 template<
class TKey,
class TStorage>
1897 void x_Release(
void);
1898 bool x_CanPrint(
void);
1938 static TPID GetPID(
void);
1940 static bool UpdatePID(
void);
1941 static bool UpdatePID_AsyncSafe(
void);
1945 fOnFork_PrintStart = 1 << 0,
1946 fOnFork_ResetTimer = 1 << 1,
1947 fOnFork_AsyncSafe = 1 << 15
1978 TUID GetUID(
void)
const;
1981 string GetStringUID(
TUID uid = 0)
const;
1985 TUID UpdateUID(
TUID uid = 0)
const;
1988 void GetStringUID(
TUID uid,
char*
buf,
size_t buf_len)
const;
1991 void GetStringUID(
TUID uid,
char*
buf)
const;
1994 string GetNextHitID(
void)
const;
2010 void SetAutoWrite(
bool value);
2027 void SetProperty(
const string& name,
2028 const string&
value,
2029 EPropertyMode
mode = eProp_Default);
2036 string GetProperty(
const string& name,
2037 EPropertyMode
mode = eProp_Default)
const;
2043 void DeleteProperty(
const string& name,
2044 EPropertyMode
mode = eProp_Default);
2049 void PrintProperties(
void);
2082 void PrintStart(
const string& message);
2085 void PrintStop(
void);
2109 void PrintRequestStop(
void);
2130 static bool IsSetOldPostFormat(
void);
2132 static void SetOldPostFormat(
bool value);
2135 static bool IsUsingSystemThreadId(
void);
2137 static void UseSystemThreadId(
bool value =
true);
2140 const string& GetUsername(
void)
const;
2143 void SetUsername(
const string& username);
2147 const string&
GetHost(
void)
const;
2149 const string& GetEncodedHost(
void)
const;
2152 const string& GetHostname(
void)
const;
2154 const string& GetEncodedHostname(
void)
const;
2157 void SetHostname(
const string& hostname);
2162 void SetHostIP(
const string&
ip);
2165 const string& GetAppName(
void)
const;
2167 const string& GetEncodedAppName(
void)
const;
2169 void SetAppName(
const string& app_name);
2178 m_ExitCode = exit_code;
2179 m_ExitCodeSet =
true;
2190 string GetDefaultSessionID(
void)
const;
2193 void SetDefaultSessionID(
const string& session_id);
2196 string GetSessionID(
void)
const;
2198 string GetEncodedSessionID(
void)
const;
2203 static string GetDefaultClientIP(
void);
2207 static void SetDefaultClientIP(
const string& client_ip);
2214 string GetDefaultHitID(
void)
const;
2218 void SetDefaultHitID(
const string& hit_id);
2221 static const string& GetHostRole(
void);
2224 static const string& GetHostLocation(
void);
2234 void InitMessages(
size_t max_size = 100);
2241 void DiscardMessages(
void);
2246 static bool GetLogTruncate(
void);
2248 static void SetLogTruncate(
bool value);
2255 static bool IsUsingRootLog(
void);
2263 const char* cmd_logfile =
NULL);
2273 static TTID GetTID(
void);
2283 unsigned int GetLogRate_Limit(ELogRate_Type
type)
const;
2284 void SetLogRate_Limit(ELogRate_Type
type,
unsigned int limit);
2287 unsigned int GetLogRate_Period(ELogRate_Type
type)
const;
2288 void SetLogRate_Period(ELogRate_Type
type,
unsigned int period);
2291 static void x_FinalizeSetupDiag(
void);
2297 {
return sm_ApplogSeverityLocked; }
2299 { sm_ApplogSeverityLocked = lock; }
2301 static bool IsMainThreadDataInitialized(
void);
2308 void x_CreateUID(
void)
const;
2309 void x_CreateUID_AsyncSafe(
void)
const;
2313 const string& message);
2315 static void x_StartRequest(
void);
2317 static void x_LogEnvironment(
void);
2323 void ResetLogRates(
void);
2329 void* cleanup_data);
2331 friend class CDiagBuffer;
2341 bool x_DiagAtApplicationLevel(
void)
const;
2342 bool x_IsSetDefaultHitID(
void)
const;
2343 CSharedHitId x_GetDefaultHitID(EDefaultHitIDFlags flag)
const;
2344 string x_GetNextHitID(
bool is_default)
const;
2346 void x_LogHitID_WithLock(
void)
const;
2407 template<
class TEntries>
2411 for (
typename TEntries::const_iterator it =
entries.begin(); it !=
entries.end(); ++it) {
2412 x_Match(it->first, it->second, extra);
2463 virtual void WriteMessage(
const char*
buf,
2468 virtual string GetLogName(
void);
2493 bool can_delete =
true);
2498 bool* current_ownership = 0);
2578 virtual string GetLogName(
void);
2582 void SetLogName(
const string& log_name);
2585 char m_LogName[2048];
2607 bool quick_flush =
true,
2608 const string& stream_name =
"");
2656 virtual void WriteMessage(
const char*
buf,
2668 virtual void Reopen(TReopenFlags
flags);
2671 virtual void SetLogName(
const string& log_name);
2715 virtual void WriteMessage(
const char*
buf,
2756 virtual void SetLogName(
const string& log_name);
2812 void InstallToDiag(
void);
2818 void RemoveFromDiag(
void);
2822 void SetCustomThreadSuffix(
const string& suffix);
2826 virtual string GetLogName(
void);
2848 bool quick_flush =
true,
2850 void* cleanup_data = 0,
2851 const string& stream_name =
""
2882 bool quick_flush =
true);
2950 void*
operator new (size_t) {
throw runtime_error(
"forbidden"); }
2956 void*
operator new[] (size_t) {
throw runtime_error(
"forbidden"); }
2962 void operator delete (
void*) { }
2968 void operator delete[] (
void*) { }
3000 const string& explanation,
3005 : m_Message(message),
3006 m_Explanation(explanation),
3007 m_Severity(severity)
3064 bool GetDescription(
const ErrCode& err_code,
3092 #define DIAG_MESSAGE_FILE "MessageFile"
3102 bool can_delete =
true);
Guard for collecting diag messages (affects the current thread only).
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
Thread local context data stored in TLS.
CFileHandleDiagHandler –.
Helper class to hold hit id and sub-hit counter which can be shared between multiple request contexts...
CStreamDiagHandler_Base –.
Template class for strict ID types.
Callback interface for stream parser.
void(*)(CSeq_entry_Handle seh, IWorkbench *wb, const CSerialObject &obj) handler
void Print(const CCompactSAMApplication::AlignInfo &ai)
static void cleanup(void)
static const char * str(char *buf, int n)
int m_ErrSubCode
Sub Error code.
int GetErrorSubCode(void) const
Get error subcode of the current message.
TDiagPostFlags GetPostFlags(void) const
Get post flags for the current message.
virtual CDiagHandler * New(const string &s)=0
Factory method interface.
string m_Explanation
Error message (with detailed explanation)
void Write(string &str, TDiagWriteFlags flags=fNone) const
Binary OR of "EDiagWriteFlags".
void SetDiagFilter(EDiagFilter what, const char *filter_str)
Set diagnostic filter.
TExtraArgs m_ExtraArgs
If event type is "extra", contains the list of arguments.
void PushDiagPostPrefix(const char *prefix)
Push a string to the list of message prefixes.
void Clear(void)
Delete all stored error descriptions from memory.
void ParseCurrFunctName(void) const
const char * GetModule(void) const
Get module name of the current message.
void SetDescription(const ErrCode &err_code, const SDiagErrCodeDescription &description)
Set error description for specified error code.
string m_PostPrefix
Message prefix.
TCount m_RequestId
FastCGI iteration or request ID.
EDiagPostFlag
Which parts of the diagnostic context should be posted.
EDiagSev GetDiagPostLevel(void)
Get current threshold severity for posting the messages.
SetPostFlags(TDiagPostFlags flags)
void SetDiagPostFlag(EDiagPostFlag flag)
Set the specified flag (globally).
static const char * kProperty_UserName
Global properties.
EDiagSevChange
Severity level change state.
friend const CNcbiDiag & Message(const CNcbiDiag &diag)
Set IsMessage flag to indicate that the current post is a message.
bool m_AllowBadExtraNames
unique_ptr< CEncodedString > m_Username
int m_Code
Major error code number.
TDiagPostFlags m_PostFlags
Bitwise OR of "EDiagPostFlag".
CStreamDiagHandler_Base * m_Perf
string m_StrCurrFunctName
const char * m_File
File name.
EDiagSev m_PostSeverity
Post severity.
Uint8 TCount
Generic type for counters (posts, requests etc.)
const char * m_Buffer
Not guaranteed to be '\0'-terminated!
void SetModule(const string &module)
CStreamDiagHandler_Base * m_Trace
const CNcbiDiag & SetClass(const char *nclass) const
Set class name.
CNcbiOstream * m_Stream
Diagnostic stream.
CDiagErrCodeInfo(void)
Constructor.
CDiagContext & GetDiagContext(void)
Get diag context instance.
void(* FAbortHandler)(void)
Abort handler function type.
CDiagErrCodeInfo(CNcbiIstream &is)
Constructor – can throw runtime_error.
bool HaveDescription(const ErrCode &err_code) const
Check if error description exists.
EDiagSev m_Severity
Severity level of current msg.
map< string, string > TProperties
const CNcbiDiag &(* FManip)(const CNcbiDiag &)
Diagnostic stream manipulator.
void SetDiagFixedPostLevel(EDiagSev post_sev)
Sets and locks the level, combining the previous two calls.
void SetAction(EAction action)
Specify on-destroy action.
Uint8 GetStartingPoint(void) const
Get the lowest thread-local post number in this guard's scope.
void SetSplitLogFile(bool value=true)
Split log files flag.
EDiagCollectMessages
Flags to control collecting messages and flushing them to the new destination when switching diag han...
const char * m_Module
Module name.
static const char * kProperty_AppName
static const char * kProperty_ClientIP
MDiagClass(const char *nclass)
void SetAllPostFlags(TDiagPostFlags flags) const
Set new post flags for the current message.
static bool sm_ApplogSeverityLocked
bool m_TraceEnabled
Trace enabled?
void DiagHandler_Reopen(void)
Ask diagnostic handler to reopen log files if necessary.
string GetDiagFilter(EDiagFilter what)
Get current diagnostic filter.
friend const CNcbiDiag & StackTrace(const CNcbiDiag &diag)
Print stack trace.
int GetExitSignal(void) const
Get exit signal.
virtual void Reopen(TReopenFlags)
Reopen file to enable log rotation.
unique_ptr< CRequestRateControl > m_TraceLogRC
const CNcbiDiag & Put(const FManip, const FManip &manip) const
Helper method to handle various diagnostic stream manipulators.
CAsyncDiagThread * m_AsyncThread
Thread handling all physical printing of log messages.
atomic< bool > m_ErrLogSuspended
CDiagContext_Extra Extra(void) const
Create a temporary CDiagContext_Extra object.
void CheckErrSubcodeX(int)
Additional dummy function for use in NCBI_CHECK_ERR_SUBCODE_X macro.
friend const CNcbiDiag & Fatal(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to FATAL.
list< SDiagMessage > TMessages
TCount m_ProcPost
Number of the post in the process.
const CNcbiDiag & SetLine(size_t line) const
Set line number for post.
bool DisableDiagPostLevelChange(bool disable_change=true)
Disable change the diagnostic post level.
bool IsCollectingMessages(void) const
Check if message collecting is on.
CDiagErrCodeInfo(const string &file_name)
Constructor – can throw runtime_error.
int GetErrorCode(void) const
Get error code of the current message.
friend const CNcbiDiag & Console(const CNcbiDiag &diag)
Set IsConsole flag to indicate that the current post should go to console regardless of its severity ...
bool IsSetExitCode(void) const
Check if exit code has been set.
int m_ErrSubCode
Error subcode.
const CNcbiDiag & SetErrorCode(int code=0, int subcode=0) const
Set error code and subcode numbers.
size_t m_Line
Line number in file.
CNcbiDiag(const CNcbiDiag &)
Private copy constructor to prohibit copy.
void SetDiagRequestId(Uint8 id)
Set iteration number/request ID.
CDiagBuffer & m_Buffer
This thread's error msg. buffer.
static const char * kProperty_ExitSig
bool CheckFilters(const CException *ex=NULL) const
Check if filters are passed for the current message.
friend const CNcbiDiag & Info(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to INFO.
bool m_CanDeleteErrCodeInfo
Can delete err code info?
const CNcbiDiag & Put(const CException *, const X &x) const
Helper method to post an exception to diagnostic stream.
int TDiagPostFlags
Binary OR of "EDiagPostFlag".
EDiagSev m_Severity
Severity level.
const string & GetClass(void) const
bool GetSplitLogFile(void)
Get split log files flag.
virtual void operator()(SDiagMessage &msg)=0
~CNcbiDiag(void)
Destructor.
bool m_QuickFlush
Quick flush of stream flag.
unique_ptr< TMessages > m_Messages
const CNcbiDiag & Put(const exception *, const X &x) const
bool GetOmitStackTrace(void) const
friend const CNcbiDiag & Note(const CNcbiDiag &diag)
Set IsNote flag to indicate that the current post is a note.
void SetSeverityCap(EDiagSev sev)
Set new severity cap for use in PrintCapped mode.
EDiagWriteFlags
Compose a message string in the standard format(see also "flags"): "<file>", line <line>: <severity>:...
unique_ptr< CEncodedString > m_Host
CNcbiIos &(* FIosManip)(CNcbiIos &)
EAppDiagStream
Where to write the application's diagnostics to.
EDiagTrace m_TraceDefault
Default trace setting.
Uint8 TTID
Get thread ID used in messages.
void UnsetDiagTraceFlag(EDiagPostFlag flag)
EPostNumberIncrement
Post number increment flag for GetProcessPostNumber() and GetThreadPostNumber().
const char * m_Prefix
Prefix string.
const char * GetFile(void) const
virtual void Post(const SDiagMessage &mess)=0
Post message to handler.
friend const CNcbiDiag & operator<<(const CNcbiDiag &diag, const MDiagFunction &function)
EDiagSev GetDiagDieLevel(void)
Get the "die" (abort) level for the program.
const CNcbiDiag & GetRef(void) const
Some compilers (e.g.
string m_Message
Error message (short)
const CNcbiDiag & Put(const ErrCode *, const ErrCode &err_code) const
Helper method to post error code and subcode to diagnostic stream.
const CNcbiDiag & operator<<(FManip manip) const
virtual ~INextDiagMessage(void)
bool IsDiagStream(const CNcbiOstream *os)
size_t GetLine(void) const
Get line number for the current message.
bool IsVisibleDiagPostLevel(EDiagSev sev)
Check if the specified severity is higher or equal to the currently selected post level and will be p...
EEventType
Type of event to report.
TDiagPostFlags m_Flags
Bitwise OR of "EDiagPostFlag".
SDiagErrCodeDescription(const string &message, const string &explanation, int severity=-1)
Destructor.
bool m_NoTee
Special flag indicating that the message should not be printed by Tee-handler.
static CDiagContext * sm_Instance
EDiagSev m_DieSeverity
Die level severity.
const CNcbiDiag & Put(const Severity *, const Severity &severity) const
Helper method to set severity level.
map< ErrCode, SDiagErrCodeDescription > TInfo
Define map for error messages.
atomic< bool > m_AppLogSuspended
void PopDiagPostPrefix(void)
Pop a string from the list of message prefixes.
void AppendDiagFilter(EDiagFilter what, const char *filter_str)
Append diagnostic filter.
static void DiagTrouble(const CDiagCompileInfo &info, const char *message=NULL)
Display trouble error message.
MDiagModule(const char *module)
static const char * kProperty_ReqTime
bool GetDiagTrace(void)
Check if traces are enabled.
void SetFastCGIIteration(Uint8 id)
CStopWatch * m_ReopenTimer
static void SetApplogSeverityLocked(bool lock)
const CNcbiDiag & SetFile(const char *file) const
Set file name to post.
CNcbiDiag(EDiagSev sev=eDiag_Error, TDiagPostFlags post_flags=eDPF_Default)
Constructor.
CStopWatch * m_ReopenTimer
CStreamDiagHandler_Base * m_Log
const string & GetHostIP(void) const
Get host IP address.
TCount m_ThrPost
Number of the post in the thread.
friend const CNcbiDiag & Trace(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to TRACE.
EDiagSevChange m_PostSeverityChange
Severity change.
int m_Severity
Message severity (if less that 0, then use current diagnostic severity level)
int CompareDiagPostLevel(EDiagSev sev1, EDiagSev sev2)
Compare two severities.
static const char * kProperty_ExitCode
void UnsetDiagPostFlag(EDiagPostFlag flag)
Unset the specified flag (globally).
unique_ptr< CStopWatch > m_StopWatch
CDiagHandler * GetDiagHandler(bool take_ownership=false, bool *current_ownership=0)
Get the currently set diagnostic handler class.
void SetDiagPostPrefix(const char *prefix)
Specify a string to prefix all subsequent error postings with.
void ResetIsConsoleFlag(void) const
Reset IsConsole flag.
void SetDoubleDiagHandler(void)
Output diagnostics using both old and new style handlers.
EDiagSev SetDiagDieLevel(EDiagSev die_sev=eDiag_Fatal)
Set the "die" (abort) level for the program.
NCBI_XNCBI_EXPORT void Abort(void)
Smart abort function.
IOS_BASE &(* FIosbaseManip)(IOS_BASE &)
void x_EndMess(void) const
Private replacement for Endm called from manipulators.
const CNcbiDiag & SetFunction(const char *function) const
Set function name.
static void DiagValidate(const CDiagCompileInfo &info, const char *expression, const char *message)
Display validation message.
list< TExtraArg > TExtraArgs
size_t m_BufferLen
Length of m_Buffer.
static const char * kProperty_HostName
void SetDiagErrCodeInfo(CDiagErrCodeInfo *info, bool can_delete=true)
Set handler for processing error codes.
static void DiagAssertIfSuppressedSystemMessageBox(const CDiagCompileInfo &info, const char *expression, const char *message=NULL)
Same as DiagAssert but only if the system message box is suppressed.
static TDiagPostFlags ForceImportantFlags(TDiagPostFlags flags)
Set important flags to their globally set values.
TDiagPostFlags SetPostFlags(TDiagPostFlags flags) const
Set specific post flags for the current message.
static const char * SeverityName(EDiagSev sev)
Get a common symbolic name for the severity levels.
EDiagSev SetDiagPostLevel(EDiagSev post_sev=eDiag_Error)
Set the threshold severity for posting the messages.
EDiagTrace
Which setting disables/enables posting of "eDiag_Trace" messages.
EAction
Action to perform in guard's destructor.
ELogRate_Type
Type of logging rate limit.
void SetExitCode(int exit_code)
Set exit code.
CDiagFileHandleHolder * m_Handle
friend const CNcbiDiag & Reset(const CNcbiDiag &diag)
Reset the content of current message.
friend const CNcbiDiag & Critical(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to CRITICAL ERROR.
FOnForkAction
Actions to perform in UpdateOnFork().
void SetOmitStackTrace(bool value)
friend const CNcbiDiag & Warning(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to WARNING.
void(* FDiagHandler)(const SDiagMessage &mess)
Diagnostic handler function type.
void SetExitSignal(int exit_sig)
Set exit signal.
SDiagMessage::EEventType m_EventType
const char * m_Class
Class name.
deque< SDiagMessage > TMessages
Save messages if the handle is unavailable.
EDiagSev GetSeverityCap(void) const
Get current severity cap for use in ePrintCapped mode.
~CDiagErrCodeInfo(void)
Destructor.
TDiagPostFlags m_PostFlags
Post flags.
CStreamDiagHandler_Base TParent
pair< string, string > TExtraArg
static NCBI_XNCBI_EXPORT void DiagAssert(const CDiagCompileInfo &info, const char *expression, const char *message=NULL)
Assert specified expression and report results.
static const char * kProperty_BytesRd
EDiagSev GetCollectSeverity(void) const
Get current collect severity.
SDiagMessage::TCount TCount
bool IsSetDiagPostFlag(EDiagPostFlag flag, TDiagPostFlags flags=eDPF_Default)
Check if a specified flag is set.
TInfo m_Info
Map storing error codes and descriptions.
void x_SetFormat(EFormatFlag fmt) const
const char * GetFunction(void) const
Get function name of the current message.
const CNcbiDiag & Put(const volatile void *, const X &x) const
Generic method to post to diagnostic stream.
virtual CNcbiOstream * GetStream(void)
TDiagPostFlags m_Flags
flags to set
EDiagFileType
CDiagHandler –.
EDiagAppState
Application execution states shown in the std prefix.
friend const CNcbiDiag & Endm(const CNcbiDiag &diag)
Flush current message, start new one.
friend const CNcbiDiag & Error(const CNcbiDiag &diag)
Flush current message, then set a severity for the next diagnostic message to ERROR.
void(* FDiagCleanup)(void *data)
Diagnostic cleanup function type.
CDiagCompileInfo m_CompileInfo
list< string > m_PrefixList
List of prefixes.
CStreamDiagHandler_Base * m_Err
bool m_ApplogSeverityLocked
Limiting applog post level?
TDiagPostFlags SetDiagTraceAllFlags(TDiagPostFlags flags)
Versions of the above for extra trace flags.
const CNcbiDiag & x_Put(const CException &ex) const
Helper func for the exception-related Put()
bool SetLogFile(const string &file_name, EDiagFileType file_type=eDiagFile_All, bool quick_flush=true)
Set log files.
static const char * kProperty_SessionID
bool IsSetDiagHandler(void)
Check if diagnostic handler is set.
virtual ~CDiagHandler(void)
Destructor.
void ResetIsMessageFlag(void) const
unique_ptr< CSharedHitId > m_DefaultHitId
const char * m_Function
Function name.
CNcbiOstream & operator<<(CNcbiOstream &os, const SDiagMessage &mess)
Insert message in output stream.
void LogFields(const TEntries &entries) const
Log (as an extra) all names/values matching fields in NCBI_LOG_FIELDS.
void SetDiagHandler(CDiagHandler *handler, bool can_delete=true)
Set the diagnostic handler using the specified diagnostic handler class.
ErrCode(int code, int subcode=0)
Constructor.
string GetGlobalRequestId(void) const
Deprecated version of HID generator.
const string & GetFunction(void) const
SDiagMessage::TExtraArgs TExtraArgs
const char * m_ErrText
Sometimes 'error' has no numeric code, but can be represented as text.
atomic< bool > m_TraceLogSuspended
void SetDiagTrace(EDiagTrace how, EDiagTrace dflt=eDT_Default)
Set the diagnostic trace settings.
const char * GetClass(void) const
Get class name of the current message.
CDiagHandler * m_Handler
Class handler.
EDiagSev
Severity level for the posted diagnostics.
const char * g_DiagUnknownFunction(void)
EEventType m_Event
If the severity is eDPF_AppLog, m_Event contains event type.
TDiagPostFlags SetDiagPostAllFlags(TDiagPostFlags flags)
Set global post flags to "flags".
bool x_NeedModule(void) const
void SetFunction(const string &func)
Uint8 GetDiagRequestId(void)
Get iteration number/request ID.
const char * GetFile(void) const
Get file used for the current message.
bool m_IgnoreToDie
Ignore to die on die sev.
MDiagFunction(const char *function)
Uint8 GetFastCGIIteration(void)
SDiagMessage::TExtraArg TExtraArg
CNcbiOstream * GetDiagStream(void)
Get current diagnostic stream (if it was set by SetDiagStream) or NULL.
unique_ptr< TMessages > m_Messages
static NCBI_XNCBI_EXPORT void DiagFatal(const CDiagCompileInfo &info, const char *message)
Display fatal error message.
bool IsSetDiagErrCodeInfo()
Indicates whether an error-code processing handler has been set.
CDiagErrCodeInfo * m_ErrCodeInfo
Error code information.
unique_ptr< CRequestRateControl > m_AppLogRC
static const char * kProperty_HostIP
const char * m_CurrFunctName
static bool StrToSeverityLevel(const char *str_sev, EDiagSev &sev)
Get severity from string.
EPropertyMode
Property visibility flag.
EDiagSev GetPrintSeverity(void) const
Get current print severity.
static const char * kProperty_AppState
Per-thread properties.
int GetExitCode(void) const
Get exit code.
CDiagContext(const CDiagContext &)
Int8 TUID
Unique process ID.
void SetFile(const string &file)
void SetClass(const string &cls)
void SetDiagTraceFlag(EDiagPostFlag flag)
EDiagSev m_Level
Severity level.
CDiagContext & operator=(const CDiagContext &)
CDiagErrCodeInfo * GetDiagErrCodeInfo(bool take_ownership=false)
Get handler for processing error codes.
CStreamDiagHandler_Base TParent
friend const CNcbiDiag & operator<<(const CNcbiDiag &diag, const MDiagModule &module)
TDiagPostFlags ResetPostFlags(TDiagPostFlags flags) const
Clear specific post flags for the current message.
static bool IsApplogSeverityLocked(void)
When using applog, the diag post level is locked to Warning.
unique_ptr< CEncodedString > m_DefaultSessionId
string GetLogFile(EDiagFileType file_type)
Get log file name for the given log type.
static const char * kProperty_BytesWr
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
unique_ptr< CEncodedString > m_AppName
void SetAbortHandler(FAbortHandler func=0)
Set/unset abort handler.
void x_LogHitID(bool ignore_app_state=false) const
int m_SubCode
Minor error code number.
CDiagCompileInfo(void)
CDiagCompileInfo::
friend const CNcbiDiag & operator<<(const CNcbiDiag &diag, const MDiagClass &nclass)
void ResetIsNoteFlag(void) const
Reset IsNote flag.
EDiagFilter
Diag severity types to put the filter on.
EDiagSev GetSeverity(void) const
Get severity of the current message.
EAction GetAction(void) const
Get selected on-destroy action.
bool m_TypedExtra
Set to true if this is a typed extra message (the arguments include "NCBIEXTRATYPE=<extra-type>").
CNcbiDiag & operator=(const CNcbiDiag &)
Private assignment operator to prohibit assignment.
static const char * kProperty_ReqStatus
void g_Diag_Use_RWLock(bool enable=true)
Use RW-lock for synchronization rather than mutex.
const char * GetModule(void) const
bool m_CanDeleteHandler
Can handler be deleted?
const CNcbiDiag & Put(const NCBI_NS_NCBI::SetPostFlags *, const NCBI_NS_NCBI::SetPostFlags &flags) const
Helper method to set specific post flags.
const CNcbiDiag & SetModule(const char *module) const
Set module name.
unique_ptr< CRequestRateControl > m_ErrLogRC
SDiagMessageData * m_Data
virtual CNcbiOstream * GetStream(void)
bool IgnoreDiagDieLevel(bool ignore)
Ignore the die level settings.
@ eDPF_AtomicWrite
This flag is deprecated and ignored - all log writes are atomic.
@ eDPF_ErrCodeUseSeverity
Use severity from error code (default)
@ eDPF_Location
Include class and function if any.
@ eDPF_OmitSeparator
No '—' separator before message.
@ eDPF_MergeLines
Escape EOLs.
@ eDPF_ErrCodeMsgInFront
Put ErrCode text in front of the message.
@ eDPF_ErrCodeExplanation
Error explanation (default)
@ eDPF_IsNote
Print "Note[X]" severity name.
@ eDPF_DateTime
Include date and time.
@ eDPF_ErrorID
Error code and subcode (default)
@ eDPF_Log
Print the posted message only; without severity, location, prefix, etc.
@ eDPF_Severity
Severity (default)
@ eDPF_OmitInfoSev
No sev. indication if eDiag_Info.
@ eDPF_Default
Use global default flags (merge with).
@ eDPF_IsConsole
Send the message to 'console' regardless of it's severity.
@ eDPF_PreMergeLines
Obsolete. Use eDPF_MergeLines.
@ eDPF_Trace
Default flags to use when tracing.
@ eDPF_File
File name (not full path)
@ eDPF_UseExactUserFlags
Use flags provided by user as-is, do not allow CNcbiDiag to replace "important" flags by the globally...
@ eDPF_ImportantFlagsMask
Important bits which should be taken from the globally set flags even if a user attempts to override ...
@ eDPF_ErrCodeMessage
Error code message (default)
@ eDPF_Exception
Default flags to use for exception formatting.
@ eDPF_LongFilename
Full file path.
@ eDPF_AppLog
Post message to application log.
@ eDPF_Prefix
Prefix (default)
@ eDPF_All
All flags (except for the "unusual" ones!)
@ eDiagSC_Enable
Enable change severity level.
@ eDiagSC_Disable
Disable change severity level.
@ eDiagSC_Unknown
Status of changing severity is unknown (first call)
@ eDCM_Discard
Discard the collected messages without flushing.
@ eDCM_Init
Start collecting messages (with limit), do nothing if already initialized.
@ eDCM_NoChange
Continue collecting messages if already started.
@ eDCM_InitNoLimit
Start collecting messages without limit (must stop collecting later using eDCM_Flush or eDCM_Discard)...
@ eDCM_Flush
Flush the collected messages and stop collecting.
@ eDS_Default
Try standard log file (app.name + ".log") in /log/, use stderr on failure.
@ eDS_ToMemory
Keep in a temp.memory buffer, see FlushMessages()
@ eDS_User
Leave as was previously set (or not set) by user.
@ eDS_Disable
Don't write it anywhere.
@ eDS_AppSpecific
Call the application's SetupDiag_AppSpecific()
@ eDS_ToStdlog
Try standard log file (app.name + ".log") in /log/ and current directory, use stderr if both fail.
@ eDS_ToStdout
To standard output stream.
@ eDS_ToStderr
To standard error stream.
@ eDS_ToSyslog
To system log daemon.
@ ePostNumber_NoIncrement
Get post number without incrementing it.
@ ePostNumber_Increment
Increment and return the new post number.
@ eEvent_RequestStop
Finish processing request.
@ eEvent_RequestStart
Start processing request.
@ eEvent_Start
Application start.
@ eEvent_Extra
Other application events.
@ eEvent_Stop
Application exit.
@ eDT_Enable
Enable messages of severity "eDiag_Trace".
@ eDT_Disable
Ignore messages of severity "eDiag_Trace".
@ eDT_Default
Restores the default tracing context.
@ ePrint
Print all collected messages as is.
@ eDiscard
Discard collected messages, default.
@ eLogRate_App
Application log.
@ eDiagFile_Trace
Trace log file.
@ eDiagFile_Perf
Perf log file.
@ eDiagFile_Err
Error log file.
@ eDiagFile_All
All log files.
@ eDiagFile_Log
Access log file.
@ eDiagAppState_RequestEnd
RE.
@ eDiagAppState_AppEnd
AE.
@ eDiagAppState_AppBegin
AB.
@ eDiagAppState_RequestBegin
RB.
@ eDiagAppState_NotSet
Reserved value, never used in messages.
@ eDiagAppState_Request
R.
@ eDiag_Trace
Trace message.
@ eDiag_Info
Informational message.
@ eDiag_Error
Error message.
@ eDiag_Warning
Warning message.
@ eDiag_Fatal
Fatal error – guarantees exit(or abort)
@ eDiagSevMin
Verbosity level for min. severity.
@ eDiag_Critical
Critical error message.
@ eDiagSevMax
Verbosity level for max. severity.
@ eProp_Default
Auto-mode for known properties, local for others.
@ eProp_Global
The property is global for the application.
@ eDiagFilter_All
for all non-FATAL
@ eDiagFilter_Post
for all non-TRACE, non-FATAL
@ eDiagFilter_Trace
for TRACEs only
void Read(CObjectIStream &in, TObjectPtr object, const CTypeRef &type)
void Write(CObjectOStream &out, TConstObjectPtr object, const CTypeRef &type)
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::ostream CNcbiOstream
Portable alias for ostream.
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
IO_PREFIX::ios CNcbiIos
Portable alias for ios.
#define NCBI_XNCBI_EXPORT
Uint4 GetHost(TEndpointKey key)
const GenericPointer< typename T::ValueType > T2 value
const CharType(& source)[N]
static void s_EscapeNewlines(const void *src_buf, size_t src_size, size_t *src_read, void *dst_buf, size_t dst_size, size_t *dst_written)
Escape newlines in the string.
CDiagContext_Extra g_PostPerf(int status, double timespan, SDiagMessage::TExtraArgs &args)
std::istream & in(std::istream &in_, double &x_)
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
SDiagErrCodeDescription –.
Template structure used to point out wrong error subcode in ERR_POST_X, STD_CATCH_X and alike macros.
Template structure used to point out incorrect usage of NCBI_DEFINE_ERR_SUBCODE_X macro i....
static wxAcceleratorEntry entries[3]