NCBI C++ ToolKit
Classes | Macros | Typedefs | Enumerations | Functions
ncbidiag.hpp File Reference

Defines NCBI C++ diagnostic APIs, classes, and macros. More...

#include <corelib/ncbi_stack.hpp>
#include <deque>
#include <vector>
#include <map>
#include <atomic>
#include <stdexcept>
#include <corelib/ncbidiag.inl>
+ Include dependency graph for ncbidiag.hpp:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

class  CDiagCompileInfo
 Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function. More...
 
struct  WRONG_ERROR_SUBCODE_IN_POST_MACRO< errorCode, errorSubcode, maxErrorSubcode, false >
 Specialization of template: when error subcode is valid existence of this specialization will be valuable for not issuing compiler error. More...
 
struct  WRONG_USAGE_OF_DEFINE_ERR_SUBCODE_MACRO< errorCode, false >
 Specialization of template: when usage of NCBI_DEFINE_ERR_SUBCODE_X is correct existence of this specialization will be valuable for not issuing compiler error. More...
 
class  ErrCode
 ErrCode –. More...
 
class  Severity
 Severity –. More...
 
class  SetPostFlags
 SetPostFlags –. More...
 
class  MDiagModule
 MDiagModule –. More...
 
class  MDiagClass
 MDiagClass –. More...
 
class  MDiagFunction
 MDiagFunction –. More...
 
class  CNcbiDiag
 CNcbiDiag –. More...
 
class  CDiagCollectGuard
 Guard for collecting diag messages (affects the current thread only). More...
 
class  CDiagAutoPrefix
 CDiagAutoPrefix –. More...
 
class  INextDiagMessage
 Callback interface for stream parser. More...
 
struct  SDiagMessage
 SDiagMessage –. More...
 
class  CDiagContext_Extra
 Temporary object for holding extra message arguments. More...
 
class  CDiagContext
 
class  CNcbiLogFields
 CNcbiLogFields –. More...
 
class  CDiagHandler
 
class  CStreamDiagHandler_Base
 CStreamDiagHandler_Base –. More...
 
class  CStreamDiagHandler
 CStreamDiagHandler –. More...
 
class  CFileHandleDiagHandler
 CFileHandleDiagHandler –. More...
 
class  CFileDiagHandler
 CFileDiagHandler –. More...
 
class  CAsyncDiagHandler
 
class  CDiagFactory
 CDiagFactory –. More...
 
class  CDiagRestorer
 CDiagRestorer –. More...
 
struct  SDiagErrCodeDescription
 SDiagErrCodeDescription –. More...
 
class  CDiagErrCodeInfo
 CDiagErrCodeInfo –. More...
 

Macros

#define NCBI_CURRENT_FUNCTION   NCBI_NS_NCBI::g_DiagUnknownFunction()
 Get current function name. More...
 
#define NCBI_MAKE_MODULE(module)   NCBI_AS_STRING(module)
 Set default module name based on NCBI_MODULE macro. More...
 
#define DIAG_COMPILE_INFO
 Make compile time diagnostic information object to use in CNcbiDiag and CException. More...
 
#define ERR_POST(message)
 Error posting with file, line number information but without error codes. More...
 
#define SEVERITY_POST(severity, message)
 Wrappers for ERR_POST family of macros checking if the desired severity is enabled. More...
 
#define WARNING_POST(message)   SEVERITY_POST(Warning, message)
 
#define INFO_POST(message)   SEVERITY_POST(Info, message)
 
#define TRACE_POST(message)   SEVERITY_POST(Trace, message)
 
#define SEVERITY_POST_X(severity, subcode, message)
 
#define WARNING_POST_X(subcode, message)   SEVERITY_POST_X(Warning, subcode, message)
 
#define INFO_POST_X(subcode, message)   SEVERITY_POST_X(Info, subcode, message)
 
#define TRACE_POST_X(subcode, message)   SEVERITY_POST_X(Trace, subcode, message)
 
#define SEVERITY_POST_EX(severity, errcode, subcode, message)
 
#define WARNING_POST_EX(errcode, subcode, message)   SEVERITY_POST_EX(Warning, errcode, subcode, message)
 
#define INFO_POST_EX(errcode, message)   SEVERITY_POST_EX(Info, errcode, subcode, message)
 
#define TRACE_POST_EX(errcode, message)   SEVERITY_POST_EX(Trace, errcode, subcode, message)
 
#define LOG_POST(message)
 This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro LOG_POST_X to make possible more flexible error statistics and logging. More...
 
#define ERR_FATAL(message)
 Posting fatal error and abort. More...
 
#define ERR_POST_EX(err_code, err_subcode, message)
 Error posting with error codes. More...
 
#define LOG_POST_EX(err_code, err_subcode, message)
 
#define ERR_FATAL_EX(err_code, err_subcode, message)
 
#define NCBI_DEFINE_ERRCODE_X(name, err_code, max_err_subcode)
 Define global error code name with given value (err_code) and given maximum value of error subcode within this code. More...
 
#define NCBI_DEFINE_ERR_SUBCODE_X(max_err_subcode)    NCBI_DEFINE_ERR_SUBCODE_XX(NCBI_USE_ERRCODE_X, max_err_subcode)
 Define maximum value of subcode for the error code currently in use. More...
 
#define NCBI_DEFINE_ERR_SUBCODE_XX(name, max_err_subcode)
 Define maximum value of subcode for particular error code name. More...
 
#define NCBI_ERRCODE_X_NAME(name)    NCBI_NS_NCBI::err_code_x::NCBI_NAME2(eErrCodeX_, name)
 Returns value of error code by its name defined by NCBI_DEFINE_ERRCODE_X. More...
 
#define NCBI_ERRCODE_X   NCBI_ERRCODE_X_NAME(NCBI_USE_ERRCODE_X)
 Returns currently set default error code. More...
 
#define NCBI_MAX_ERR_SUBCODE_X_NAME(name)    NCBI_NS_NCBI::err_code_x::NCBI_NAME2(SErrCodeX_Max_, name)<true>::value
 Returns maximum value of error subcode within error code with given name. More...
 
#define NCBI_MAX_ERR_SUBCODE_X    NCBI_MAX_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X)
 Returns maximum value of error subcode within current default error code. More...
 
#define NCBI_CHECK_ERRCODE_USAGE(name)
 Check that NCBI_DEFINE_ERR_SUBCODE_X is used for correctly defined error code. More...
 
#define NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode)
 Issue compile-time error if error subcode given is not valid for given error code name. More...
 
#define NCBI_CHECK_ERR_SUBCODE_X(subcode)    NCBI_CHECK_ERR_SUBCODE_X_NAME(NCBI_USE_ERRCODE_X, subcode)
 Issue compile-time error if error subcode given is not valid for current error code. More...
 
#define NCBI_ERR_SUBCODE_X_NAME(name, subcode)    (NCBI_CHECK_ERR_SUBCODE_X_NAME(name, subcode), subcode)
 Pass subcode as argument with check of its validity for given error code. More...
 
#define NCBI_ERR_SUBCODE_X(subcode)    (NCBI_CHECK_ERR_SUBCODE_X(subcode), subcode)
 Pass subcode as argument with check of its validity for current error code. More...
 
#define ERR_POST_X(err_subcode, message)    ERR_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
 Error posting with default error code and given error subcode. More...
 
#define LOG_POST_X(err_subcode, message)    LOG_POST_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
 
#define ERR_FATAL_X(err_subcode, message)    ERR_FATAL_XX(NCBI_USE_ERRCODE_X, err_subcode, message)
 
#define ERR_POST_XX(error_name, err_subcode, message)
 Error posting with error code having given name and with given error subcode. More...
 
#define LOG_POST_XX(error_name, err_subcode, message)
 
#define ERR_FATAL_XX(error_name, err_subcode, message)
 
#define NCBI_REPEAT_POST_N_TIMES(post_macro, count, params)
 Common code for making log or error posting only given number of times during program execution. More...
 
#define ERR_POST_N_TIMES(count, message)    NCBI_REPEAT_POST_N_TIMES( ERR_POST, count, (message) )
 Error posting only given number of times during program execution. More...
 
#define LOG_POST_N_TIMES(count, message)    NCBI_REPEAT_POST_N_TIMES( LOG_POST, count, (message) )
 
#define ERR_POST_ONCE(message)   ERR_POST_N_TIMES(1, message)
 Error posting only once during program execution. More...
 
#define LOG_POST_ONCE(message)   LOG_POST_N_TIMES(1, message)
 
#define ERR_POST_X_N_TIMES(count, err_subcode, message)    NCBI_REPEAT_POST_N_TIMES( ERR_POST_X, count, (err_subcode, message) )
 Error posting only given number of times during program execution with default error code and given error subcode. More...
 
#define LOG_POST_X_N_TIMES(count, err_subcode, message)    NCBI_REPEAT_POST_N_TIMES( LOG_POST_X, count, (err_subcode, message) )
 
#define ERR_POST_X_ONCE(err_subcode, message)    ERR_POST_X_N_TIMES(1, err_subcode, message)
 Error posting only once during program execution with default error code and given error subcode. More...
 
#define LOG_POST_X_ONCE(err_subcode, message)    LOG_POST_X_N_TIMES(1, err_subcode, message)
 
#define ERR_POST_XX_N_TIMES(count, error_name, err_subcode, message)
 Error posting only given number of times during program execution with given error code name and given error subcode. More...
 
#define LOG_POST_XX_N_TIMES(count, error_name, err_subcode, message)
 
#define ERR_POST_XX_ONCE(error_name, err_subcode, message)    ERR_POST_XX_N_TIMES(1, error_name, err_subcode, message)
 Error posting only once during program execution with given error code name and given error subcode. More...
 
#define LOG_POST_XX_ONCE(error_name, err_subcode, message)    LOG_POST_XX_N_TIMES(1, error_name, err_subcode, message)
 
#define DIAG_POST_LEVEL   "DIAG_POST_LEVEL"
 Diagnostic post severity level. More...
 
#define DIAG_TRACE   "DIAG_TRACE"
 Diagnostic trace setting. More...
 
#define DIAG_MESSAGE_FILE   "MessageFile"
 Diagnostic message file. More...
 

Typedefs

typedef int TDiagPostFlags
 Binary OR of "EDiagPostFlag". More...
 
typedef void(* FAbortHandler) (void)
 Abort handler function type. More...
 
typedef void(* FDiagHandler) (const SDiagMessage &mess)
 Diagnostic handler function type. More...
 
typedef void(* FDiagCleanup) (void *data)
 Diagnostic cleanup function type. More...
 

Enumerations

enum  EDiagSev {
  eDiag_Info = 0 , eDiag_Warning , eDiag_Error , eDiag_Critical ,
  eDiag_Fatal , eDiag_Trace , eDiagSevMin = eDiag_Info , eDiagSevMax = eDiag_Trace
}
 Severity level for the posted diagnostics. More...
 
enum  EDiagSevChange { eDiagSC_Unknown , eDiagSC_Disable , eDiagSC_Enable }
 Severity level change state. More...
 
enum  EDiagPostFlag {
  eDPF_File = 1 << 0 , eDPF_LongFilename = 1 << 1 , eDPF_Line = 1 << 2 , eDPF_Prefix = 1 << 3 ,
  eDPF_Severity = 1 << 4 , eDPF_ErrorID = 1 << 5 , eDPF_DateTime = 1 << 7 , eDPF_ErrCodeMessage = 1 << 8 ,
  eDPF_ErrCodeExplanation = 1 << 9 , eDPF_ErrCodeUseSeverity = 1 << 10 , eDPF_Location = 1 << 11 , eDPF_TID = 1 << 13 ,
  eDPF_PID = 0 , eDPF_SerialNo = 0 , eDPF_SerialNo_Thread = 0 , eDPF_RequestId = 0 ,
  eDPF_Iteration = eDPF_RequestId , eDPF_UID = 0 , eDPF_ErrCode = eDPF_ErrorID , eDPF_ErrSubCode = eDPF_ErrorID ,
  eDPF_All = 0x7FFFF , eDPF_Trace , eDPF_Exception = eDPF_Trace | eDPF_ErrorID , eDPF_Log = 0 ,
  eDPF_ErrCodeMsgInFront = 1 << 19 , eDPF_MergeLines = 1 << 21 , eDPF_PreMergeLines = eDPF_MergeLines , eDPF_OmitInfoSev = 1 << 22 ,
  eDPF_OmitSeparator = 1 << 23 , eDPF_AppLog = 1 << 24 , eDPF_IsNote = 1 << 25 , eDPF_IsMessage = eDPF_IsNote ,
  eDPF_AtomicWrite = 1 << 26 , eDPF_IsConsole = 1 << 27 , eDPF_Default = 1 << 28 , eDPF_ImportantFlagsMask ,
  eDPF_UseExactUserFlags = 1 << 29
}
 Which parts of the diagnostic context should be posted. More...
 
enum  EDiagAppState {
  eDiagAppState_NotSet , eDiagAppState_AppBegin , eDiagAppState_AppRun , eDiagAppState_AppEnd ,
  eDiagAppState_RequestBegin , eDiagAppState_Request , eDiagAppState_RequestEnd
}
 Application execution states shown in the std prefix. More...
 
enum  EDiagTrace { eDT_Default = 0 , eDT_Disable , eDT_Enable }
 Which setting disables/enables posting of "eDiag_Trace" messages. More...
 
enum  EAppDiagStream {
  eDS_ToStdout , eDS_ToStderr , eDS_ToStdlog , eDS_ToMemory ,
  eDS_Disable , eDS_User , eDS_AppSpecific , eDS_Default ,
  eDS_ToSyslog
}
 Where to write the application's diagnostics to. More...
 
enum  EDiagCollectMessages {
  eDCM_Init , eDCM_InitNoLimit , eDCM_NoChange , eDCM_Flush ,
  eDCM_Discard
}
 Flags to control collecting messages and flushing them to the new destination when switching diag handlers. More...
 
enum  EPostNumberIncrement { ePostNumber_NoIncrement , ePostNumber_Increment }
 Post number increment flag for GetProcessPostNumber() and GetThreadPostNumber(). More...
 
enum  EDiagFileType {
  eDiagFile_Err , eDiagFile_Log , eDiagFile_Trace , eDiagFile_Perf ,
  eDiagFile_All
}
 CDiagHandler –. More...
 
enum  EDiagFilter { eDiagFilter_Trace , eDiagFilter_Post , eDiagFilter_All }
 Diag severity types to put the filter on. More...
 

Functions

const char * g_DiagUnknownFunction (void)
 
void CheckErrSubcodeX (int)
 Additional dummy function for use in NCBI_CHECK_ERR_SUBCODE_X macro. More...
 
bool IsSetDiagPostFlag (EDiagPostFlag flag, TDiagPostFlags flags=eDPF_Default)
 Check if a specified flag is set. More...
 
TDiagPostFlags SetDiagPostAllFlags (TDiagPostFlags flags)
 Set global post flags to "flags". More...
 
void SetDiagPostFlag (EDiagPostFlag flag)
 Set the specified flag (globally). More...
 
void UnsetDiagPostFlag (EDiagPostFlag flag)
 Unset the specified flag (globally). More...
 
TDiagPostFlags SetDiagTraceAllFlags (TDiagPostFlags flags)
 Versions of the above for extra trace flags. More...
 
void SetDiagTraceFlag (EDiagPostFlag flag)
 
void UnsetDiagTraceFlag (EDiagPostFlag flag)
 
void SetDiagPostPrefix (const char *prefix)
 Specify a string to prefix all subsequent error postings with. More...
 
void PushDiagPostPrefix (const char *prefix)
 Push a string to the list of message prefixes. More...
 
void PopDiagPostPrefix (void)
 Pop a string from the list of message prefixes. More...
 
Uint8 GetDiagRequestId (void)
 Get iteration number/request ID. More...
 
void SetDiagRequestId (Uint8 id)
 Set iteration number/request ID. More...
 
Uint8 GetFastCGIIteration (void)
 
void SetFastCGIIteration (Uint8 id)
 
EDiagSev SetDiagPostLevel (EDiagSev post_sev=eDiag_Error)
 Set the threshold severity for posting the messages. More...
 
EDiagSev GetDiagPostLevel (void)
 Get current threshold severity for posting the messages. More...
 
int CompareDiagPostLevel (EDiagSev sev1, EDiagSev sev2)
 Compare two severities. More...
 
bool IsVisibleDiagPostLevel (EDiagSev sev)
 Check if the specified severity is higher or equal to the currently selected post level and will be printed by ERR_POST. More...
 
bool DisableDiagPostLevelChange (bool disable_change=true)
 Disable change the diagnostic post level. More...
 
void SetDiagFixedPostLevel (EDiagSev post_sev)
 Sets and locks the level, combining the previous two calls. More...
 
EDiagSev SetDiagDieLevel (EDiagSev die_sev=eDiag_Fatal)
 Set the "die" (abort) level for the program. More...
 
EDiagSev GetDiagDieLevel (void)
 Get the "die" (abort) level for the program. More...
 
bool IgnoreDiagDieLevel (bool ignore)
 Ignore the die level settings. More...
 
void SetAbortHandler (FAbortHandler func=0)
 Set/unset abort handler. More...
 
NCBI_XNCBI_EXPORT void Abort (void)
 Smart abort function. More...
 
void SetDiagTrace (EDiagTrace how, EDiagTrace dflt=eDT_Default)
 Set the diagnostic trace settings. More...
 
bool GetDiagTrace (void)
 Check if traces are enabled. More...
 
CNcbiOstreamoperator<< (CNcbiOstream &os, const SDiagMessage &mess)
 Insert message in output stream. More...
 
CDiagContextGetDiagContext (void)
 Get diag context instance. More...
 
void SetDiagHandler (CDiagHandler *handler, bool can_delete=true)
 Set the diagnostic handler using the specified diagnostic handler class. More...
 
CDiagHandlerGetDiagHandler (bool take_ownership=false, bool *current_ownership=0)
 Get the currently set diagnostic handler class. More...
 
void SetDiagHandler (FDiagHandler func, void *data, FDiagCleanup cleanup)
 Set the diagnostic handler using the specified diagnostic handler and cleanup functions. More...
 
bool IsSetDiagHandler (void)
 Check if diagnostic handler is set. More...
 
void DiagHandler_Reopen (void)
 Ask diagnostic handler to reopen log files if necessary. More...
 
void SetDiagFilter (EDiagFilter what, const char *filter_str)
 Set diagnostic filter. More...
 
string GetDiagFilter (EDiagFilter what)
 Get current diagnostic filter. More...
 
void AppendDiagFilter (EDiagFilter what, const char *filter_str)
 Append diagnostic filter. More...
 
void SetDoubleDiagHandler (void)
 Output diagnostics using both old and new style handlers. More...
 
void SetDiagStream (CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
 Set diagnostic stream. More...
 
bool IsDiagStream (const CNcbiOstream *os)
 
CNcbiOstreamGetDiagStream (void)
 Get current diagnostic stream (if it was set by SetDiagStream) or NULL. More...
 
void SetSplitLogFile (bool value=true)
 Split log files flag. More...
 
bool GetSplitLogFile (void)
 Get split log files flag. More...
 
bool SetLogFile (const string &file_name, EDiagFileType file_type=eDiagFile_All, bool quick_flush=true)
 Set log files. More...
 
string GetLogFile (EDiagFileType file_type)
 Get log file name for the given log type. More...
 
string GetLogFile (void)
 Get log file name or diag handler name. More...
 
void g_Diag_Use_RWLock (bool enable=true)
 Use RW-lock for synchronization rather than mutex. More...
 
void SetDiagErrCodeInfo (CDiagErrCodeInfo *info, bool can_delete=true)
 Set handler for processing error codes. More...
 
bool IsSetDiagErrCodeInfo ()
 Indicates whether an error-code processing handler has been set. More...
 
CDiagErrCodeInfoGetDiagErrCodeInfo (bool take_ownership=false)
 Get handler for processing error codes. More...
 

Detailed Description

Defines NCBI C++ diagnostic APIs, classes, and macros.

More elaborate documentation could be found in: http://ncbi.github.io/cxx-toolkit/pages/ch_log.html

Definition in file ncbidiag.hpp.

Modified on Mon Apr 22 04:05:04 2024 by modify_doxy.py rev. 669887