nghttpx: Add $pid to --accesslog-format variable
$pid refers to the PID of the running process.
This commit is contained in:
parent
93023acc6c
commit
1fe50f272b
|
@ -759,6 +759,7 @@ void fill_default_config()
|
|||
mod_config()->pid_file = nullptr;
|
||||
mod_config()->uid = 0;
|
||||
mod_config()->gid = 0;
|
||||
mod_config()->pid = getpid();
|
||||
mod_config()->backend_ipv4 = false;
|
||||
mod_config()->backend_ipv6 = false;
|
||||
mod_config()->cert_tree = nullptr;
|
||||
|
@ -1142,6 +1143,7 @@ Logging:
|
|||
$server_port: server port.
|
||||
$request_time: request processing time in
|
||||
seconds with milliseconds resolution.
|
||||
$pid: PID of the running process.
|
||||
Default: )"
|
||||
<< DEFAULT_ACCESSLOG_FORMAT << R"(
|
||||
--errorlog-file=<PATH>
|
||||
|
|
|
@ -746,7 +746,8 @@ void ClientHandler::write_accesslog(Downstream *downstream)
|
|||
downstream->get_response_http_status(),
|
||||
downstream->get_response_sent_bodylen(),
|
||||
port_.c_str(),
|
||||
get_config()->port
|
||||
get_config()->port,
|
||||
get_config()->pid,
|
||||
};
|
||||
|
||||
upstream_accesslog(get_config()->accesslog_format, &lgsp);
|
||||
|
@ -767,7 +768,8 @@ void ClientHandler::write_accesslog(int major, int minor,
|
|||
status,
|
||||
body_bytes_sent,
|
||||
port_.c_str(),
|
||||
get_config()->port
|
||||
get_config()->port,
|
||||
get_config()->pid,
|
||||
};
|
||||
|
||||
upstream_accesslog(get_config()->accesslog_format, &lgsp);
|
||||
|
|
|
@ -402,6 +402,8 @@ std::vector<LogFragment> parse_log_format(const char *optarg)
|
|||
type = SHRPX_LOGF_SERVER_PORT;
|
||||
} else if(util::strieq("$request_time", var_start, varlen)) {
|
||||
type = SHRPX_LOGF_REQUEST_TIME;
|
||||
} else if(util::strieq("$pid", var_start, varlen)) {
|
||||
type = SHRPX_LOGF_PID;
|
||||
} else {
|
||||
LOG(WARN) << "Unrecognized log format variable: "
|
||||
<< std::string(var_start, varlen);
|
||||
|
|
|
@ -254,6 +254,7 @@ struct Config {
|
|||
int argc;
|
||||
uid_t uid;
|
||||
gid_t gid;
|
||||
pid_t pid;
|
||||
uint16_t port;
|
||||
uint16_t downstream_port;
|
||||
// port in http proxy URI
|
||||
|
|
|
@ -139,7 +139,7 @@ Log::~Log()
|
|||
rv = snprintf(buf, sizeof(buf),
|
||||
"%s PID%d [%s%s%s] %s\n",
|
||||
cached_time->c_str(),
|
||||
getpid(),
|
||||
get_config()->pid,
|
||||
tty ? SEVERITY_COLOR[severity_] : "",
|
||||
SEVERITY_STR[severity_],
|
||||
tty ? "\033[0m" : "",
|
||||
|
@ -148,7 +148,7 @@ Log::~Log()
|
|||
rv = snprintf(buf, sizeof(buf),
|
||||
"%s PID%d [%s%s%s] %s%s:%d%s %s\n",
|
||||
cached_time->c_str(),
|
||||
getpid(),
|
||||
get_config()->pid,
|
||||
tty ? SEVERITY_COLOR[severity_] : "",
|
||||
SEVERITY_STR[severity_],
|
||||
tty ? "\033[0m" : "",
|
||||
|
@ -258,6 +258,9 @@ void upstream_accesslog(const std::vector<LogFragment>& lfv, LogSpec *lgsp)
|
|||
std::tie(p, avail) = copy( sec.c_str(), avail, p);
|
||||
}
|
||||
break;
|
||||
case SHRPX_LOGF_PID:
|
||||
std::tie(p, avail) = copy(util::utos(lgsp->pid).c_str(), avail, p);
|
||||
break;
|
||||
case SHRPX_LOGF_NONE:
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
|
||||
#include "shrpx.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <sstream>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -116,6 +118,7 @@ enum LogFragmentType {
|
|||
SHRPX_LOGF_REMOTE_PORT,
|
||||
SHRPX_LOGF_SERVER_PORT,
|
||||
SHRPX_LOGF_REQUEST_TIME,
|
||||
SHRPX_LOGF_PID,
|
||||
};
|
||||
|
||||
struct LogFragment {
|
||||
|
@ -135,6 +138,7 @@ struct LogSpec {
|
|||
int64_t body_bytes_sent;
|
||||
const char *remote_port;
|
||||
uint16_t server_port;
|
||||
pid_t pid;
|
||||
};
|
||||
|
||||
void upstream_accesslog(const std::vector<LogFragment>& lf, LogSpec *lgsp);
|
||||
|
|
Loading…
Reference in New Issue