// PHID: same as s_TestCase_PHID_Req_subhit_2(), but with PHID set in the environment. // void s_TestCase_PHID_Req_subhit_3(void) { char* subhitid; putenv((char*)"HTTP_NCBI_PHID=SOME_ENV_PHID"); NcbiLog_AppStart(NULL); NcbiLog_AppRun(); // app-level sub-hit-id GETSUBHIT; // request 1 NcbiLog_SetHitID("REQUEST1"); NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // app-level in-between requests sub-hit-id GETSUBHIT; // request 2 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // stop GETSUBHIT; NcbiLog_AppStop(0); putenv((char*)"HTTP_NCBI_PHID="); }
// PHID: use autogenerated phid and GetNextSubHitID() on app-wide level // void s_TestCase_PHID_App_subhit(void) { NcbiLog_AppStart(NULL); NcbiLog_AppRun(); NcbiLog_GetNextSubHitID(); NcbiLog_AppStop(0); }
// PHID: set global app-wide PHID. // void s_TestCase_PHID_App(void) { NcbiLog_AppSetHitID("APP-HIT-ID"); NcbiLog_AppStart(NULL); NcbiLog_AppRun(); NcbiLog_AppStop(0); }
bool CTestRegApp::TestApp_Init(void) { // Initialize the C logging API with default MT locking imlementation NcbiLog_InitMT(GetAppName().c_str()); // Set output to files in current directory NcbiLog_SetDestination(eNcbiLog_Cwd); // Start application NcbiLog_AppStart(NULL); NcbiLog_AppRun(); return true; }
// Default start/stop + 2 empty requests inside. // void s_TestCase_EmptyRequests(void) { NcbiLog_AppStart(NULL); NcbiLog_AppRun(); // request 1 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); NcbiLog_ReqStop(200, 1, 2); // request 2 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); NcbiLog_ReqStop(200, 1, 2); // stop NcbiLog_AppStop(0); }
// PHID: use GetNextSubHitID() for each request // void s_TestCase_PHID_Req_subhit_1(void) { char* subhitid; NcbiLog_AppStart(NULL); NcbiLog_AppRun(); // request 1 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // request 2 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // stop NcbiLog_AppStop(0); }
// PHID: use GetNextSubHitID() for app and each request. // Use implicit request name for one of the requests. // void s_TestCase_PHID_Req_subhit_2(void) { char* subhitid; NcbiLog_AppStart(NULL); NcbiLog_AppRun(); // app-level sub-hit-id GETSUBHIT; // request 1 NcbiLog_SetHitID("REQUEST1"); NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // app-level in-between requests sub-hit-id GETSUBHIT; // request 2 NcbiLog_ReqStart(NULL); NcbiLog_ReqRun(); GETSUBHIT; NcbiLog_ReqStop(200, 1, 2); // stop GETSUBHIT; NcbiLog_AppStop(0); }
// Default start/stop, nothing else. // void s_TestCase_EmptyApp(void) { NcbiLog_AppStart(NULL); NcbiLog_AppRun(); NcbiLog_AppStop(0); }
int main(int argc, const char* argv[] /*, const char* envp[]*/) { TNcbiLog_MTLock mt_lock = NcbiLog_MTLock_Create(NULL, Test_MT_Handler); /* Initialize logging API */ NcbiLog_Init(argv[0], mt_lock, eNcbiLog_MT_TakeOwnership); /* Or, NcbiLog_InitMT(argv[0]); -- use default MT handler as above. NcbiLog_InitST(argv[0]); -- only for single-threaded applications */ /* Set logging destination */ NcbiLog_SetDestination(eNcbiLog_Stdout); /* Or, NcbiLog_SetDestination(eNcbiLog_Default); -- default, can be skipped NcbiLog_SetDestination(eNcbiLog_Stdlog); NcbiLog_SetDestination(eNcbiLog_Stdout); NcbiLog_SetDestination(eNcbiLog_Stderr); NcbiLog_SetDestination(eNcbiLog_Disable); */ /* Set host name NcbiLog_SetHost("SOMEHOSTNAME"); */ /* Set log_site NcbiLog_SetLogSite(""); */ /* Set process/thread ID NcbiLog_SetProcessId(pid); NcbiLog_SetThreadId(tid); */ /* Start application */ NcbiLog_AppStart(argv); NcbiLog_AppRun(); /* Standard messages */ {{ NcbiLog_SetPostLevel(eNcbiLog_Warning); NcbiLog_Trace("Message"); NcbiLog_Warning("Message"); NcbiLog_Error("Message"); NcbiLog_Critical("Message"); /* NcbiLog_Fatal("Message"); */ }} /* Standard messages with user provided time */ {{ time_t timer; NcbiLog_SetPostLevel(eNcbiLog_Trace); timer = time(0); NcbiLog_SetTime(timer, 0); NcbiLog_Trace("Use user provided time (1)"); NcbiLog_Trace("Use user provided time (2)"); NcbiLog_SetTime(0,0); NcbiLog_Trace("Use system local time"); }} /* Request without parameters */ {{ NcbiLog_ReqStart(NULL); NcbiLog_ReqStop(200, 1, 2); }} /* Message printed between requests */ {{ NcbiLog_Error("Message printed between requests"); }} /* Request without parameters -- new ID */ {{ NcbiLog_SetRequestId(10); NcbiLog_ReqStart(NULL); NcbiLog_ReqStop(403, 5, 6); }} /* Request with parameters */ {{ static const SNcbiLog_Param params[] = { { "k1", "v1" }, { "k2", "v2" }, { "", "v3" }, { "k4", "" }, { "", "" }, { "k5", "v5" }, { NULL, NULL } }; NcbiLog_SetSession("session name"); NcbiLog_SetClient("192.168.1.1"); NcbiLog_ReqStart(params); NcbiLog_ReqRun(); NcbiLog_ReqStop(500, 3, 4); }} /* Extra & performance logging */ {{ double timespan = 1.2345678; static const SNcbiLog_Param params[] = { { "resource", "test" }, { "key", "value" }, { NULL, NULL } }; NcbiLog_Extra(params); NcbiLog_Perf(200, timespan, params); }} /* Stop application with exit code 0 */ NcbiLog_AppStop(0); /* Deinitialize logging API */ NcbiLog_Destroy(); return 0; }