*
kDefaultCGI=
"https://intranet.ncbi.nlm.nih.gov/ieb/ToolBox/util/ncbi_applog.cgi";
163 "^\\d{5,}/\\d{3,}/\\d{4,}/[NSPRBE ]{3}[0-9A-Z]{16} " 165 "\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3,9} " 166 ".{15} .{15} [^ ]{1,} +" 240 virtual void Init();
291 size_tkUsageWidth = 90;
297unique_ptr<CCommandArgDescriptions>
cmd(
new 300 cmd->SetUsageContext(
GetArguments().GetProgramBasename(),
"Command-line utility to log to AppLog");
305arg->SetUsageContext(
kEmptyStr,
"Start application. Return token.",
false, kUsageWidth);
306arg->SetDetailedDescription(
307 "Starting logging. You should specify a name of application for that you log and its PID at least. " 308 "First, utility tries to log locally (to /log) by default. If it can't do that then it try to call " 309 "a CGI that does the logging on other machine, or log to stderr on error." 310 "Returns logging token that should be used for any subsequent app related calls." 323(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
326(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
331(
"logsite",
"SITE",
"Value for logsite parameter. If empty $NCBI_APPLOG_SITE will be used.",
336(
"hostrole",
"ROLE",
"Host role (will be used automatically for 'redirect' mode)",
339(
"hostloc",
"LOCATION",
"Host location (will be used automatically for 'redirect' mode)",
342(
"srvport",
"PORT",
"Server port (will be used automatically for 'redirect' mode)",
344 cmd->AddCommand(
"start_app", arg.release());
350arg->SetUsageContext(
kEmptyStr,
"Stop application.",
false, kUsageWidth);
351arg->SetDetailedDescription(
352 "Stop logging and invalidate passed token. This command should be last in the logging session." 355(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
359(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
362(
"exectime",
"TIMESPAN",
"Application execution time. If not specified, calculates on base " 363 "of -timestamp parameters for start/stop commands, or current time.",
368(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
372 cmd->AddCommand(
"stop_app", arg.release());
378arg->SetUsageContext(
kEmptyStr,
"Start request. Return token.",
false, kUsageWidth);
379arg->SetDetailedDescription(
380 "Starting logging request. " 381 "Returns logging token specific for this request, it should be used for all subsequent calls related " 382 "to this request. The <stop_request> command invalidate it." 385(
"token",
"Session token, obtained from stdout for <start_app> command or previous request.",
CArgDescriptions::eString);
397(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
401(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
405 cmd->AddCommand(
"start_request", arg.release());
411arg->SetUsageContext(
kEmptyStr,
"Stop request.",
false, kUsageWidth);
412arg->SetDetailedDescription(
413 "Stop logging request. " 414 "Invalidate request specific token obtained for <start_request> command. " 415 "Returns the same token as <start_app> command, so you can use any for logging between requests." 426(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
431(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
435 cmd->AddCommand(
"stop_request", arg.release());
441arg->SetUsageContext(
kEmptyStr,
"Post a message.",
false, kUsageWidth);
442arg->SetDetailedDescription(
443 "Post a message to the log with specified severity." 446(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
453(
"severity", &(*
new CArgAllow_Strings,
"trace",
"info",
"warning",
"error",
"critical"));
456arg->AddFlag(
"note",
"Post message as a note, using Note[X] notation for a severity");
458(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
463(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
467 cmd->AddCommand(
"post", arg.release());
473arg->SetUsageContext(
kEmptyStr,
"Post an extra information.",
false, kUsageWidth);
476(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
480(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
485(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
489 cmd->AddCommand(
"extra", arg.release());
495arg->SetUsageContext(
kEmptyStr,
"Post performance information.",
false, kUsageWidth);
498(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
506(
"timestamp",
"TIME",
"Posting time if differ from current (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
511(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
515 cmd->AddCommand(
"perf", arg.release());
522arg->SetUsageContext(
kEmptyStr,
"Parse token information and print requested field to stdout.",
false, kUsageWidth);
525(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
526arg->AddFlag(
"appname",
"Name of the application.");
527arg->AddFlag(
"client",
"Client IP address.");
528arg->AddFlag(
"guid",
"Globally unique process ID.");
529arg->AddFlag(
"host",
"Name of the host where the application runs.");
530arg->AddFlag(
"hostrole",
"Host role.");
531arg->AddFlag(
"hostloc",
"Host location.");
532arg->AddFlag(
"logsite",
"Value for logsite parameter.");
533arg->AddFlag(
"pid",
"Process ID of the application.");
534arg->AddFlag(
"sid",
"Session ID (application-wide or request, depending on the type of token).");
535arg->AddFlag(
"phid",
"Hit ID (application-wide value).");
536arg->AddFlag(
"rid",
"Request ID.");
537arg->AddFlag(
"srvport",
"Server port.");
538arg->AddFlag(
"app_start_time",
"Application start time (time_t value).");
539arg->AddFlag(
"req_start_time",
"Request start time (for request-type tokens only, time_t value).");
540 cmd->AddCommand(
"parse_token", arg.release());
546arg->SetUsageContext(
kEmptyStr,
"Generate an Applog query URL.",
false, kUsageWidth);
547arg->SetDetailedDescription(
548 "Generate an Applog query URL on a base of token information and print it to stdout. " 549 "Token can be obtained from <start_app> or <start_request> command. " 550 "Generated URL will include data to a whole application or request only, accordingly to " 551 "the type of specified token and provided flags. Also, this command should be called " 552 "after <stop_app> or <stop_request> to get correct date/time range for the query. " 553 "Or you can use -maxtime argument to specify the end of the query time range. " 554 "Starting date/time for a query will be automatically obtained from the token. " 555 "The generated url query includes only a minimum information by default, " 556 "at least one flag should be used to add search terms, if in doubt use -std flag." 557 "This operation doesn't affect current logging (if any)." 560(
"token",
"Session token, obtained from stdout for <start_app> or <start_request> command.",
CArgDescriptions::eString);
561arg->AddFlag(
"std",
"Include application name, host name and pid to the query. " 562 "Automatically imply -appname, -host and -pid flags.");
563arg->AddFlag(
"appname",
"Include application name to the query.");
564arg->AddFlag(
"host",
"Include host name to the query.");
565arg->AddFlag(
"pid",
"Include process ID of the application to the query.");
566arg->AddFlag(
"sid",
"Include session ID (application-wide or request, depending on the type of token) to the query.");
567arg->AddFlag(
"phid",
"Include hit ID (application-wide or request, depending on the type of token) to the query.");
568arg->AddDefaultKey(
"maxtime",
"TIME",
569 "Specify ending date/time for a query range, current by default (YYYY-MM-DDThh:mm:ss, MM/DD/YY hh:mm:ss, time_t).",
571arg->AddDefaultKey(
"maxtime-delay",
"TIMESPAN",
572 "A timespan used to adjust ending date/time for a query, specified by -maxtime argument " 573 "(or current time, if not specified). Could be useful to get an URL before sending <stop_app> " 574 "command and to avoid any time calculations directly in the scripts. " 575 "Accept a string with timespan in the human readable format (like '100 seconds', '100s', '2m 30s', '1d').",
577 cmd->AddCommand(
"url", arg.release());
583arg->SetUsageContext(
kEmptyStr,
"Post already prepared log in applog format.",
false, kUsageWidth);
584arg->SetDetailedDescription(
585 "Copy already existing data in applog format to the log. You can specify a file name with data " 586 "or print it to the standard input. All lines in non-applog format will be ignored. " 587 "If $NCBI_APPLOG_SITE environment variable is specified, that the application name in the passed " 588 "logging data will be replaced with its value and original application name added as 'extra'." 591(
"file",
"filename",
"Name of the file with log lines. Use '-' to read from the standard input.",
594(
"appname",
"NAME",
"Name of the application (optional). If empty, an application name from " 595 "the first RAW line will be used. This parameter affects the name of the created log file only.",
598(
"logsite",
"SITE",
"Value for logsite parameter. If empty $NCBI_APPLOG_SITE will be used.",
604(
"nl",
"N",
"Turn ON incremental logging for CGI redirects. " 605 "Send previously accumulated data after every specified number of log lines.",
608(
"nr",
"N",
"Turn ON incremental logging for CGI redirects. " 609 "Send previously accumulated data after every specified number of requests.",
612(
"timeout",
"SEC",
"Turn ON incremental logging for CGI redirects ('-' source only). " 613 "Send previously accumulated data after specified number of seconds of inactivity in the standard input.",
624(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
626 cmd->AddCommand(
"raw", arg.release());
632arg->SetUsageContext(
kEmptyStr,
"Generate and return IDs.",
false, kUsageWidth);
633arg->SetDetailedDescription(
634 "This operation doesn't affect current logging (if any). All flags will be " 635 "processed and printed in the exact order they were specified in the command line. " 636 "If more than one flag specified, each value will be printed on a separate line." 640 "Generate and return Hit ID (PHID) to use in the user script.");
643 "Generate and return Session ID (SID) to use in the user script.");
645(
"format",
"FORMAT",
"Output format for generated values.",
649 cmd->AddCommand(
"generate", arg.release());
655arg->SetUsageContext(
kEmptyStr,
"Health checks.",
false, kUsageWidth);
656arg->SetDetailedDescription(
657 "Check local and CGI logging capabilities, print short report to stdout " 658 "in the NCBI registry format. Exit with status code 0 if logging is possible " 659 "(local or via CGI). If this is allowed via CGI only, check that versions " 660 "for local and CGI executables match." 663(
"logsite",
"SITE",
"Value for logsite parameter. If empty $NCBI_APPLOG_SITE will be used.",
668(
"mode",
"MODE",
"Use local/redirect logging ('redirect' will be used automatically if /log is not accessible on current machine)",
672 cmd->AddCommand(
"health", arg.release());
687 #if defined(NCBI_OS_MSWIN) 692 unsigned longtimeout_msec = timeout.
IsInfinite() ? 1
694 HANDLEhStdin = GetStdHandle(STD_INPUT_HANDLE);
700 unsigned longx_sleep = 1;
701 DWORDbytes_avail = 0;
705 if( !res || !timeout_msec) {
715 if(x_sleep > timeout_msec) {
716x_sleep = timeout_msec;
718timeout_msec -= x_sleep;
732poll_fd[0].
fd= fileno(stdin);
736 int n=
poll(poll_fd, 1, timeout_msec);
746 if(errno != EINTR) {
771 boolneed_hostname =
true;
772 boolneed_sid =
true;
773 boolneed_phid =
true;
774 boolneed_logsite =
true;
775 boolskip_next_arg =
false;
779 for(
size_t i= 1;
i< raw_args.
Size(); ++
i) {
781skip_next_arg =
false;
784 if(
i== 2 && !is_start_app && raw_args[
i].
empty() ) {
787s_args +=
" \""+
m_Token+
"\"";
792need_hostname =
false;
801need_logsite =
false;
817skip_next_arg =
true;
820s_args +=
" \""+ raw_args[
i] +
"\"";
841 if(!logsite.empty()) {
880cgi << s_args << endl;
896*cgi << header << endl;
907ECgiSplitMethod method = eRAW_AllAtOnce;
909 size_tcriterion_count = 1;
913method = eRAW_NumLines;
914criterion_count = args[
"nl"].AsInteger();
917method = eRAW_NumRequests;
918criterion_count = args[
"nr"].AsInteger();
920 if(args[
"timeout"]) {
924method = eRAW_Timeout;
925criterion_timeout.
Set(args[
"timeout"].AsDouble());
930 size_tn_sent_lines = 0;
931 size_tn_sent_requests = 0;
944 boolneed_split =
false;
948need_split = (n_sent_lines % criterion_count == 0);
950 caseeRAW_NumRequests:
953 size_tnamepos, namelen;
958need_split = (n_sent_requests % criterion_count == 0);
980 if(method == eRAW_Timeout) {
985*cgi << header << endl;
998 throwstd::runtime_error(
"Failed to redirect request to CGI");
1002getline(cgi,
output,
'\0');
1004 throwstd::runtime_error(
"Failed to read CGI output");
1007 if(res != 0 && res != 200) {
1008 throwstd::runtime_error(
"Failed to call CGI, HTTP status code "+
NStr::IntToString(res));
1015 throwstd::runtime_error(
"Failed to call CGI: "+
output);
1027 if(!apos || !apos[0] || !apos[1] || (apos[0] >= apos[1])) {
1028 throwstd::runtime_error(
"Error processing input raw log, line has wrong format");
1031*from = (size_t)apos[0];
1034*
len= (size_t)(apos[1] - apos[0]);
1037*appname =
m_Raw_line.substr(apos[0], apos[1] - apos[0]);
1105 boolhave_name =
false,
1109have_atime =
false,
1110have_rtime =
false;
1112 ITERATE(list<string>, pair, pairs) {
1116 if(
key==
"name") {
1119}
else if(
key==
"pid") {
1122}
else if(
key==
"guid") {
1125}
else if(
key==
"host") {
1127}
else if(
key==
"hostrole") {
1129}
else if(
key==
"hostloc") {
1131}
else if(
key==
"srvport") {
1133}
else if(
key==
"client") {
1135}
else if(
key==
"asid") {
1137}
else if(
key==
"rsid") {
1140}
else if(
key==
"phid") {
1142}
else if(
key==
"logsite") {
1144}
else if(
key==
"rid") {
1148}
else if(
key==
"atime") {
1154}
else if(
key==
"rtime") {
1163 if(!(have_name && have_pid && have_guid && have_atime)) {
1164 throwstd::runtime_error(
"Token string has wrong format");
1167 if(!(have_rid && have_rtime)) {
1168 throwstd::runtime_error(
"Token string has wrong format (request token type expected)");
1179 boolneed_eol = (raw_args.
Size() > 4);
1181 for(
size_t i= 3;
i< raw_args.
Size(); ++
i) {
1182 stringarg = raw_args[
i];
1183 if(arg ==
"-appname") {
1185}
else if(arg ==
"-client") {
1187}
else if(arg ==
"-guid") {
1189}
else if(arg ==
"-host") {
1191}
else if(arg ==
"-hostrole") {
1193}
else if(arg ==
"-hostloc") {
1195}
else if(arg ==
"-logsite") {
1197}
else if(arg ==
"-pid") {
1199}
else if(arg ==
"-sid") {
1201}
else if(arg ==
"-phid") {
1203}
else if(arg ==
"-rid") {
1205}
else if(arg ==
"-srvport") {
1207}
else if(arg ==
"-app_start_time") {
1209}
else if(arg ==
"-req_start_time") {
1212 Error(
"Unknown command line argument: "+ arg);
1282 throwstd::runtime_error(
"PHID is too long '"+
m_Info.
phid_app+
"'");
1346 static const char* kPHID =
"NCBI_LOG_HIT_ID";
1347 static const char* kSID =
"NCBI_LOG_SESSION_ID";
1350 const stringfmt =
GetArgs()[
"format"].AsString();
1354 boolnewline =
false;
1358 for(
size_t i= 1;
i< raw_args.
Size(); ++
i) {
1359 stringarg = raw_args[
i];
1360 const char*
env=
nullptr;
1362 if(arg ==
"-phid") {
1367}
else if(arg ==
"-sid") {
1377 if(fmt ==
"shell"|| fmt ==
"shell-export") {
1378cout <<
env<<
"=";
1381 if(fmt ==
"shell-export") {
1382cout <<
"\nexport "<<
env<<
'\n';
1397 static const char* kCgi =
"CGI";
1398 static const char* kLocal =
"LOCAL";
1399 static const char*
kVersion=
"Version";
1400 static const char* kLog =
"Log";
1403 if(args[
"mode"].AsString() ==
"cgi") {
1435 strings_args =
"health ";
1443cgi << s_args << endl;
1447 boolis_cgi_on =
false;
1448 inthttp_status = -1;
1452getline(cgi,
output,
'\0');
1454is_cgi_on = (http_status == 0 || http_status == 200) &&
1468 returnis_log_writable ? 0 : 1;
1476 catch(exception&) {}
1482 if(!is_log_writable) {
1496 boolis_api_init =
false;
1508 if(args.
Exist(
"logsite")) {
1516 if(
cmd==
"start_app") {
1520 stringsrvport = args[
"srvport"].AsString();
1521 if( srvport.empty() ) {
1528 if(
cmd==
"raw") {
1531 stringfilename = args[
"file"].AsString();
1532 if(filename ==
"-") {
1537 throwstd::runtime_error(
"Failed to open file '"+ filename +
"'");
1549 boolfound =
false;
1557 throwstd::runtime_error(
"Error processing input raw log, cannot find any line in applog format");
1564 if(
cmd==
"generate") {
1568 if(
cmd==
"health") {
1573 m_Token= args[
"token"].AsString();
1578 throwstd::runtime_error(
"Syntax error: Please specify token argument in the command line or via $NCBI_APPLOG_TOKEN");
1581 if(
cmd==
"parse_token") {
1591 if(args.
Exist(
"timestamp")) {
1592timestamp = args[
"timestamp"].AsString();
1594 if(timestamp.empty() &&
cmd==
"url") {
1596timestamp = args[
"maxtime"].AsString();
1598 if( !timestamp.empty() ) {
1600 if(timestamp.length() == 19 && timestamp.find(
"T") !=
NPOS) {
1604 else if(timestamp.length() == 17 && timestamp.find(
"/") !=
NPOS) {
1614 if(
cmd==
"url") {
1618 if(args[
"std"]) {
1625 if(args[
"appname"]) {
1629 if(args[
"host"]) {
1632 if(args[
"pid"]) {
1636 if(args[
"sid"]) {
1639 if(args[
"phid"]) {
1656 stringtimespan = args[
"maxtime-delay"].AsString();
1657 if(!timespan.empty()) {
1670 string mode= args[
"mode"].AsString();
1671 if(
mode==
"redirect") {
1674 if(
mode==
"cgi") {
1697is_api_init =
true;
1700-- GUID approach
forlogfile
names 1710 if(!logfile.empty()) {
1720 throwstd::runtime_error(
"Failed to set output destination from $NCBI_CONFIG__LOG__FILE");
1726 if(dst_str.empty() || dst_str ==
"default") {
1732is_api_init =
false;
1736 throwstd::runtime_error(
"/log is not writable for CGI logger");
1741 if(dst_str ==
"file") {
1748 throwstd::runtime_error(
"Failed to set output destination to file '"+ path +
"'");
1752 if(dst_str ==
"stdlog") {
1755 if(dst_str ==
"cwd") {
1758 if(dst_str ==
"stdout") {
1761 if(dst_str ==
"stderr") {
1764 throwstd::runtime_error(
"Syntax error: NcbiApplogDestination parameter have incorrect value "+ dst_str);
1769 if(cur_dst != dst) {
1770 throwstd::runtime_error(
"Failed to set output destination to "+ dst_str);
1783 if(
cmd==
"start_app") {
1785 m_Info.
pid= args[
"pid"].AsInteger();
1821 if(
cmd==
"stop_app") {
1822 intstatus = args[
"status"].AsInteger();
1823 doubleexectime = 0;
1824 if(args[
"exectime"].
HasValue()) {
1825exectime = args[
"exectime"].AsDouble();
1834 if(
cmd==
"start_request") {
1837 m_Info.
rid= args[
"rid"].AsInteger();
1845 stringparams = args[
"param"].AsString();
1853 if(params.empty()) {
1856params = extra +
"&"+ params;
1867 if(
cmd==
"stop_request") {
1870 throwstd::runtime_error(
"Token string has wrong format (request token type expected)");
1872 intstatus = args[
"status"].AsInteger();
1873 intn_read = args[
"input"].AsInteger();
1874 intn_write = args[
"output"].AsInteger();
1882 if(
cmd==
"post") {
1883 stringsev = args[
"severity"].AsString();
1884 string msg= args[
"message"].AsString();
1885 boolnote = args[
"note"].AsBoolean();
1891 if(sev ==
"trace") {
1899 else if(sev ==
"info") {
1907 else if(sev ==
"warning") {
1915 else if(sev ==
"error") {
1923 else if(sev ==
"critical") {
1937 if(
cmd==
"extra") {
1939 stringparams = args[
"param"].AsString();
1947 if(
cmd==
"perf") {
1948 intstatus = args[
"status"].AsInteger();
1949 doublets = args[
"time"].AsDouble();
1950 stringparams = args[
"param"].AsString();
1958 if(params.empty()) {
1961params = extra +
"&"+ params;
1981 stringapp, orig_appname;
1982 size_tnamepos, namelen;
1984orig_appname =
"orig_appname="+ app;
2002ECmdType cmd_type = eCmdOther;
2004cmd_type = eCmdAppStart;
2006cmd_type = eCmdRequestStart;
2008cmd_type = eCmdPerf;
2010 size_tparam_ofs = 0;
2019 if(ppos && ppos[0] && ppos[1]) {
2020param_ofs = ppos[1] + 1;
2024 throwstd::runtime_error(
"Error processing input raw log, perf line has wrong format");
2029 caseeCmdRequestStart:
2032 size_tpos = parampos + param_ofs;
2034 if( params.empty() ) {
2035params = orig_appname;
2037params = orig_appname +
"&"+ params;
2039 strings =
m_Raw_line.substr(0, pos) + params;
2048 if(cmd_type == eCmdAppStart) {
2052+
"extra "+ orig_appname;
2054 size_tpos = s.find(
"/PB ");
2056 throwstd::runtime_error(
"Error processing input raw log, starting line has a wrong format");
2090 catch(std::exception
const& e) {
2103 int main(
intargc,
const char* argv[])
CCommandArgDescriptions â.
This stream exchanges data with an HTTP server located at the URL: http[s]://host[:port]/path[?...
int ReadCgiResponse(CConn_HttpStream &cgi)
Read and check CGI response.
string m_Token
Current token.
int PrintTokenInformation(ETokenType type)
Print requested token information to stdout.
virtual int Run()
Run the application.
bool m_IsRemoteLogging
TRUE if mode == "cgi".
void SetInfo()
Set C Logging API information from m_Info.
string GenerateToken(ETokenType type) const
Generate token on the base of current logging information.
void GetRawAppName(CRegexp &re, string *appname, size_t *pos=nullptr, size_t *len=nullptr)
void UpdateInfo()
Update information in the m_Info from C Logging API.
int Redirect()
Redirect logging request to to another machine via CGI.
ETokenType ParseToken()
Parse m_Token and fill logging information in m_Info.
SInfo m_Info
Logging information.
void Error(const string &msg)
Print error message.
virtual void Init()
Initialize the application.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
CTimeout â Timeout interval.
void Print(const CCompactSAMApplication::AlignInfo &ai)
static const struct name_t names[]
static SQLCHAR output[256]
#define poll(fds, nfds, timeout)
static const char location[]
void reset(element_type *p=0, EOwnership ownership=eTakeOwnership)
Reset will delete the old pointer (if owned), set content to the new value, and assume the ownership ...
const CNcbiEnvironment & GetEnvironment(void) const
Get the application's cached environment.
const string & GetProgramExecutablePath(EFollowLinks follow_links=eIgnoreLinks) const
Get the application's executable path.
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
CVersionInfo GetVersion(void) const
Get the program version information.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
void DisableArgDescriptions(TDisableArgDesc disable=fDisableStdArgs)
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ fDisableStdArgs
(-logfile, -conffile, -version etc)
bool Exist(const string &name) const
Check existence of argument description.
string GetCommand(void) const
Get current command.
@ fHidden
Hide it in Usage.
@ eExcludes
One argument excludes another.
@ eNoSortCommands
On PrintUsage, keep commands unsorted.
@ eCommandMandatory
Nonempty command is required.
@ eDouble
Convertible into a floating point number (double)
@ eString
An arbitrary string.
@ eInteger
Convertible into an integer number (int or Int8)
int GetStatusCode(void) const
Get the last seen HTTP status code, if available.
@ fHTTP_NoAutomagicSID
Do not add NCBI SID automagically.
@ fHTTP_Flushable
Connector will really flush on Flush()
ENcbiLog_Destination NcbiLog_SetDestinationFile(const char *logfile_base)
Variant of NcbiLog_SetDestination for logging to a specific file (eNcbiLog_File).
void NcbiLog_AppSetSession(const char *session)
Set session ID (SID) for the whole application.
void NcbiLog_Info(const char *msg)
Writes a message to the <appname>.trace file at level 'INFO'.
const char * NcbiLog_GetHostRole(void)
Get host role.
void NcbiLog_SetHitID(const char *hit_id)
Set hit ID (HID, a.k.a.
const char * NcbiLog_GetHostName(void)
Get host name.
void NcbiLog_Error(const char *msg)
Writes a message to the <appname>.err log at level 'ERROR'.
void NcbiLog_InitST(const char *appname)
Version of NcbiLog_Init to use in single-threaded applications.
ENcbiLog_AppState
Application execution states shown in the std prefix.
TNcbiLog_UInt8 TNcbiLog_Counter
void NcbiLog_SetHost(const char *host)
Set the host name.
ENcbiLog_Destination
Where to write the application's diagnostics to.
ENcbiLog_Severity NcbiLog_SetPostLevel(ENcbiLog_Severity sev)
Set new posting severity threshold.
void NcbiLog_Destroy(void)
Destroy NcbiLog API.
TNcbiLog_UInt8 TNcbiLog_PID
Process, thread and counter types.
void NcbiLog_AppStart(const char *argv[])
Should be called as soon as possible during application initialization.
void NcbiLog_ReqStop(int status, size_t bytes_rd, size_t bytes_wr)
Should be called once request processing is complete.
void NcbiLog_SetSplitLogFile(int value)
Set split log files flag.
unsigned __int64 TNcbiLog_UInt8
void NcbiLog_SetClient(const char *client)
Set client for the request.
void NcbiLog_Warning(const char *msg)
Writes a message to the <appname>.err log at level 'WARNING'.
void NcbiLog_Critical(const char *msg)
Writes a message to the <appname>.err log at level 'CRITICAL'.
void NcbiLog_Trace(const char *msg)
Writes a message to the <appname>.trace file at level 'TRACE'.
void NcbiLog_ReqRun(void)
Should be called once request processing initialization is complete.
void NcbiLog_AppRun(void)
Should be called after the application is initialized and before its main part.
__int64 TNcbiLog_Int8
Big integer type.
const char * NcbiLog_GetHostLocation(void)
Get host location.
void SetDiagStream(CNcbiOstream *os, bool quick_flush=true, FDiagCleanup cleanup=0, void *cleanup_data=0, const string &stream_name="")
Set diagnostic stream.
void NcbiLog_Note(ENcbiLog_Severity sev, const char *msg)
Writes a message using "Note[X]" notation for severity.
void NcbiLog_SetSession(const char *session)
Set session ID (SID) for the request.
@ eDS_Disable
Don't write it anywhere.
@ eNcbiLog_NotSet
Reserved value, never used in messages.
@ eNcbiLog_Stdlog
Try /log/<*>/<appname>.log; fallback to .
@ eNcbiLog_File
To specific file, see NcbiLog_SetDestinationFile()
@ eNcbiLog_Stderr
To standard error stream.
@ eNcbiLog_Stdout
To standard output stream.
@ eNcbiLog_Default
Try /log/<*>/<appname>.log; fallback to STDERR.
@ eNcbiLog_Info
Informational message.
@ eNcbiLog_Warning
Warning message.
@ eNcbiLog_Trace
Trace message.
@ eNcbiLog_Error
Error message.
@ eNcbiLog_Critical
Critical error message.
const string & Get(const string &name, bool *found=NULL) const
Get environment value by name.
SIZE_TYPE Size(void) const
Get size (number) of arguments.
#define NCBI_PARAM_TYPE(section, name)
Generate typename for a parameter from its {section, name} attributes.
@ eParam_NoThread
Do not use per-thread values.
int64_t Int8
8-byte (64-bit) signed integer
uint64_t Uint8
8-byte (64-bit) unsigned integer
const TOffset * GetResults(size_t idx) const
Get location of pattern/subpattern for the last GetMatch().
bool IsMatch(CTempString str, TMatch flags=fMatch_default)
Check existence substring which match a specified pattern.
IRWRegistry * Read(CNcbiIstream &is, TFlags flags=0, const string &path=kEmptyStr)
Read and parse the stream "is", and merge its content with current Registry entries.
virtual string GetString(const string §ion, const string &name, const string &default_value, TFlags flags=0) const
Get the parameter string value.
bool Write(CNcbiOstream &os, TFlags flags=0) const
Write the registry content to output stream.
bool Set(const string §ion, const string &name, const string &value, TFlags flags=0, const string &comment=kEmptyStr)
Set the configuration parameter value.
CNcbiIstream & NcbiGetlineEOL(CNcbiIstream &is, string &str, string::size_type *count=NULL)
Read from "is" to "str" the next line (taking into account platform specifics of End-of-Line)
IO_PREFIX::istream CNcbiIstream
Portable alias for istream.
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
static const string BoolToString(bool value)
Convert bool to string.
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
static unsigned long StringToULong(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned long.
static string & Replace(const string &src, const string &search, const string &replace, string &dst, SIZE_TYPE start_pos=0, SIZE_TYPE max_replace=0, SIZE_TYPE *num_replace=0)
Replace occurrences of a substring within a string.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static bool StartsWith(const CTempString str, const CTempString start, ECase use_case=eCase)
Check if a string starts with a specified prefix value.
static Uint8 StringToUInt8(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to Uint8.
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
static string ULongToString(unsigned long value, TNumToStringFlags flags=0, int base=10)
Convert unsigned long to string.
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
static string Sanitize(CTempString str, TSS_Flags flags=fSS_print)
Sanitize a string, allowing only specified classes of characters.
static string URLEncode(const CTempString str, EUrlEncode flag=eUrlEnc_SkipMarkChars)
URL-encode string.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string.
static string & ToLower(string &str)
Convert string to lower case â string& version.
static string UInt8ToString(Uint8 value, TNumToStringFlags flags=0, int base=10)
Convert UInt8 to string.
@ fSS_cntrl
Check on iscntrl()
@ fSS_Reject
Reject specified characters, allow all other.
@ fSS_Remove
Remove (rather than replace) rejected chars.
@ fSplit_MergeDelimiters
Merge adjacent delimiters.
CTime & SetCurrent(void)
Make the time current in the presently active time zone.
CTimeSpan & AssignFromSmartString(const string &str)
Assign value to time span object from string representation of time in formats produced by AsSmartStr...
time_t GetTimeT(void) const
Get time in time_t format.
unsigned long GetAsMilliSeconds(void) const
Get as number of milliseconds.
void Set(EType type)
Set special value.
CTime & SetTimeT(const time_t t)
Set time using time_t time value.
const long kMicroSecondsPerSecond
Number of microseconds in one second.
const long kNanoSecondsPerSecond
Number of nanoseconds in one second.
static void GetCurrentTimeT(time_t *sec, long *nanosec=0)
Get current UTC time in time_t format (with nanoseconds).
@ eInfinite
Infinite timeout.
string ComposeUrl(void)
Compose URL.
void SetSession(const string &value)
void SetHost(const string &value)
void SetDateTime(const CTime &start, const CTime &end=CTime())
void SetHitID(const string &value)
void SetRequestID(Uint8 value)
void SetProcessID(Uint8 value)
void SetAppName(const string &value)
Setters.
void SetLogsite(const string &value)
virtual string Print(void) const
Print version information.
#define HANDLE
An abstraction for a file handle.
unsigned int
A callback function used to compare two keys in a database.
const TYPE & Get(const CNamedParameterList *param)
constexpr bool empty(list< Ts... >) noexcept
const struct ncbi::grid::netcache::search::fields::KEY key
const GenericPointer< typename T::ValueType > T2 value
NCBI_PARAM_DEF_EX(string, NCBI, NcbiApplogCGI, kDefaultCGI, eParam_NoThread, NCBI_CONFIG__NCBIAPPLOG_CGI)
const char * kDefaultCGI
Default CGI used by default if /log directory is not writable on current machine.
static bool s_PeekStdin(const CTimeout &timeout)
Wait for data in stdin with a timeout.
const char * kPerfRegexp
Regular expression to check perf message and get position of performance parameters perf <exit_code> ...
const char * kErrorMessagePrefix
Prefix for ncbi_applog error messages. ALl error messages going to stderr.
const char * kApplogRegexp
Regular expression to check lines of raw logs (checks all fields up to appname).
int main(int argc, const char *argv[])
const unsigned int kParamsOffset
Parameters offset after the end of the application name.
NCBI_PARAM_DECL(string, NCBI, NcbiApplogCGI)
Declare the parameter for logging CGI.
Defines classes: CApplogUrl â compose Applog URL.
TNcbiLog_Context NcbiLogP_GetContextPtr(void)
int NcbiLogP_DisableChecks(int disable)
Enable/disable internal checks (enabled by default) Used by ncbi_applog.
const char * NcbiLogP_GetHitID_Env(void)
This routine is called during start up and again in NcbiLog_ReqStart().
const char * NcbiLogP_GenerateHitID(char *buf, size_t n, TNcbiLog_UInt8 uid)
Generate new Hit ID string.
const char * NcbiLogP_GenerateSID(char *buf, size_t n, TNcbiLog_UInt8 uid)
Generate new SID string.
ENcbiLog_Destination NcbiLogP_SetDestination(ENcbiLog_Destination ds, unsigned int port, const char *logsite)
Variant of NcbiLog_SetDestination.
void NcbiLogP_ReqStartStr(const char *params)
Variant of NcbiLog_ReqStart, that use already prepared string with parameters.
TNcbiLog_Info * NcbiLogP_GetInfoPtr(void)
void NcbiLogP_AppStop(int exit_status, int exit_signal, double execution_time)
Should be called immediately prior to the application exit.
TNcbiLog_UInt8 NcbiLogP_GenerateUID(void)
Generate new unique process ID.
void NcbiLogP_ExtraStr(const char *params)
Variant of NcbiLog_Extra, that use already prepared string with parameters.
const char * NcbiLogP_GetSessionID_Env(void)
This routine is called during start up and again in NcbiLog_ReqStart().
void NcbiLogP_PerfStr(int status, double timespan, const char *params)
Variant of NcbiLog_Perf, that use already prepared string with parameters.
void NcbiLogP_Raw2(const char *line, size_t len)
Variant of NcbiLogP_Raw with already known line size to avoid double length calculation.
#define NCBILOG_HITID_MAX
#define NCBILOG_ENTRY_MIN
#define NCBILOG_SESSION_MAX
const unsigned long kWaitPrecision
void SleepMilliSec(unsigned long ml_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines unified interface to application:
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
std::istream & in(std::istream &in_, double &x_)
static PCRE2_SIZE bufsize
static SLJIT_INLINE sljit_ins msg(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Application access log and error postings info structure (global).
TNcbiLog_Counter rid
Request ID (e.g.
const char * host_location
Host location (NULL if unknown or not set)
const char * host_role
Host role (NULL if unknown or not set)
TNcbiLog_PID pid
Process ID.
int remote_logging
1 if logging request is going from remote host
ENcbiLog_AppState state
Application state.
int phid_inherit
1 if PHID set explicitly and should be inherited (by requests)
char host[256+1]
Name of the host where the process runs (UNK_HOST if unknown)
int user_posting_time
If 1 use post_time as is, and never change it.
TNcbiLog_Counter psn
Serial number of the posting within the process.
char phid[3 *1024+1]
App-wide hit ID (empty string if unknown)
TNcbiLog_UInt8 guid
Globally unique process ID.
char session[3 *256+1]
App-wide session ID (UNK_SESSION if unknown)
STime app_start_time
Application start time.
STime post_time
GMT time at which the message was posted, use current time if it is not specified (equal to 0)
Structure to store logging information All string values stored URL-encoded.
string appname
Name of the application (UNK_APP if unknown)
string sid_app
Application-wide session ID (set in "start_app")
string host
Name of the host where the process runs.
string logsite
Application-wide LogSite value (set in "start_app")
string host_location
Host location (CGI mode only, ignored for local host)
unsigned int server_port
Value of $SERVER_PORT environment variable.
string sid_req
Request session ID (UNK_SESSION if unknown)
STime req_start_time
Request start time.
string phid_app
Application-wide hit ID (set in "start_app")
string phid_req
Request hit ID (set in "req_app")
TNcbiLog_PID pid
Process ID.
string host_role
Host role (CGI mode only, ignored for local host)
TNcbiLog_Int8 guid
Globally unique process ID.
STime app_start_time
Application start time.
STime post_time
Posting time (if differs from the current time)
ENcbiLog_AppState state
Assumed 'state' for Logging API.
string client
Client IP address (UNK_CLIENT if unknown)
TNcbiLog_Counter rid
Request ID (0 if not directly specified)
Thread-specific context data.
STime req_start_time
Request start time.
char client[256+1]
Request specific client IP address.
TNcbiLog_Counter tsn
Serial number of the posting within the thread.
TNcbiLog_Counter rid
Request ID (e.g.
TNcbiLog_TID tid
Thread ID.
char session[3 *256+1]
Request specific session ID.
Application access log and error postings info structure.
unsigned long ns
Nanosecond part of the time.
C++ wrappers for the Perl-compatible regular expression (PCRE) library.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4