shrpx: Don't run expensive INFO log code

INFO log and its surrounding code are now guarded by
LOG_ENABLED(SEVERITY) macro so that they don't run if log level
threshold is higher. This increases performance because log formatting
is somewhat expensive.
This commit is contained in:
Tatsuhiro Tsujikawa 2013-01-21 22:42:49 +09:00
parent 5adfd07e7c
commit 29bec93eb9
12 changed files with 102 additions and 89 deletions

View File

@ -105,10 +105,12 @@ int cache_downstream_host_address()
rv = getnameinfo(res->ai_addr, res->ai_addrlen, host, sizeof(host),
0, 0, NI_NUMERICHOST);
if(rv == 0) {
LOG(INFO) << "Using first returned address for downstream "
<< host
<< ", port "
<< get_config()->downstream_port;
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Using first returned address for downstream "
<< host
<< ", port "
<< get_config()->downstream_port;
}
} else {
LOG(FATAL) << gai_strerror(rv);
DIE();
@ -147,9 +149,11 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
addrinfo *res, *rp;
r = getaddrinfo(get_config()->host, service, &hints, &res);
if(r != 0) {
LOG(INFO) << "Unable to get IPv" << (family == AF_INET ? "4" : "6")
<< " address for " << get_config()->host << ": "
<< gai_strerror(r);
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Unable to get IPv" << (family == AF_INET ? "4" : "6")
<< " address for " << get_config()->host << ": "
<< gai_strerror(r);
}
return NULL;
}
for(rp = res; rp; rp = rp->ai_next) {
@ -183,7 +187,10 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
r = getnameinfo(rp->ai_addr, rp->ai_addrlen, host, sizeof(host),
0, 0, NI_NUMERICHOST);
if(r == 0) {
LOG(INFO) << "Listening on " << host << ", port " << get_config()->port;
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Listening on " << host << ", port "
<< get_config()->port;
}
} else {
LOG(FATAL) << gai_strerror(r);
DIE();
@ -191,7 +198,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
}
freeaddrinfo(res);
if(rp == 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Listening " << (family == AF_INET ? "IPv4" : "IPv6")
<< " socket failed";
}
@ -263,7 +270,7 @@ int event_loop()
listener_handler->create_spdy_session();
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
LOG(INFO) << "Entering event loop";
}
event_base_loop(evbase, 0);

View File

@ -76,13 +76,13 @@ void upstream_eventcb(bufferevent *bev, short events, void *arg)
ClientHandler *handler = reinterpret_cast<ClientHandler*>(arg);
bool finish = false;
if(events & BEV_EVENT_EOF) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, handler) << "EOF";
}
finish = true;
}
if(events & BEV_EVENT_ERROR) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, handler) << "Network error: "
<< evutil_socket_error_to_string
(EVUTIL_SOCKET_ERROR());
@ -90,7 +90,7 @@ void upstream_eventcb(bufferevent *bev, short events, void *arg)
finish = true;
}
if(events & BEV_EVENT_TIMEOUT) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, handler) << "Time out";
}
finish = true;
@ -99,12 +99,12 @@ void upstream_eventcb(bufferevent *bev, short events, void *arg)
delete handler;
} else {
if(events & BEV_EVENT_CONNECTED) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, handler) << "SSL/TLS handleshake completed";
}
handler->set_bev_cb(upstream_readcb, upstream_writecb, upstream_eventcb);
handler->validate_next_proto();
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
if(SSL_session_reused(handler->get_ssl())) {
CLOG(INFO, handler) << "SSL/TLS session reused";
}
@ -143,7 +143,7 @@ ClientHandler::ClientHandler(bufferevent *bev, int fd, SSL *ssl,
ClientHandler::~ClientHandler()
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Deleting";
}
if(ssl_) {
@ -161,7 +161,7 @@ ClientHandler::~ClientHandler()
i != dconn_pool_.end(); ++i) {
delete *i;
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Deleted";
}
}
@ -200,7 +200,7 @@ int ClientHandler::validate_next_proto()
unsigned int next_proto_len;
SSL_get0_next_proto_negotiated(ssl_, &next_proto, &next_proto_len);
if(next_proto) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::string proto(next_proto, next_proto+next_proto_len);
CLOG(INFO, this) << "The negotiated next protocol: " << proto;
}
@ -211,11 +211,11 @@ int ClientHandler::validate_next_proto()
return 0;
}
} else {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "No proto negotiated.";
}
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Use HTTP/1.1";
}
HttpsUpstream *https_upstream = new HttpsUpstream(this);
@ -250,7 +250,7 @@ void ClientHandler::set_should_close_after_write(bool f)
void ClientHandler::pool_downstream_connection(DownstreamConnection *dconn)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Pooling downstream connection DCONN:" << dconn;
}
dconn_pool_.insert(dconn);
@ -258,7 +258,7 @@ void ClientHandler::pool_downstream_connection(DownstreamConnection *dconn)
void ClientHandler::remove_downstream_connection(DownstreamConnection *dconn)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Removing downstream connection DCONN:" << dconn
<< " from pool";
}
@ -268,7 +268,7 @@ void ClientHandler::remove_downstream_connection(DownstreamConnection *dconn)
DownstreamConnection* ClientHandler::get_downstream_connection()
{
if(dconn_pool_.empty()) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Downstream connection pool is empty."
<< " Create new one";
}
@ -280,7 +280,7 @@ DownstreamConnection* ClientHandler::get_downstream_connection()
} else {
DownstreamConnection *dconn = *dconn_pool_.begin();
dconn_pool_.erase(dconn);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
CLOG(INFO, this) << "Reuse downstream connection DCONN:" << dconn
<< " from pool";
}

View File

@ -63,7 +63,7 @@ Downstream::Downstream(Upstream *upstream, int stream_id, int priority)
Downstream::~Downstream()
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, this) << "Deleting";
}
if(response_body_buf_) {
@ -73,7 +73,7 @@ Downstream::~Downstream()
if(dconn_) {
delete dconn_;
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, this) << "Deleted";
}
}

View File

@ -66,7 +66,7 @@ HttpDownstreamConnection::~HttpDownstreamConnection()
int HttpDownstreamConnection::attach_downstream(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Attaching to DOWNSTREAM:" << downstream;
}
Upstream *upstream = downstream->get_upstream();
@ -85,7 +85,7 @@ int HttpDownstreamConnection::attach_downstream(Downstream *downstream)
bev_ = 0;
return SHRPX_ERR_NETWORK;
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Connecting to downstream server";
}
}
@ -184,7 +184,7 @@ int HttpDownstreamConnection::push_request_headers()
}
hdrs += "\r\n";
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
const char *hdrp;
std::string nhdrs;
if(get_config()->tty) {
@ -272,21 +272,21 @@ void idle_eventcb(bufferevent *bev, short events, void *arg)
if(events & BEV_EVENT_CONNECTED) {
// Downstream was detached before connection established?
// This may be safe to be left.
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Idle connection connected?";
}
return;
}
if(events & BEV_EVENT_EOF) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Idle connection EOF";
}
} else if(events & BEV_EVENT_TIMEOUT) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Idle connection timeout";
}
} else if(events & BEV_EVENT_ERROR) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Idle connection network error";
}
}
@ -298,7 +298,7 @@ void idle_eventcb(bufferevent *bev, short events, void *arg)
void HttpDownstreamConnection::detach_downstream(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Detaching from DOWNSTREAM:" << downstream;
}
downstream->set_downstream_connection(0);
@ -443,7 +443,7 @@ int HttpDownstreamConnection::on_read()
if(htperr == HPE_OK) {
return 0;
} else {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "HTTP parser failure: "
<< "(" << http_errno_name(htperr) << ") "
<< http_errno_description(htperr);

View File

@ -74,7 +74,7 @@ int htp_msg_begin(http_parser *htp)
{
HttpsUpstream *upstream;
upstream = reinterpret_cast<HttpsUpstream*>(htp->data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "HTTP request started";
}
upstream->reset_current_header_length();
@ -131,7 +131,7 @@ int htp_hdrs_completecb(http_parser *htp)
int rv;
HttpsUpstream *upstream;
upstream = reinterpret_cast<HttpsUpstream*>(htp->data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "HTTP request headers completed";
}
Downstream *downstream = upstream->get_downstream();
@ -142,7 +142,7 @@ int htp_hdrs_completecb(http_parser *htp)
downstream->set_request_connection_close(!http_should_keep_alive(htp));
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::stringstream ss;
ss << downstream->get_request_method() << " "
<< downstream->get_request_path() << " "
@ -222,7 +222,7 @@ int htp_msg_completecb(http_parser *htp)
int rv;
HttpsUpstream *upstream;
upstream = reinterpret_cast<HttpsUpstream*>(htp->data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "HTTP request completed";
}
Downstream *downstream = upstream->get_downstream();
@ -306,14 +306,14 @@ int HttpsUpstream::on_read()
return -1;
}
} else if(downstream->get_output_buffer_full()) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, this) << "Downstream output buffer is full";
}
pause_read(SHRPX_NO_BUFFER);
}
}
} else {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, this) << "HTTP parse failure: "
<< "(" << http_errno_name(htperr) << ") "
<< http_errno_description(htperr);
@ -454,16 +454,16 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
HttpsUpstream *upstream;
upstream = static_cast<HttpsUpstream*>(downstream->get_upstream());
if(events & BEV_EVENT_CONNECTED) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Connection established";
}
} else if(events & BEV_EVENT_EOF) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "EOF";
}
if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) {
// Server may indicate the end of the request by EOF
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "The end of the response body was indicated by "
<< "EOF";
}
@ -483,7 +483,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
// Nothing to do
} else {
// error
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Treated as error";
}
if(upstream->error_reply(502) != 0) {
@ -496,7 +496,7 @@ void https_downstream_eventcb(bufferevent *bev, short events, void *ptr)
upstream->resume_read(SHRPX_MSG_BLOCK);
}
} else if(events & (BEV_EVENT_ERROR | BEV_EVENT_TIMEOUT)) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
if(events & BEV_EVENT_ERROR) {
DCLOG(INFO, dconn) << "Network error";
} else {
@ -590,7 +590,7 @@ Downstream* HttpsUpstream::get_downstream() const
int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response header completed";
}
std::string via_value;
@ -643,7 +643,7 @@ int HttpsUpstream::on_downstream_header_complete(Downstream *downstream)
}
hdrs += "\r\n";
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
const char *hdrp;
std::string nhdrs;
if(get_config()->tty) {
@ -696,7 +696,7 @@ int HttpsUpstream::on_downstream_body_complete(Downstream *downstream)
return -1;
}
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response completed";
}
if(downstream->get_request_connection_close() ||

View File

@ -81,7 +81,7 @@ void ListenHandler::create_worker_thread(size_t num)
bufferevent *bev = bufferevent_socket_new(evbase_, info->sv[0],
BEV_OPT_DEFER_CALLBACKS);
info->bev = bev;
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
LLOG(INFO, this) << "Created thread #" << num_worker_;
}
++num_worker_;
@ -91,7 +91,7 @@ void ListenHandler::create_worker_thread(size_t num)
int ListenHandler::accept_connection(evutil_socket_t fd,
sockaddr *addr, int addrlen)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
LLOG(INFO, this) << "Accepted connection. fd=" << fd;
}
if(num_worker_ == 0) {

View File

@ -90,7 +90,7 @@ Log::Log(int severity, const char *filename, int linenum)
Log::~Log()
{
if(severity_ >= severity_thres_) {
if(log_enabled(severity_)) {
fprintf(stderr, "[%s%s%s] %s\n %s(%s:%d)%s\n",
get_config()->tty ? SEVERITY_COLOR[severity_] : "",
SEVERITY_STR[severity_],

View File

@ -33,6 +33,8 @@ namespace shrpx {
#define ENABLE_LOG 1
#define LOG_ENABLED(SEVERITY) (ENABLE_LOG && Log::log_enabled(SEVERITY))
#define LOG(SEVERITY) Log(SEVERITY, __FILE__, __LINE__)
// Listener log
@ -81,6 +83,10 @@ public:
}
static void set_severity_level(int severity);
static int set_severity_level_by_name(const char *name);
static bool log_enabled(int severity)
{
return severity >= severity_thres_;
}
private:
int severity_;
const char *filename_;

View File

@ -89,7 +89,7 @@ int SpdyDownstreamConnection::init_request_body_buf()
int SpdyDownstreamConnection::attach_downstream(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Attaching to DOWNSTREAM:" << downstream;
}
if(init_request_body_buf() == -1) {
@ -107,7 +107,7 @@ int SpdyDownstreamConnection::attach_downstream(Downstream *downstream)
void SpdyDownstreamConnection::detach_downstream(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Detaching from DOWNSTREAM:" << downstream;
}
downstream->set_downstream_connection(0);
@ -293,7 +293,7 @@ int SpdyDownstreamConnection::push_request_headers()
nv[hdidx++] = via_value.c_str();
}
nv[hdidx++] = 0;
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::stringstream ss;
for(size_t i = 0; nv[i]; i += 2) {
ss << TTY_HTTP_HD << nv[i] << TTY_RST << ": " << nv[i+1] << "\n";

View File

@ -65,7 +65,7 @@ SpdySession::~SpdySession()
int SpdySession::disconnect()
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "Disconnecting";
}
spdylay_session_del(session_);
@ -217,7 +217,7 @@ void eventcb(bufferevent *bev, short events, void *ptr)
{
SpdySession *spdy = reinterpret_cast<SpdySession*>(ptr);
if(events & BEV_EVENT_CONNECTED) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Connection established";
}
spdy->connected();
@ -231,12 +231,12 @@ void eventcb(bufferevent *bev, short events, void *ptr)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val));
} else if(events & BEV_EVENT_EOF) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "EOF";
}
spdy->disconnect();
} else if(events & (BEV_EVENT_ERROR | BEV_EVENT_TIMEOUT)) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
if(events & BEV_EVENT_ERROR) {
SSLOG(INFO, spdy) << "Network error";
} else {
@ -257,7 +257,7 @@ int SpdySession::initiate_connection()
{
int rv;
assert(state_ == DISCONNECTED);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "Connecting to downstream server";
}
@ -461,7 +461,7 @@ void on_stream_close_callback
{
int rv;
SpdySession *spdy = reinterpret_cast<SpdySession*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Stream stream_id=" << stream_id
<< " is being closed";
}
@ -507,7 +507,7 @@ void on_ctrl_recv_callback
Downstream *downstream;
switch(type) {
case SPDYLAY_SYN_STREAM:
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Received upstream SYN_STREAM stream_id="
<< frame->syn_stream.stream_id;
}
@ -594,7 +594,7 @@ void on_ctrl_recv_callback
}
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::stringstream ss;
for(size_t i = 0; nv[i]; i += 2) {
ss << TTY_HTTP_HD << nv[i] << TTY_RST << ": " << nv[i+1] << "\n";
@ -645,7 +645,7 @@ void on_data_chunk_recv_callback(spdylay_session *session,
if(spdy->get_flow_control()) {
sd->dconn->inc_recv_window_size(len);
if(sd->dconn->get_recv_window_size() > spdy->get_initial_window_size()) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Flow control error: recv_window_size="
<< sd->dconn->get_recv_window_size()
<< ", initial_window_size="
@ -740,7 +740,7 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session,
void *user_data)
{
SpdySession *spdy = reinterpret_cast<SpdySession*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Failed to parse received control frame. type="
<< type
<< ", error_code=" << error_code << ":"
@ -756,7 +756,7 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session,
void *user_data)
{
SpdySession *spdy = reinterpret_cast<SpdySession*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, spdy) << "Received unknown control frame";
}
}
@ -769,7 +769,7 @@ int SpdySession::on_connect()
unsigned int next_proto_len;
SSL_get0_next_proto_negotiated(ssl_, &next_proto, &next_proto_len);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::string proto(next_proto, next_proto+next_proto_len);
SSLOG(INFO, this) << "Negotiated next protocol: " << proto;
}
@ -851,7 +851,7 @@ int SpdySession::on_read()
if(rv == 0) {
if(spdylay_session_want_read(session_) == 0 &&
spdylay_session_want_write(session_) == 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "No more read/write for this session";
}
rv = -1;
@ -875,7 +875,7 @@ int SpdySession::send()
if(rv == 0) {
if(spdylay_session_want_read(session_) == 0 &&
spdylay_session_want_write(session_) == 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
SSLOG(INFO, this) << "No more read/write for this session";
}
rv = -1;

View File

@ -95,7 +95,7 @@ void on_stream_close_callback
void *user_data)
{
SpdyUpstream *upstream = reinterpret_cast<SpdyUpstream*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Stream stream_id=" << stream_id
<< " is being closed";
}
@ -143,7 +143,7 @@ void on_ctrl_recv_callback
SpdyUpstream *upstream = reinterpret_cast<SpdyUpstream*>(user_data);
switch(type) {
case SPDYLAY_SYN_STREAM: {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Received upstream SYN_STREAM stream_id="
<< frame->syn_stream.stream_id;
}
@ -192,7 +192,7 @@ void on_ctrl_recv_callback
downstream->add_request_header("X-Forwarded-Spdy", "true");
}
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::stringstream ss;
for(size_t i = 0; nv[i]; i += 2) {
ss << TTY_HTTP_HD << nv[i] << TTY_RST << ": " << nv[i+1] << "\n";
@ -245,7 +245,7 @@ void on_data_chunk_recv_callback(spdylay_session *session,
downstream->inc_recv_window_size(len);
if(downstream->get_recv_window_size() >
upstream->get_initial_window_size()) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Flow control error: recv_window_size="
<< downstream->get_recv_window_size()
<< ", initial_window_size="
@ -292,7 +292,7 @@ void on_ctrl_recv_parse_error_callback(spdylay_session *session,
void *user_data)
{
SpdyUpstream *upstream = reinterpret_cast<SpdyUpstream*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Failed to parse received control frame. type="
<< type
<< ", error_code=" << error_code << ":"
@ -308,7 +308,7 @@ void on_unknown_ctrl_recv_callback(spdylay_session *session,
void *user_data)
{
SpdyUpstream *upstream = reinterpret_cast<SpdyUpstream*>(user_data);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Received unknown control frame.";
}
}
@ -388,7 +388,7 @@ int SpdyUpstream::on_read()
if(rv == 0) {
if(spdylay_session_want_read(session_) == 0 &&
spdylay_session_want_write(session_) == 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, this) << "No more read/write for this SPDY session";
}
rv = -1;
@ -413,7 +413,7 @@ int SpdyUpstream::send()
if(rv == 0) {
if(spdylay_session_want_read(session_) == 0 &&
spdylay_session_want_write(session_) == 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, this) << "No more read/write for this SPDY session";
}
rv = -1;
@ -449,7 +449,7 @@ void spdy_downstream_readcb(bufferevent *bev, void *ptr)
}
int rv = downstream->on_read();
if(rv != 0) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "HTTP parser failure";
}
if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) {
@ -502,7 +502,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
SpdyUpstream *upstream;
upstream = static_cast<SpdyUpstream*>(downstream->get_upstream());
if(events & BEV_EVENT_CONNECTED) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "Connection established. stream_id="
<< downstream->get_stream_id();
}
@ -511,7 +511,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
reinterpret_cast<char *>(&val), sizeof(val));
} else if(events & BEV_EVENT_EOF) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DCLOG(INFO, dconn) << "EOF. stream_id=" << downstream->get_stream_id();
}
if(downstream->get_request_state() == Downstream::STREAM_CLOSED) {
@ -528,7 +528,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
// downstream wil be deleted in on_stream_close_callback.
if(downstream->get_response_state() == Downstream::HEADER_COMPLETE) {
// Server may indicate the end of the request by EOF
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, upstream) << "Downstream body was ended by EOF";
}
downstream->set_response_state(Downstream::MSG_COMPLETE);
@ -556,7 +556,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
// At this point, downstream may be deleted.
}
} else if(events & (BEV_EVENT_ERROR | BEV_EVENT_TIMEOUT)) {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
if(events & BEV_EVENT_ERROR) {
DCLOG(INFO, dconn) << "Downstream network error: "
<< evutil_socket_error_to_string
@ -609,7 +609,7 @@ void spdy_downstream_eventcb(bufferevent *bev, short events, void *ptr)
int SpdyUpstream::rst_stream(Downstream *downstream, int status_code)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
ULOG(INFO, this) << "RST_STREAM stream_id="
<< downstream->get_stream_id();
}
@ -744,7 +744,7 @@ spdylay_session* SpdyUpstream::get_spdy_session()
// spdylay_session_recv. These calls may delete downstream.
int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response header completed";
}
size_t nheader = downstream->get_response_headers().size();
@ -781,7 +781,7 @@ int SpdyUpstream::on_downstream_header_complete(Downstream *downstream)
nv[hdidx++] = via_value.c_str();
}
nv[hdidx++] = 0;
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
std::stringstream ss;
for(size_t i = 0; nv[i]; i += 2) {
ss << TTY_HTTP_HD << nv[i] << TTY_RST << ": " << nv[i+1] << "\n";
@ -835,7 +835,7 @@ int SpdyUpstream::on_downstream_body(Downstream *downstream,
// spdylay_session_recv. These calls may delete downstream.
int SpdyUpstream::on_downstream_body_complete(Downstream *downstream)
{
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
DLOG(INFO, downstream) << "HTTP response completed";
}
spdylay_session_resume_data(session_, downstream->get_stream_id());

View File

@ -47,7 +47,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
while(evbuffer_get_length(input) >= sizeof(WorkerEvent)) {
WorkerEvent wev;
evbuffer_remove(input, &wev, sizeof(WorkerEvent));
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
TLOG(INFO, this) << "WorkerEvent: client_fd=" << wev.client_fd
<< ", addrlen=" << wev.client_addrlen;
}
@ -59,11 +59,11 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
wev.client_addrlen);
if(client_handler) {
client_handler->set_spdy_session(spdy_);
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
TLOG(INFO, this) << "CLIENT_HANDLER:" << client_handler << " created";
}
} else {
if(ENABLE_LOG) {
if(LOG_ENABLED(INFO)) {
TLOG(ERROR, this) << "ClientHandler creation failed";
}
close(wev.client_fd);