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::g_DiagUnknownFunction()
149 #define NCBI_MAKE_MODULE(module) NCBI_AS_STRING(module)
170 #define DIAG_COMPILE_INFO \
171 ncbi::CDiagCompileInfo(__FILE__, \
173 NCBI_CURRENT_FUNCTION, \
174 NCBI_MAKE_MODULE(NCBI_MODULE))
185 #define ERR_POST(message) \
186 ( ncbi::CNcbiDiag(DIAG_COMPILE_INFO).GetRef() \
195 #define SEVERITY_POST(severity, message) \
196 do if (ncbi::IsVisibleDiagPostLevel(ncbi::eDiag_##severity)) \
197 ERR_POST(severity << message); \
199 #define WARNING_POST(message) SEVERITY_POST(Warning, message)
200 #define INFO_POST(message) SEVERITY_POST(Info, message)
201 #define TRACE_POST(message) SEVERITY_POST(Trace, message)
202 #define SEVERITY_POST_X(severity, subcode, message) \
203 do if (ncbi::IsVisibleDiagPostLevel(ncbi::eDiag_##severity)) \
204 ERR_POST_X(subcode, severity << message); \
206 #define WARNING_POST_X(subcode, message) SEVERITY_POST_X(Warning, subcode, message)
207 #define INFO_POST_X(subcode, message) SEVERITY_POST_X(Info, subcode, message)
208 #define TRACE_POST_X(subcode, message) SEVERITY_POST_X(Trace, subcode, message)
209 #define SEVERITY_POST_EX(severity, errcode, subcode, message) \
210 do if (ncbi::IsVisibleDiagPostLevel(ncbi::eDiag_##severity)) \
211 ERR_POST_EX(errcode, subcode, severity << message); \
213 #define WARNING_POST_EX(errcode, subcode, message) SEVERITY_POST_EX(Warning, errcode, subcode, message)
214 #define INFO_POST_EX(errcode, message) SEVERITY_POST_EX(Info, errcode, subcode, message)
215 #define TRACE_POST_EX(errcode, message) SEVERITY_POST_EX(Trace, errcode, subcode, message)
225 #define LOG_POST(message) \
226 ( ncbi::CNcbiDiag(DIAG_COMPILE_INFO, \
228 ncbi::eDPF_Log | ncbi::eDPF_IsNote).GetRef() \
239 #define ERR_FATAL(message) \
240 ncbi::EndmFatal(ncbi::CNcbiDiag(DIAG_COMPILE_INFO, \
241 ncbi::eDiag_Fatal).GetRef() << message )
251 #define ERR_POST_EX(err_code, err_subcode, message) \
252 ( ncbi::CNcbiDiag(DIAG_COMPILE_INFO).GetRef() \
253 << ncbi::ErrCode( (err_code), (err_subcode) ) \
257 #define LOG_POST_EX(err_code, err_subcode, message) \
258 ( ncbi::CNcbiDiag(DIAG_COMPILE_INFO, \
260 ncbi::eDPF_Log | ncbi::eDPF_IsNote).GetRef() \
261 << ncbi::ErrCode( (err_code), (err_subcode) ) \
265 #define ERR_FATAL_EX(err_code, err_subcode, message) \
266 ncbi::EndmFatal(ncbi::CNcbiDiag(DIAG_COMPILE_INFO, \
267 ncbi::eDiag_Fatal).GetRef() << \
268 ncbi::ErrCode( (err_code), (err_subcode) ) << message )
296 #define NCBI_DEFINE_ERRCODE_X(name, err_code, max_err_subcode) \
297 namespace err_code_x { \
299 eErrCodeX_##name = err_code, \
300 eErrCodeX_Max_##name = max_err_subcode \
302 template <bool dummy> \
303 struct SErrCodeX_Max_##name { \
305 value = max_err_subcode, \
306 dumm_dumm = int(dummy) \
331 #define NCBI_DEFINE_ERR_SUBCODE_X(max_err_subcode) \
332 NCBI_DEFINE_ERR_SUBCODE_XX(NCBI_USE_ERRCODE_X, max_err_subcode)
352 #define NCBI_DEFINE_ERR_SUBCODE_XX(name, max_err_subcode) \
353 NCBI_CHECK_ERRCODE_USAGE(name) \
354 namespace err_code_x { \
356 struct NCBI_NAME2(SErrCodeX_Max_, name)<true> { \
358 value = max_err_subcode \
367 #define NCBI_ERRCODE_X_NAME(name) \
368 ncbi::err_code_x::NCBI_NAME2(eErrCodeX_, name)
374 #define NCBI_ERRCODE_X NCBI_ERRCODE_X_NAME(NCBI_USE_ERRCODE_X)
379 #define NCBI_MAX_ERR_SUBCODE_X_NAME(name) \
380 ncbi::err_code_x::NCBI_NAME2(SErrCodeX_Max_, name)<true>::value
385 #define NCBI_MAX_ERR_SUBCODE_X \
386 NCBI_MAX_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X)
400 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode,
bool isWrong>
405 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode>
407 <errorCode, errorSubcode, maxErrorSubcode,
false> {
417 template <
int errorCode,
bool isWrong>
423 template <
int errorCode>
430 #define NCBI_CHECK_ERRCODE_USAGE(name) \
431 inline void NCBI_NAME2(s_ErrCodeCheck_, name) ( \
432 ncbi::WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO < \
433 NCBI_ERRCODE_X_NAME(name), \
434 ncbi::err_code_x::eErrCodeX_Max_##name != 0> \
450 #define NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode) \
451 ncbi::CheckErrSubcodeX( \
452 (int)sizeof(ncbi::WRONG_ERROR_SUBCODE_IN_POST_MACRO< \
453 NCBI_ERRCODE_X_NAME(name), subcode, \
454 NCBI_MAX_ERR_SUBCODE_X_NAME(name), \
455 ((unsigned int)subcode > \
456 (unsigned int)NCBI_MAX_ERR_SUBCODE_X_NAME(name)) \
462 #define NCBI_CHECK_ERR_SUBCODE_X(subcode) \
463 NCBI_CHECK_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X, subcode)
466 #define NCBI_ERR_SUBCODE_X_NAME(name, subcode) \
467 (NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode), subcode)
470 #define NCBI_ERR_SUBCODE_X(subcode) \
471 (NCBI_CHECK_ERR_SUBCODE_X(subcode), subcode)
473 #if defined(NCBI_COMPILER_ICC)
478 struct WRONG_ERROR_SUBCODE_IN_POST_MACRO_2;
486 template <
int errorCode,
int errorSubcode,
int maxErrorSubcode>
488 <errorCode, errorSubcode, maxErrorSubcode,
true> {
489 typedef char t[
sizeof(WRONG_ERROR_SUBCODE_IN_POST_MACRO_2<errorCode>)];
495 struct WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO_2;
503 template <
int errorCode>
505 typedef char t[
sizeof(
506 WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO_2<errorCode>)];
548 #define ERR_POST_X(err_subcode, message) \
549 ERR_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
551 #define LOG_POST_X(err_subcode, message) \
552 LOG_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
554 #define ERR_FATAL_X(err_subcode, message) \
555 ERR_FATAL_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
562 #define ERR_POST_XX(error_name, err_subcode, message) \
563 ERR_POST_EX(NCBI_ERRCODE_X_NAME(error_name), \
564 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
567 #define LOG_POST_XX(error_name, err_subcode, message) \
568 LOG_POST_EX(NCBI_ERRCODE_X_NAME(error_name), \
569 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
572 #define ERR_FATAL_XX(error_name, err_subcode, message) \
573 ERR_FATAL_EX(NCBI_ERRCODE_X_NAME(error_name), \
574 NCBI_ERR_SUBCODE_X_NAME(error_name, err_subcode), \
580 #define NCBI_REPEAT_POST_N_TIMES(post_macro, count, params) \
582 static atomic<int> sx_to_show(count); \
583 int to_show = sx_to_show; \
584 if ( to_show > 0 ) { \
585 sx_to_show = to_show - 1; \
592 #define ERR_POST_N_TIMES(count, message) \
593 NCBI_REPEAT_POST_N_TIMES( ERR_POST, count, (message) )
595 #define LOG_POST_N_TIMES(count, message) \
596 NCBI_REPEAT_POST_N_TIMES( LOG_POST, count, (message) )
600 #define ERR_POST_ONCE(message) ERR_POST_N_TIMES(1, message)
602 #define LOG_POST_ONCE(message) LOG_POST_N_TIMES(1, message)
609 #define ERR_POST_X_N_TIMES(count, err_subcode, message) \
610 NCBI_REPEAT_POST_N_TIMES( ERR_POST_X, count, (err_subcode, message) )
612 #define LOG_POST_X_N_TIMES(count, err_subcode, message) \
613 NCBI_REPEAT_POST_N_TIMES( LOG_POST_X, count, (err_subcode, message) )
619 #define ERR_POST_X_ONCE(err_subcode, message) \
620 ERR_POST_X_N_TIMES(1, err_subcode, message)
622 #define LOG_POST_X_ONCE(err_subcode, message) \
623 LOG_POST_X_N_TIMES(1, err_subcode, message)
629 #define ERR_POST_XX_N_TIMES(count, error_name, err_subcode, message) \
630 NCBI_REPEAT_POST_N_TIMES( ERR_POST_XX, count, \
631 (error_name, err_subcode, message) )
633 #define LOG_POST_XX_N_TIMES(count, error_name, err_subcode, message) \
634 NCBI_REPEAT_POST_N_TIMES( LOG_POST_XX, count, \
635 (error_name, err_subcode, message) )
641 #define ERR_POST_XX_ONCE(error_name, err_subcode, message) \
642 ERR_POST_XX_N_TIMES(1, error_name, err_subcode, message)
644 #define LOG_POST_XX_ONCE(error_name, err_subcode, message) \
645 LOG_POST_XX_N_TIMES(1, error_name, err_subcode, message)
719 #if defined(NCBI_THREADS)
947 template<
class X>
const CNcbiDiag&
Put(
const volatile void*,
const X& x)
const;
953 typedef IOS_BASE& (*FIosbaseManip)(IOS_BASE&);
972 template<
class X>
inline
977 template<
class X>
inline
1003 const ncbi::SetPostFlags&
flags)
const;
1011 return manip(*
this);
1015 return manip(*
this);
1163 const char* message);
1167 const char* message =
NULL);
1172 const char* expression,
1173 const char* message =
NULL);
1179 const char* expression,
1180 const char* message =
NULL);
1185 const char* expression,
1186 const char* message);
1329 EAction action = eDiscard);
1344 void SetPrintSeverity(
EDiagSev sev);
1350 void SetCollectSeverity(
EDiagSev sev);
1371 void Release(EAction action);
1374 void x_Init(
EDiagSev print_severity,
1445 #define DIAG_POST_LEVEL "DIAG_POST_LEVEL"
1535 extern void Abort(
void);
1538 #define DIAG_TRACE "DIAG_TRACE"
1607 const char*
file = 0,
size_t line = 0,
1609 int err_code = 0,
int err_subcode = 0,
1610 const char* err_text = 0,
1611 const char* module = 0,
1612 const char* nclass = 0,
1613 const char*
function = 0);
1630 bool ParseMessage(
const string& message);
1647 static string GetEventName(EEventType event);
1688 string FormatExtraMessage(
void)
const;
1691 TUID GetUID(
void)
const;
1693 CTime GetTime(
void)
const;
1715 const string&
GetHost(
void)
const;
1716 string GetClient(
void)
const;
1717 string GetSession(
void)
const;
1718 const string& GetAppName(
void)
const;
1723 string x_GetModule(
void)
const;
1726 static void s_UnescapeNewlines(
string&
buf);
1734 bool x_ParseExtraArgs(
const string&
str,
size_t pos);
1742 bool x_IsSetOldFormat(
void)
const;
1746 void x_InitData(
void)
const;
1748 void x_SaveContextData(
void)
const;
1761 return mess.
Write(os);
1821 template<
class TKey,
class TStorage>
class CStrictId;
1842 #if !NCBI_INT8_IS_LONG
1845 #elif SIZEOF_LONG_LONG
1854 template<
class TKey,
class TStorage>
1895 void x_Release(
void);
1896 bool x_CanPrint(
void);
1936 static TPID GetPID(
void);
1938 static bool UpdatePID(
void);
1939 static bool UpdatePID_AsyncSafe(
void);
1943 fOnFork_PrintStart = 1 << 0,
1944 fOnFork_ResetTimer = 1 << 1,
1945 fOnFork_AsyncSafe = 1 << 15
1976 TUID GetUID(
void)
const;
1979 string GetStringUID(
TUID uid = 0)
const;
1983 TUID UpdateUID(
TUID uid = 0)
const;
1986 void GetStringUID(
TUID uid,
char*
buf,
size_t buf_len)
const;
1989 void GetStringUID(
TUID uid,
char*
buf)
const;
1992 string GetNextHitID(
void)
const;
2008 void SetAutoWrite(
bool value);
2025 void SetProperty(
const string& name,
2026 const string&
value,
2027 EPropertyMode
mode = eProp_Default);
2034 string GetProperty(
const string& name,
2035 EPropertyMode
mode = eProp_Default)
const;
2041 void DeleteProperty(
const string& name,
2042 EPropertyMode
mode = eProp_Default);
2047 void PrintProperties(
void);
2080 void PrintStart(
const string& message);
2083 void PrintStop(
void);
2107 void PrintRequestStop(
void);
2128 static bool IsSetOldPostFormat(
void);
2130 static void SetOldPostFormat(
bool value);
2133 static bool IsUsingSystemThreadId(
void);
2135 static void UseSystemThreadId(
bool value =
true);
2138 const string& GetUsername(
void)
const;
2141 void SetUsername(
const string& username);
2145 const string&
GetHost(
void)
const;
2147 const string& GetEncodedHost(
void)
const;
2150 const string& GetHostname(
void)
const;
2152 const string& GetEncodedHostname(
void)
const;
2155 void SetHostname(
const string& hostname);
2160 void SetHostIP(
const string&
ip);
2163 const string& GetAppName(
void)
const;
2165 const string& GetEncodedAppName(
void)
const;
2167 void SetAppName(
const string& app_name);
2176 m_ExitCode = exit_code;
2177 m_ExitCodeSet =
true;
2188 string GetDefaultSessionID(
void)
const;
2191 void SetDefaultSessionID(
const string& session_id);
2194 string GetSessionID(
void)
const;
2196 string GetEncodedSessionID(
void)
const;
2201 static string GetDefaultClientIP(
void);
2205 static void SetDefaultClientIP(
const string& client_ip);
2212 string GetDefaultHitID(
void)
const;
2216 void SetDefaultHitID(
const string& hit_id);
2219 static const string& GetHostRole(
void);
2222 static const string& GetHostLocation(
void);
2232 void InitMessages(
size_t max_size = 100);
2239 void DiscardMessages(
void);
2244 static bool GetLogTruncate(
void);
2246 static void SetLogTruncate(
bool value);
2253 static bool IsUsingRootLog(
void);
2261 const char* cmd_logfile =
NULL);
2271 static TTID GetTID(
void);
2281 unsigned int GetLogRate_Limit(ELogRate_Type
type)
const;
2282 void SetLogRate_Limit(ELogRate_Type
type,
unsigned int limit);
2285 unsigned int GetLogRate_Period(ELogRate_Type
type)
const;
2286 void SetLogRate_Period(ELogRate_Type
type,
unsigned int period);
2289 static void x_FinalizeSetupDiag(
void);
2295 {
return sm_ApplogSeverityLocked; }
2297 { sm_ApplogSeverityLocked = lock; }
2299 static bool IsMainThreadDataInitialized(
void);
2302 static bool GetDisabledAppLog(
void);
2311 static EDisabledAppLogEvents GetDisabledAppLogEvents(
void);
2318 void x_CreateUID(
void)
const;
2319 void x_CreateUID_AsyncSafe(
void)
const;
2323 const string& message);
2325 static void x_StartRequest(
void);
2327 static void x_LogEnvironment(
void);
2333 void ResetLogRates(
void);
2339 void* cleanup_data);
2341 friend class CDiagBuffer;
2351 bool x_DiagAtApplicationLevel(
void)
const;
2352 bool x_IsSetDefaultHitID(
void)
const;
2353 CSharedHitId x_GetDefaultHitID(EDefaultHitIDFlags flag)
const;
2354 string x_GetNextHitID(
bool is_default)
const;
2356 void x_LogHitID_WithLock(
void)
const;
2417 template<
class TEntries>
2421 for (
typename TEntries::const_iterator it =
entries.begin(); it !=
entries.end(); ++it) {
2422 x_Match(it->first, it->second, extra);
2473 virtual void WriteMessage(
const char*
buf,
2478 virtual string GetLogName(
void);
2503 bool can_delete =
true);
2508 bool* current_ownership = 0);
2588 virtual string GetLogName(
void);
2592 void SetLogName(
const string& log_name);
2595 char m_LogName[2048];
2617 bool quick_flush =
true,
2618 const string& stream_name =
"");
2666 virtual void WriteMessage(
const char*
buf,
2678 virtual void Reopen(TReopenFlags
flags);
2681 virtual void SetLogName(
const string& log_name);
2725 virtual void WriteMessage(
const char*
buf,
2766 virtual void SetLogName(
const string& log_name);
2820 void InstallToDiag(
void);
2826 void RemoveFromDiag(
void);
2830 void SetCustomThreadSuffix(
const string& suffix);
2834 static void SetDiscardOnOverflow();
2838 virtual string GetLogName(
void);
2848 bool m_DiscardOnOverflow =
false;
2866 bool quick_flush =
true,
2868 void* cleanup_data = 0,
2869 const string& stream_name =
""
2900 bool quick_flush =
true);
2968 void*
operator new (size_t) {
throw runtime_error(
"forbidden"); }
2974 void*
operator new[] (size_t) {
throw runtime_error(
"forbidden"); }
2980 void operator delete (
void*) { }
2986 void operator delete[] (
void*) { }
3018 const string& explanation,
3023 : m_Message(message),
3024 m_Explanation(explanation),
3025 m_Severity(severity)
3082 bool GetDescription(
const ErrCode& err_code,
3110 #define DIAG_MESSAGE_FILE "MessageFile"
3120 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.
atomic< size_t > m_DroppedMessages
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.
EDisabledAppLogEvents
Flags for disabling groups of applog events with DIAG_DISABLE_APPLOG_MESSAGES.
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.
const CNcbiDiag & Put(const ncbi::SetPostFlags *, const ncbi::SetPostFlags &flags) const
Helper method to set specific post flags.
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.
atomic< size_t > m_DroppedRequests
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 eDPF_AppLog flag is set, 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
size_t GetDroppedMessagesCount(void) const
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 & SetModule(const char *module) const
Set module name.
size_t GetDroppedRequestsCount(void) const
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.
@ eDisable_All
Disable all applog events (default).
@ 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]