NCBI C++ ToolKit
|
Search Toolkit Book for CDiagContext
#include <corelib/ncbidiag.hpp>
Public Types | |
enum | FOnForkAction { fOnFork_PrintStart = 1 << 0 , fOnFork_ResetTimer = 1 << 1 , fOnFork_AsyncSafe = 1 << 15 } |
Actions to perform in UpdateOnFork(). More... | |
enum | EPropertyMode { eProp_Default , eProp_Global , eProp_Thread } |
Property visibility flag. More... | |
enum | ELogRate_Type { eLogRate_App , eLogRate_Err , eLogRate_Trace } |
Type of logging rate limit. More... | |
typedef Uint8 | TPID |
typedef int | TOnForkFlags |
typedef SDiagMessage::TUID | TUID |
typedef SDiagMessage::TCount | TCount |
typedef Uint8 | TTID |
Get thread ID used in messages. More... | |
Public Member Functions | |
CDiagContext (void) | |
~CDiagContext (void) | |
TUID | GetUID (void) const |
Return (create if not created yet) unique diagnostic ID. More... | |
string | GetStringUID (TUID uid=0) const |
Return string representation of UID. More... | |
TUID | UpdateUID (TUID uid=0) const |
Take the source UID and replace its timestamp part with the current time. More... | |
void | GetStringUID (TUID uid, char *buf, size_t buf_len) const |
Fill buffer with string representation of UID. More... | |
void | GetStringUID (TUID uid, char *buf) const |
string | GetNextHitID (void) const |
Create global unique request id. More... | |
string | GetGlobalRequestId (void) const |
Deprecated version of HID generator. More... | |
void | SetAutoWrite (bool value) |
Set AutoWrite flag. More... | |
void | SetProperty (const string &name, const string &value, EPropertyMode mode=eProp_Default) |
Set application context property by name. More... | |
string | GetProperty (const string &name, EPropertyMode mode=eProp_Default) const |
Get application context property by name, return empty string if the property is not set. More... | |
void | DeleteProperty (const string &name, EPropertyMode mode=eProp_Default) |
Delete a property by name. More... | |
void | PrintProperties (void) |
Forced dump of all set properties. More... | |
void | PrintStart (const string &message) |
Print start/stop etc. More... | |
void | PrintStop (void) |
Print exit message. More... | |
void | PrintExtra (const string &message) |
Print extra message in plain text format. More... | |
CDiagContext_Extra | Extra (void) const |
Create a temporary CDiagContext_Extra object. More... | |
void | PrintRequestStart (const string &message) |
Print request start message (for request-driven applications) More... | |
CDiagContext_Extra | PrintRequestStart (void) |
Create a temporary CDiagContext_Extra object. More... | |
void | PrintRequestStop (void) |
Print request stop message (for request-driven applications) More... | |
EDiagAppState | GetGlobalAppState (void) const |
Always returns global application state. More... | |
void | SetGlobalAppState (EDiagAppState state) |
Set global application state. More... | |
EDiagAppState | GetAppState (void) const |
Return application state for the current thread if it's set. More... | |
void | SetAppState (EDiagAppState state) |
Set application state. More... | |
void | SetAppState (EDiagAppState state, EPropertyMode mode) |
The 'mode' flag is deprecated. More... | |
const string & | GetUsername (void) const |
Get username. More... | |
void | SetUsername (const string &username) |
Set username. More... | |
const string & | GetHost (void) const |
Get host name. More... | |
const string & | GetEncodedHost (void) const |
URL-encoded version of GetHost() More... | |
const string & | GetHostname (void) const |
Get cached hostname - do not try to detect host name as GetHost() does. More... | |
const string & | GetEncodedHostname (void) const |
Get URL-encoded hostname. More... | |
void | SetHostname (const string &hostname) |
Set hostname. More... | |
const string & | GetHostIP (void) const |
Get host IP address. More... | |
void | SetHostIP (const string &ip) |
Set host IP address. More... | |
const string & | GetAppName (void) const |
Get application name. More... | |
const string & | GetEncodedAppName (void) const |
Get URL-encoded application name. More... | |
void | SetAppName (const string &app_name) |
Set application name. More... | |
bool | IsSetExitCode (void) const |
Check if exit code has been set. More... | |
int | GetExitCode (void) const |
Get exit code. More... | |
void | SetExitCode (int exit_code) |
Set exit code. More... | |
int | GetExitSignal (void) const |
Get exit signal. More... | |
void | SetExitSignal (int exit_sig) |
Set exit signal. More... | |
string | GetDefaultSessionID (void) const |
Get default session id. More... | |
void | SetDefaultSessionID (const string &session_id) |
Set new default session id. More... | |
string | GetSessionID (void) const |
Get the effective session id: the per-request session id if set, or the default session id. More... | |
string | GetEncodedSessionID (void) const |
Get url-encoded session id. More... | |
string | GetDefaultHitID (void) const |
Get global default hit id. More... | |
void | SetDefaultHitID (const string &hit_id) |
Set new global default hit id. More... | |
void | WriteStdPrefix (CNcbiOstream &ostr, const SDiagMessage &msg) const |
Write standard prefix to the stream. More... | |
void | InitMessages (size_t max_size=100) |
Start collecting all messages (the collected messages can be flushed to a new destination later). More... | |
void | PushMessage (const SDiagMessage &message) |
Save new message. More... | |
void | FlushMessages (CDiagHandler &handler) |
Flush the collected messages to the current diag handler. More... | |
void | DiscardMessages (void) |
Discard the collected messages without printing them. More... | |
bool | IsCollectingMessages (void) const |
Check if message collecting is on. More... | |
unsigned int | GetLogRate_Limit (ELogRate_Type type) const |
Logging rate control - max number of messages per period. More... | |
void | SetLogRate_Limit (ELogRate_Type type, unsigned int limit) |
unsigned int | GetLogRate_Period (ELogRate_Type type) const |
Logging rate control - the messages control period, seconds. More... | |
void | SetLogRate_Period (ELogRate_Type type, unsigned int period) |
Static Public Member Functions | |
static TPID | GetPID (void) |
Get cached PID (read real PID if not cached yet). More... | |
static bool | UpdatePID (void) |
Reset PID cache (e.g. after fork). Return true if PID was updated. More... | |
static bool | UpdatePID_AsyncSafe (void) |
static void | UpdateOnFork (TOnForkFlags flags) |
Update diagnostics after fork(). More... | |
static CRequestContext & | GetRequestContext (void) |
Shortcut to CDiagContextThreadData::GetThreadData().GetRequestContext() More... | |
static void | SetRequestContext (CRequestContext *ctx) |
Shortcut to CDiagContextThreadData::GetThreadData().SetRequestContext() More... | |
static bool | IsSetOldPostFormat (void) |
Check old/new format flag (for compatibility only) More... | |
static void | SetOldPostFormat (bool value) |
Set old/new format flag. More... | |
static bool | IsUsingSystemThreadId (void) |
Check if system TID is printed instead of CThread::GetSelf() More... | |
static void | UseSystemThreadId (bool value=true) |
Switch printing system TID (rather than CThread::GetSelf()) on/off. More... | |
static string | GetDefaultClientIP (void) |
Get default client ip. More... | |
static void | SetDefaultClientIP (const string &client_ip) |
Set new default client ip. More... | |
static const string & | GetHostRole (void) |
Get host role (DEV/QA/TRY/PROD) from /etc/ncbi/role. More... | |
static const string & | GetHostLocation (void) |
Get host location (be-md/st-va) from /etc/ncbi/location. More... | |
static bool | GetLogTruncate (void) |
Get log file truncation flag. More... | |
static void | SetLogTruncate (bool value) |
Set log file truncation flag. More... | |
static void | SetUseRootLog (void) |
@depracated The flag is always set now, the funcion still calls SetupDiag() for compatibility, but has no other effects. More... | |
static bool | IsUsingRootLog (void) |
Check if the current diagnostics destination is /log/*. More... | |
static void | SetupDiag (EAppDiagStream ds=eDS_Default, CNcbiRegistry *config=NULL, EDiagCollectMessages collect=eDCM_NoChange, const char *cmd_logfile=NULL) |
Application-wide diagnostics setup. More... | |
static TCount | GetProcessPostNumber (EPostNumberIncrement inc) |
Return process post number (incrementing depends on the flag). More... | |
static TCount | GetThreadPostNumber (EPostNumberIncrement inc) |
Return thread post number (incrementing depends on the flag). More... | |
static TTID | GetTID (void) |
static void | x_FinalizeSetupDiag (void) |
Internal function, should be used only by CNcbiApplication. More... | |
static bool | IsApplogSeverityLocked (void) |
When using applog, the diag post level is locked to Warning. More... | |
static void | SetApplogSeverityLocked (bool lock) |
static bool | IsMainThreadDataInitialized (void) |
Static Public Attributes | |
static const char * | kProperty_UserName = "user" |
Global properties. More... | |
static const char * | kProperty_HostName = "host" |
static const char * | kProperty_HostIP = "host_ip_addr" |
static const char * | kProperty_AppName = "app_name" |
static const char * | kProperty_ExitSig = "exit_signal" |
static const char * | kProperty_ExitCode = "exit_code" |
static const char * | kProperty_AppState = "app_state" |
Per-thread properties. More... | |
static const char * | kProperty_ClientIP = "client_ip" |
static const char * | kProperty_SessionID = "session_id" |
static const char * | kProperty_ReqStatus = "request_status" |
static const char * | kProperty_ReqTime = "request_time" |
static const char * | kProperty_BytesRd = "bytes_rd" |
static const char * | kProperty_BytesWr = "bytes_wr" |
Private Types | |
enum | EDefaultHitIDFlags { eHitID_NoCreate , eHitID_Create } |
typedef map< string, string > | TProperties |
typedef list< SDiagMessage > | TMessages |
Private Member Functions | |
CDiagContext (const CDiagContext &) | |
CDiagContext & | operator= (const CDiagContext &) |
void | x_CreateUID (void) const |
void | x_CreateUID_AsyncSafe (void) const |
void | x_PrintMessage (SDiagMessage::EEventType event, const string &message) |
void | ResetLogRates (void) |
bool | ApproveMessage (SDiagMessage &msg, bool *show_warning) |
bool | x_DiagAtApplicationLevel (void) const |
bool | x_IsSetDefaultHitID (void) const |
CSharedHitId | x_GetDefaultHitID (EDefaultHitIDFlags flag) const |
string | x_GetNextHitID (bool is_default) const |
void | x_LogHitID (void) const |
void | x_LogHitID_WithLock (void) const |
Static Private Member Functions | |
static void | x_StartRequest (void) |
static void | x_LogEnvironment (void) |
static void | sx_ThreadDataTlsCleanup (CDiagContextThreadData *value, void *cleanup_data) |
Private Attributes | |
TUID | m_UID |
unique_ptr< CEncodedString > | m_Host |
string | m_HostIP |
unique_ptr< CEncodedString > | m_Username |
unique_ptr< CEncodedString > | m_AppName |
bool | m_AppNameSet |
unique_ptr< CEncodedString > | m_DefaultSessionId |
unique_ptr< CSharedHitId > | m_DefaultHitId |
bool | m_LoggedHitId |
int | m_ExitCode |
bool | m_ExitCodeSet |
int | m_ExitSig |
EDiagAppState | m_AppState |
TProperties | m_Properties |
unique_ptr< CStopWatch > | m_StopWatch |
unique_ptr< TMessages > | m_Messages |
size_t | m_MaxMessages |
unique_ptr< CRequestRateControl > | m_AppLogRC |
unique_ptr< CRequestRateControl > | m_ErrLogRC |
unique_ptr< CRequestRateControl > | m_TraceLogRC |
atomic< bool > | m_AppLogSuspended |
atomic< bool > | m_ErrLogSuspended |
atomic< bool > | m_TraceLogSuspended |
Static Private Attributes | |
static TPID | sm_PID = 0 |
static CDiagContext * | sm_Instance = NULL |
static bool | sm_ApplogSeverityLocked = false |
Friends | |
class | CDiagContext_Extra |
class | CDiagContextThreadData |
class | CDiagBuffer |
class | CRequestContext |
Definition at line 1930 of file ncbidiag.hpp.