nghttpx: Accept reference instead of pointer by upstream_accesslog

This commit is contained in:
Tatsuhiro Tsujikawa 2015-05-04 22:45:34 +09:00
parent cc46d363c5
commit 1ab707713f
3 changed files with 48 additions and 48 deletions

View File

@ -691,7 +691,9 @@ void ClientHandler::start_immediate_shutdown() {
}
void ClientHandler::write_accesslog(Downstream *downstream) {
LogSpec lgsp = {
upstream_accesslog(
get_config()->accesslog_format,
LogSpec{
downstream, ipaddr_.c_str(), downstream->get_request_method().c_str(),
downstream->get_request_path().empty()
@ -708,9 +710,7 @@ void ClientHandler::write_accesslog(Downstream *downstream) {
downstream->get_response_http_status(),
downstream->get_response_sent_bodylen(), port_.c_str(),
get_config()->port, get_config()->pid,
};
upstream_accesslog(get_config()->accesslog_format, &lgsp);
});
}
void ClientHandler::write_accesslog(int major, int minor, unsigned int status,
@ -718,7 +718,8 @@ void ClientHandler::write_accesslog(int major, int minor, unsigned int status,
auto time_now = std::chrono::system_clock::now();
auto highres_now = std::chrono::high_resolution_clock::now();
LogSpec lgsp = {
upstream_accesslog(get_config()->accesslog_format,
LogSpec{
nullptr, ipaddr_.c_str(),
"-", // method
"-", // path,
@ -729,9 +730,7 @@ void ClientHandler::write_accesslog(int major, int minor, unsigned int status,
major, minor, // major, minor
status, body_bytes_sent, port_.c_str(),
get_config()->port, get_config()->pid,
};
upstream_accesslog(get_config()->accesslog_format, &lgsp);
});
}
ClientHandler::WriteBuf *ClientHandler::get_wb() { return &wb_; }

View File

@ -158,7 +158,8 @@ std::pair<OutputIterator, size_t> copy(const char *src, size_t avail,
}
} // namespace
void upstream_accesslog(const std::vector<LogFragment> &lfv, LogSpec *lgsp) {
void upstream_accesslog(const std::vector<LogFragment> &lfv,
const LogSpec &lgsp) {
auto lgconf = log_config();
if (lgconf->accesslog_fd == -1 && !get_config()->accesslog_syslog) {
@ -167,12 +168,12 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, LogSpec *lgsp) {
char buf[4096];
auto downstream = lgsp->downstream;
auto downstream = lgsp.downstream;
auto p = buf;
auto avail = sizeof(buf) - 2;
lgconf->update_tstamp(lgsp->time_now);
lgconf->update_tstamp(lgsp.time_now);
auto &time_local = lgconf->time_local_str;
auto &time_iso8601 = lgconf->time_iso8601_str;
@ -182,7 +183,7 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, LogSpec *lgsp) {
std::tie(p, avail) = copy(lf.value.get(), avail, p);
break;
case SHRPX_LOGF_REMOTE_ADDR:
std::tie(p, avail) = copy(lgsp->remote_addr, avail, p);
std::tie(p, avail) = copy(lgsp.remote_addr, avail, p);
break;
case SHRPX_LOGF_TIME_LOCAL:
std::tie(p, avail) = copy(time_local.c_str(), avail, p);
@ -191,22 +192,22 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, LogSpec *lgsp) {
std::tie(p, avail) = copy(time_iso8601.c_str(), avail, p);
break;
case SHRPX_LOGF_REQUEST:
std::tie(p, avail) = copy(lgsp->method, avail, p);
std::tie(p, avail) = copy(lgsp.method, avail, p);
std::tie(p, avail) = copy(" ", avail, p);
std::tie(p, avail) = copy(lgsp->path, avail, p);
std::tie(p, avail) = copy(lgsp.path, avail, p);
std::tie(p, avail) = copy(" HTTP/", avail, p);
std::tie(p, avail) = copy(util::utos(lgsp->major).c_str(), avail, p);
if (lgsp->major < 2) {
std::tie(p, avail) = copy(util::utos(lgsp.major).c_str(), avail, p);
if (lgsp.major < 2) {
std::tie(p, avail) = copy(".", avail, p);
std::tie(p, avail) = copy(util::utos(lgsp->minor).c_str(), avail, p);
std::tie(p, avail) = copy(util::utos(lgsp.minor).c_str(), avail, p);
}
break;
case SHRPX_LOGF_STATUS:
std::tie(p, avail) = copy(util::utos(lgsp->status).c_str(), avail, p);
std::tie(p, avail) = copy(util::utos(lgsp.status).c_str(), avail, p);
break;
case SHRPX_LOGF_BODY_BYTES_SENT:
std::tie(p, avail) =
copy(util::utos(lgsp->body_bytes_sent).c_str(), avail, p);
copy(util::utos(lgsp.body_bytes_sent).c_str(), avail, p);
break;
case SHRPX_LOGF_HTTP:
if (downstream) {
@ -221,15 +222,14 @@ void upstream_accesslog(const std::vector<LogFragment> &lfv, LogSpec *lgsp) {
break;
case SHRPX_LOGF_REMOTE_PORT:
std::tie(p, avail) = copy(lgsp->remote_port, avail, p);
std::tie(p, avail) = copy(lgsp.remote_port, avail, p);
break;
case SHRPX_LOGF_SERVER_PORT:
std::tie(p, avail) =
copy(util::utos(lgsp->server_port).c_str(), avail, p);
std::tie(p, avail) = copy(util::utos(lgsp.server_port).c_str(), avail, p);
break;
case SHRPX_LOGF_REQUEST_TIME: {
auto t = std::chrono::duration_cast<std::chrono::milliseconds>(
lgsp->request_end_time - lgsp->request_start_time).count();
lgsp.request_end_time - lgsp.request_start_time).count();
auto frac = util::utos(t % 1000);
auto sec = util::utos(t / 1000);
@ -242,10 +242,10 @@ 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);
std::tie(p, avail) = copy(util::utos(lgsp.pid).c_str(), avail, p);
break;
case SHRPX_LOGF_ALPN:
std::tie(p, avail) = copy(lgsp->alpn, avail, p);
std::tie(p, avail) = copy(lgsp.alpn, avail, p);
break;
case SHRPX_LOGF_NONE:
break;

View File

@ -139,7 +139,8 @@ struct LogSpec {
pid_t pid;
};
void upstream_accesslog(const std::vector<LogFragment> &lf, LogSpec *lgsp);
void upstream_accesslog(const std::vector<LogFragment> &lf,
const LogSpec &lgsp);
int reopen_log_files();