NCBI C++ ToolKit
Classes | Functions | Variables
logging.cpp File Reference
#include "task_server_pch.hpp"
#include <corelib/ncbimtx.hpp>
#include <corelib/ncbifile.hpp>
#include <corelib/request_ctx.hpp>
#include <corelib/ncbireg.hpp>
#include "logging.hpp"
#include "threads_man.hpp"
#include "memory_man.hpp"
#include "server_core.hpp"
#include <fcntl.h>
+ Include dependency graph for logging.cpp:

Go to the source code of this file.

Go to the SVN repository for this file.

Classes

struct  SLogData
 
class  CLogWriter
 

Functions

void Logging_DiskSpaceAlert (void)
 
void SaveAppCmdLine (const string &cmd_line)
 
void SetLogFileName (CTempString name)
 
string GetLogFileName (void)
 
string GetLogVisibility (void)
 
string GetSoftFatalAction (void)
 
static void s_InitConstants (void)
 
static void s_OpenLogFile (void)
 
static void s_WriteLog (const char *buf, size_t size)
 
static void s_QueueLogWrite (char *buf, size_t size)
 
static void s_AllocNewBuf (SLogData *data, size_t buf_size)
 
static void s_RotateLogBuf (SLogData *data)
 
static void s_InitLogPrefix (SLogData *data, TSrvThreadNum thr_num)
 
static bool s_CheckBufSize (SLogData *data, size_t need_size)
 
static void s_AddToLog (SLogData *data, const char *str, size_t size)
 
static void s_AddToLogStripLF (SLogData *data, const char *str, size_t size)
 
static void s_AddToLog (SLogData *data, const char *str)
 
static void s_AddToLogStripLF (SLogData *data, const char *str)
 
static void s_AddToLog (SLogData *data, const string &str)
 
static void s_AddToLogStripLF (SLogData *data, const string &str)
 
static void s_AddToLog (SLogData *data, const string &str, Uint1 min_chars)
 
static void s_AddToLog (SLogData *data, Uint8 num)
 
static void s_AddToLog (SLogData *data, Int8 num)
 
static void s_AddToLog (SLogData *data, int num)
 
static void s_AddToLog (SLogData *data, Uint8 num, Uint1 min_digs)
 
static void s_AddToLog (SLogData *data, double num)
 
static void s_AddLogPrefix (SSrvThread *thr, SLogData *data, CRequestContext *diag_ctx=NULL)
 
static void s_AddParamName (SLogData *data, CTempString name)
 
static SLogDatas_AllocNewData (TSrvThreadNum thr_num)
 
static void s_AllocMainData (void)
 
static void s_InitFileName (void)
 
static void s_DoFatalAbort (SLogData *data)
 
static void s_CheckFatalAbort (void)
 
void LogNoteThreadsStarted (void)
 
void ConfigureLogging (const CNcbiRegistry *reg, CTempString section)
 
bool ReConfig_Logging (const CTempString &section, const CNcbiRegistry &new_reg, string &)
 
bool IsLongCommand (Uint8 cmd_len)
 
void WriteSetup_Logging (CSrvSocketTask &task)
 
void InitLogging (void)
 
void FinalizeLogging (void)
 
void AssignThreadLogging (SSrvThread *thr)
 
void CheckLoggingFlush (SSrvThread *thr)
 
void StartThreadLogging (SSrvThread *thr)
 
void StopThreadLogging (SSrvThread *thr)
 
void ReleaseThreadLogging (SSrvThread *thr)
 
static const char * find_match (char lsep, char rsep, const char *start, const char *stop)
 
static const char * str_rev_str (const char *begin_str, const char *end_str, const char *str_search)
 
static void s_ParseFuncName (const char *func, CTempString &class_name, CTempString &func_name)
 
static bool s_CheckOldStyleStart (const CSrvDiagMsg *msg)
 
static CSrvDiagMsg::ESeverity s_ConvertSeverity (EOldStyleSeverity sev)
 
static CSrvDiagMsg::ESeverity s_ConvertSeverity (EDiagSev sev)
 
CDiagContextGetDiagContext (void)
 Get diag context instance. More...
 
const CSrvDiagMsgoperator<< (const CSrvDiagMsg &msg, EOldStyleSeverity sev)
 
const CSrvDiagMsgoperator<< (const CSrvDiagMsg &msg, ErrCode err_code)
 

Variables

CSrvTime s_JiffyTime
 
static CSrvDiagMsg::ESeverity s_VisibleSev = CSrvDiagMsg::Warning
 
static bool s_LogRequests = true
 
static string s_UnkClient = "UNK_CLIENT"
 
static string s_UnkSession = "UNK_SESSION"
 
static const char * s_SevNames [] = {"Trace", "Info", "Warning", "Error", "Critical", "Fatal", "Fatal", NULL}
 
static const char * s_SoftFatalActions [] = {"abort", "shutdown", "log", NULL}
 
static int s_SoftFatal = 0
 
static const size_t kOneRecReserve = 500
 
static const size_t kInitLogBufSize = 10000000
 
static size_t s_LogBufSize = kInitLogBufSize
 
static int s_MaxFlushPeriod = 60
 
static int s_FileReopenPeriod = 60
 
static Uint8 s_LongCmd = 30000000
 
static string s_CmdLine
 
static string s_Pid
 
static string s_AppUID
 
static string s_FileName
 
static Uint8 s_ProcessPostNum = 0
 
static SLogDatas_MainData = NULL
 
static bool s_InApplog = false
 
static CMiniMutex s_WriteQueueLock
 
static list< CTempStrings_WriteQueue
 
static CLogWriters_LogWriter = NULL
 
static int s_LogFd = -1
 
static int s_LastReopenTime = 0
 
static bool s_NeedFatalHalt = false
 
static bool s_FileNameInitialized = false
 
static bool s_ThreadsStarted = false
 
static bool s_DiskSpaceAlert = false
 
static CFutex s_CntHaltedThreads
 
static CFutex s_Halt
 
string s_AppBaseName
 
SSrvThread ** s_Threads
 

Function Documentation

◆ AssignThreadLogging()

void AssignThreadLogging ( SSrvThread thr)

Definition at line 606 of file logging.cpp.

References s_AllocMainData(), s_AllocNewData(), s_MainData, and thr.

Referenced by s_AllocThread().

◆ CheckLoggingFlush()

void CheckLoggingFlush ( SSrvThread thr)

◆ ConfigureLogging()

void ConfigureLogging ( const CNcbiRegistry reg,
CTempString  section 
)

◆ FinalizeLogging()

void FinalizeLogging ( void  )

◆ find_match()

static const char* find_match ( char  lsep,
char  rsep,
const char *  start,
const char *  stop 
)
static

Definition at line 663 of file logging.cpp.

References NULL.

Referenced by s_ParseFuncName().

◆ GetLogFileName()

string GetLogFileName ( void  )

Definition at line 146 of file logging.cpp.

References s_FileName.

Referenced by main(), and CNCServer::WriteEnvInfo().

◆ GetLogVisibility()

string GetLogVisibility ( void  )

Definition at line 151 of file logging.cpp.

References s_SevNames, and s_VisibleSev.

Referenced by CNCStat::PrintState(), and WriteSetup_Logging().

◆ GetSoftFatalAction()

string GetSoftFatalAction ( void  )

Definition at line 156 of file logging.cpp.

References s_SoftFatal, and s_SoftFatalActions.

Referenced by CNCStat::PrintState(), and WriteSetup_Logging().

◆ InitLogging()

void InitLogging ( void  )

Definition at line 573 of file logging.cpp.

References s_AllocMainData(), s_InitFileName(), s_LogWriter, and s_MainData.

Referenced by CTaskServer::Initialize().

◆ IsLongCommand()

bool IsLongCommand ( Uint8  cmd_len)

Definition at line 555 of file logging.cpp.

References s_LongCmd.

Referenced by CNCMessageHandler::x_CleanCmdResources().

◆ Logging_DiskSpaceAlert()

void Logging_DiskSpaceAlert ( void  )

Definition at line 126 of file logging.cpp.

References s_DiskSpaceAlert.

Referenced by CNCBlobStorage::CheckDiskSpace().

◆ LogNoteThreadsStarted()

void LogNoteThreadsStarted ( void  )

Definition at line 517 of file logging.cpp.

References s_MainData, s_RotateLogBuf(), and s_ThreadsStarted.

Referenced by s_StartAllThreads().

◆ operator<<() [1/2]

const CSrvDiagMsg& operator<< ( const CSrvDiagMsg msg,
EOldStyleSeverity  sev 
)

Definition at line 982 of file logging.cpp.

References CSrvDiagMsg::m_Data, s_ConvertSeverity(), and SLogData::severity.

◆ operator<<() [2/2]

const CSrvDiagMsg& operator<< ( const CSrvDiagMsg msg,
ErrCode  err_code 
)

◆ ReConfig_Logging()

bool ReConfig_Logging ( const CTempString section,
const CNcbiRegistry new_reg,
string err_message 
)

Definition at line 549 of file logging.cpp.

References ConfigureLogging().

Referenced by CTaskServer::ReConfig().

◆ ReleaseThreadLogging()

void ReleaseThreadLogging ( SSrvThread thr)

Definition at line 653 of file logging.cpp.

References SLogData::buf, SLogData::cur_ptr, s_WriteLog(), and thr.

Referenced by s_JoinAllThreads().

◆ s_AddLogPrefix()

static void s_AddLogPrefix ( SSrvThread thr,
SLogData data,
CRequestContext diag_ctx = NULL 
)
static

◆ s_AddParamName()

static void s_AddParamName ( SLogData data,
CTempString  name 
)
static

◆ s_AddToLog() [1/9]

static void s_AddToLog ( SLogData data,
const char *  str 
)
inlinestatic

Definition at line 298 of file logging.cpp.

References s_AddToLog(), and str().

◆ s_AddToLog() [2/9]

static void s_AddToLog ( SLogData data,
const char *  str,
size_t  size 
)
inlinestatic

◆ s_AddToLog() [3/9]

static void s_AddToLog ( SLogData data,
const string str 
)
inlinestatic

Definition at line 310 of file logging.cpp.

References s_AddToLog(), and str().

◆ s_AddToLog() [4/9]

static void s_AddToLog ( SLogData data,
const string str,
Uint1  min_chars 
)
inlinestatic

Definition at line 322 of file logging.cpp.

References SLogData::cur_ptr, i, max(), s_AddToLog(), s_CheckBufSize(), and str().

◆ s_AddToLog() [5/9]

static void s_AddToLog ( SLogData data,
double  num 
)
inlinestatic

Definition at line 363 of file logging.cpp.

References NStr::DoubleToString(), s_AddToLog(), and SLogData::tmp_str.

◆ s_AddToLog() [6/9]

static void s_AddToLog ( SLogData data,
int  num 
)
inlinestatic

Definition at line 346 of file logging.cpp.

References s_AddToLog().

◆ s_AddToLog() [7/9]

static void s_AddToLog ( SLogData data,
Int8  num 
)
inlinestatic

Definition at line 339 of file logging.cpp.

References NStr::Int8ToString(), s_AddToLog(), and SLogData::tmp_str.

◆ s_AddToLog() [8/9]

static void s_AddToLog ( SLogData data,
Uint8  num 
)
inlinestatic

Definition at line 332 of file logging.cpp.

References s_AddToLog(), SLogData::tmp_str, and NStr::UInt8ToString().

◆ s_AddToLog() [9/9]

static void s_AddToLog ( SLogData data,
Uint8  num,
Uint1  min_digs 
)
inlinestatic

◆ s_AddToLogStripLF() [1/3]

static void s_AddToLogStripLF ( SLogData data,
const char *  str 
)
inlinestatic

Definition at line 304 of file logging.cpp.

References s_AddToLogStripLF(), and str().

◆ s_AddToLogStripLF() [2/3]

static void s_AddToLogStripLF ( SLogData data,
const char *  str,
size_t  size 
)
inlinestatic

◆ s_AddToLogStripLF() [3/3]

static void s_AddToLogStripLF ( SLogData data,
const string str 
)
inlinestatic

Definition at line 316 of file logging.cpp.

References s_AddToLogStripLF(), and str().

◆ s_AllocMainData()

static void s_AllocMainData ( void  )
static

◆ s_AllocNewBuf()

static void s_AllocNewBuf ( SLogData data,
size_t  buf_size 
)
inlinestatic

◆ s_AllocNewData()

static SLogData* s_AllocNewData ( TSrvThreadNum  thr_num)
static

◆ s_CheckBufSize()

static bool s_CheckBufSize ( SLogData data,
size_t  need_size 
)
inlinestatic

◆ s_CheckFatalAbort()

static void s_CheckFatalAbort ( void  )
inlinestatic

◆ s_CheckOldStyleStart()

static bool s_CheckOldStyleStart ( const CSrvDiagMsg msg)
inlinestatic

◆ s_ConvertSeverity() [1/2]

static CSrvDiagMsg::ESeverity s_ConvertSeverity ( EDiagSev  sev)
inlinestatic

◆ s_ConvertSeverity() [2/2]

static CSrvDiagMsg::ESeverity s_ConvertSeverity ( EOldStyleSeverity  sev)
inlinestatic

◆ s_DoFatalAbort()

static void s_DoFatalAbort ( SLogData data)
static

◆ s_InitConstants()

static void s_InitConstants ( void  )
static

◆ s_InitFileName()

static void s_InitFileName ( void  )
static

◆ s_InitLogPrefix()

static void s_InitLogPrefix ( SLogData data,
TSrvThreadNum  thr_num 
)
inlinestatic

Definition at line 258 of file logging.cpp.

References SLogData::prefix, s_Pid, SLogData::tmp_str, and NStr::UInt8ToString().

Referenced by s_AllocNewData(), and CDiagContext::UpdatePID().

◆ s_OpenLogFile()

static void s_OpenLogFile ( void  )
inlinestatic

Definition at line 187 of file logging.cpp.

References s_DiskSpaceAlert, s_FileName, and s_LogFd.

Referenced by s_InitFileName(), and s_WriteLog().

◆ s_ParseFuncName()

static void s_ParseFuncName ( const char *  func,
CTempString class_name,
CTempString func_name 
)
static

◆ s_QueueLogWrite()

static void s_QueueLogWrite ( char *  buf,
size_t  size 
)
static

◆ s_RotateLogBuf()

static void s_RotateLogBuf ( SLogData data)
static

◆ s_WriteLog()

static void s_WriteLog ( const char *  buf,
size_t  size 
)
static

◆ SaveAppCmdLine()

void SaveAppCmdLine ( const string cmd_line)

Definition at line 132 of file logging.cpp.

References s_CmdLine.

Referenced by s_ProcessParameters().

◆ SetLogFileName()

void SetLogFileName ( CTempString  name)

◆ StartThreadLogging()

void StartThreadLogging ( SSrvThread thr)

Definition at line 635 of file logging.cpp.

References s_AllocNewData(), and thr.

Referenced by s_StartCurMgrThread().

◆ StopThreadLogging()

void StopThreadLogging ( SSrvThread thr)

Definition at line 641 of file logging.cpp.

References SLogData::buf, SLogData::cur_ptr, free(), s_CheckFatalAbort(), s_QueueLogWrite(), and thr.

Referenced by s_StopCurMgrThread().

◆ str_rev_str()

static const char* str_rev_str ( const char *  begin_str,
const char *  end_str,
const char *  str_search 
)
static

Definition at line 680 of file logging.cpp.

References NULL.

Referenced by s_ParseFuncName().

◆ WriteSetup_Logging()

void WriteSetup_Logging ( CSrvSocketTask task)

Variable Documentation

◆ kInitLogBufSize

const size_t kInitLogBufSize = 10000000
static

Definition at line 97 of file logging.cpp.

◆ kOneRecReserve

const size_t kOneRecReserve = 500
static

Definition at line 96 of file logging.cpp.

Referenced by CSrvDiagMsg::Flush().

◆ s_AppBaseName

string s_AppBaseName
extern

Definition at line 77 of file server_core.cpp.

Referenced by s_AddLogPrefix(), and s_InitFileName().

◆ s_AppUID

string s_AppUID
static

Definition at line 104 of file logging.cpp.

Referenced by s_AddLogPrefix(), s_InitConstants(), and CDiagContext::UpdatePID().

◆ s_CmdLine

string s_CmdLine
static

Definition at line 102 of file logging.cpp.

Referenced by s_AllocMainData(), and SaveAppCmdLine().

◆ s_CntHaltedThreads

CFutex s_CntHaltedThreads
static

Definition at line 118 of file logging.cpp.

Referenced by s_CheckFatalAbort(), and s_DoFatalAbort().

◆ s_DiskSpaceAlert

bool s_DiskSpaceAlert = false
static

Definition at line 117 of file logging.cpp.

Referenced by Logging_DiskSpaceAlert(), and s_OpenLogFile().

◆ s_FileName

string s_FileName
static

Definition at line 105 of file logging.cpp.

Referenced by GetLogFileName(), s_InitFileName(), s_OpenLogFile(), and SetLogFileName().

◆ s_FileNameInitialized

bool s_FileNameInitialized = false
static

Definition at line 115 of file logging.cpp.

Referenced by s_DoFatalAbort(), and s_InitFileName().

◆ s_FileReopenPeriod

int s_FileReopenPeriod = 60
static

Definition at line 100 of file logging.cpp.

Referenced by ConfigureLogging(), CLogWriter::ExecuteSlice(), and WriteSetup_Logging().

◆ s_Halt

CFutex s_Halt
static

Definition at line 119 of file logging.cpp.

Referenced by s_CheckFatalAbort().

◆ s_InApplog

bool s_InApplog = false
static

Definition at line 108 of file logging.cpp.

Referenced by CSrvDiagMsg::operator<<(), and s_InitFileName().

◆ s_JiffyTime

CSrvTime s_JiffyTime
extern

Definition at line 54 of file time_man.cpp.

Referenced by s_DoFatalAbort().

◆ s_LastReopenTime

int s_LastReopenTime = 0
static

Definition at line 113 of file logging.cpp.

Referenced by CLogWriter::ExecuteSlice(), and s_WriteLog().

◆ s_LogBufSize

size_t s_LogBufSize = kInitLogBufSize
static

Definition at line 98 of file logging.cpp.

Referenced by ConfigureLogging(), s_AllocNewData(), s_RotateLogBuf(), and WriteSetup_Logging().

◆ s_LogFd

int s_LogFd = -1
static

◆ s_LogRequests

bool s_LogRequests = true
static

◆ s_LogWriter

CLogWriter* s_LogWriter = NULL
static

Definition at line 111 of file logging.cpp.

Referenced by InitLogging(), and s_QueueLogWrite().

◆ s_LongCmd

Uint8 s_LongCmd = 30000000
static

Definition at line 101 of file logging.cpp.

Referenced by ConfigureLogging(), IsLongCommand(), and WriteSetup_Logging().

◆ s_MainData

SLogData* s_MainData = NULL
static

◆ s_MaxFlushPeriod

int s_MaxFlushPeriod = 60
static

Definition at line 99 of file logging.cpp.

Referenced by CheckLoggingFlush(), ConfigureLogging(), and WriteSetup_Logging().

◆ s_NeedFatalHalt

bool s_NeedFatalHalt = false
static

Definition at line 114 of file logging.cpp.

Referenced by s_CheckFatalAbort(), and s_DoFatalAbort().

◆ s_Pid

string s_Pid
static

Definition at line 103 of file logging.cpp.

Referenced by s_InitConstants(), and s_InitLogPrefix().

◆ s_ProcessPostNum

Uint8 s_ProcessPostNum = 0
static

Definition at line 106 of file logging.cpp.

Referenced by s_AddLogPrefix().

◆ s_SevNames

const char* s_SevNames[] = {"Trace", "Info", "Warning", "Error", "Critical", "Fatal", "Fatal", NULL}
static

◆ s_SoftFatal

int s_SoftFatal = 0
static

Definition at line 95 of file logging.cpp.

Referenced by ConfigureLogging(), CSrvDiagMsg::Flush(), and GetSoftFatalAction().

◆ s_SoftFatalActions

const char* s_SoftFatalActions[] = {"abort", "shutdown", "log", NULL}
static

Definition at line 94 of file logging.cpp.

Referenced by ConfigureLogging(), and GetSoftFatalAction().

◆ s_Threads

SSrvThread** s_Threads
extern

Definition at line 59 of file threads_man.cpp.

Referenced by CDiagContext::UpdatePID().

◆ s_ThreadsStarted

bool s_ThreadsStarted = false
static

Definition at line 116 of file logging.cpp.

Referenced by LogNoteThreadsStarted(), and s_DoFatalAbort().

◆ s_UnkClient

string s_UnkClient = "UNK_CLIENT"
static

Definition at line 91 of file logging.cpp.

Referenced by s_AddLogPrefix().

◆ s_UnkSession

string s_UnkSession = "UNK_SESSION"
static

Definition at line 92 of file logging.cpp.

Referenced by s_AddLogPrefix().

◆ s_VisibleSev

Definition at line 89 of file logging.cpp.

Referenced by ConfigureLogging(), GetLogVisibility(), and CSrvDiagMsg::IsSeverityVisible().

◆ s_WriteQueue

list<CTempString> s_WriteQueue
static

Definition at line 110 of file logging.cpp.

Referenced by CLogWriter::ExecuteSlice(), s_DoFatalAbort(), and s_QueueLogWrite().

◆ s_WriteQueueLock

CMiniMutex s_WriteQueueLock
static

Definition at line 109 of file logging.cpp.

Referenced by CLogWriter::ExecuteSlice(), and s_QueueLogWrite().

Modified on Wed Feb 28 07:11:15 2024 by modify_doxy.py rev. 669887