Merge branch 'log_notice' of https://github.com/LPardue/nghttp2 into LPardue-log_notice

This commit is contained in:
Tatsuhiro Tsujikawa 2014-11-07 21:15:02 +09:00
commit c410f4055f
5 changed files with 49 additions and 40 deletions

View File

@ -190,9 +190,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
// Otherwise, close fd, and create server socket as usual. // Otherwise, close fd, and create server socket as usual.
if(port == get_config()->port) { if(port == get_config()->port) {
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Listening on port " << get_config()->port;
LOG(INFO) << "Listening on port " << get_config()->port;
}
return new_evlistener(handler, fd); return new_evlistener(handler, fd);
} }
@ -279,9 +277,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
return nullptr; return nullptr;
} }
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Listening on " << host << ", port " << get_config()->port;
LOG(INFO) << "Listening on " << host << ", port " << get_config()->port;
}
return new_evlistener(handler, fd); return new_evlistener(handler, fd);
} }
@ -356,9 +352,7 @@ void exec_binary_signal_cb(evutil_socket_t sig, short events, void *arg)
{ {
auto listener_handler = static_cast<ListenHandler*>(arg); auto listener_handler = static_cast<ListenHandler*>(arg);
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Executing new binary";
LOG(INFO) << "Executing new binary";
}
auto pid = fork(); auto pid = fork();
@ -449,9 +443,7 @@ void graceful_shutdown_signal_cb(evutil_socket_t sig, short events, void *arg)
{ {
auto listener_handler = static_cast<ListenHandler*>(arg); auto listener_handler = static_cast<ListenHandler*>(arg);
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Graceful shutdown signal received";
LOG(INFO) << "Graceful shutdown signal received";
}
worker_config->graceful_shutdown = true; worker_config->graceful_shutdown = true;
@ -1132,8 +1124,8 @@ Mode:
Logging: Logging:
-L, --log-level=<LEVEL> -L, --log-level=<LEVEL>
Set the severity level of log output. <LEVEL> Set the severity level of log output. <LEVEL>
must be one of INFO, WARNING, ERROR and FATAL. must be one of INFO, NOTICE, WARNING, ERROR and FATAL.
Default: WARNING Default: NOTICE
--accesslog-file=<PATH> --accesslog-file=<PATH>
Set path to write access log. To reopen file, Set path to write access log. To reopen file,
send USR1 signal to nghttpx. send USR1 signal to nghttpx.
@ -1216,7 +1208,7 @@ Misc:
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
Log::set_severity_level(WARNING); Log::set_severity_level(NOTICE);
create_config(); create_config();
fill_default_config(); fill_default_config();
@ -1887,9 +1879,7 @@ int main(int argc, char **argv)
event_loop(); event_loop();
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Shutdown momentarily";
LOG(INFO) << "Shutdown momentarily";
}
return 0; return 0;
} }

View File

@ -45,20 +45,21 @@ namespace shrpx {
namespace { namespace {
const char *SEVERITY_STR[] = { const char *SEVERITY_STR[] = {
"INFO", "WARN", "ERROR", "FATAL" "INFO", "NOTICE", "WARN", "ERROR", "FATAL"
}; };
} // namespace } // namespace
namespace { namespace {
const char *SEVERITY_COLOR[] = { const char *SEVERITY_COLOR[] = {
"\033[1;32m", // INFO "\033[1;32m", // INFO
"\033[1;36m", // NOTICE
"\033[1;33m", // WARN "\033[1;33m", // WARN
"\033[1;31m", // ERROR "\033[1;31m", // ERROR
"\033[1;35m", // FATAL "\033[1;35m", // FATAL
}; };
} // namespace } // namespace
int Log::severity_thres_ = WARNING; int Log::severity_thres_ = NOTICE;
void Log::set_severity_level(int severity) void Log::set_severity_level(int severity)
{ {
@ -81,6 +82,8 @@ int severity_to_syslog_level(int severity)
switch(severity) { switch(severity) {
case(INFO): case(INFO):
return LOG_INFO; return LOG_INFO;
case(NOTICE):
return LOG_NOTICE;
case(WARNING): case(WARNING):
return LOG_WARNING; return LOG_WARNING;
case(ERROR): case(ERROR):
@ -110,9 +113,14 @@ Log::~Log()
} }
if(get_config()->errorlog_syslog) { if(get_config()->errorlog_syslog) {
syslog(severity_to_syslog_level(severity_), "[%s] %s (%s:%d)", if (severity_ == NOTICE) {
SEVERITY_STR[severity_], stream_.str().c_str(), syslog(severity_to_syslog_level(severity_), "[%s] %s",
filename_, linenum_); SEVERITY_STR[severity_], stream_.str().c_str());
} else {
syslog(severity_to_syslog_level(severity_), "[%s] %s (%s:%d)",
SEVERITY_STR[severity_], stream_.str().c_str(),
filename_, linenum_);
}
return; return;
} }
@ -122,17 +130,28 @@ Log::~Log()
auto cached_time = get_config()->cached_time; auto cached_time = get_config()->cached_time;
rv = snprintf(buf, sizeof(buf), if (severity_ == NOTICE) {
"%s PID%d [%s%s%s] %s%s:%d%s %s\n", rv = snprintf(buf, sizeof(buf),
cached_time->c_str(), "%s PID%d [%s%s%s] %s\n",
getpid(), cached_time->c_str(),
tty ? SEVERITY_COLOR[severity_] : "", getpid(),
SEVERITY_STR[severity_], tty ? SEVERITY_COLOR[severity_] : "",
tty ? "\033[0m" : "", SEVERITY_STR[severity_],
tty ? "\033[1;30m" : "", tty ? "\033[0m" : "",
filename_, linenum_, stream_.str().c_str());
tty ? "\033[0m" : "", } else {
stream_.str().c_str()); rv = snprintf(buf, sizeof(buf),
"%s PID%d [%s%s%s] %s%s:%d%s %s\n",
cached_time->c_str(),
getpid(),
tty ? SEVERITY_COLOR[severity_] : "",
SEVERITY_STR[severity_],
tty ? "\033[0m" : "",
tty ? "\033[1;30m" : "",
filename_, linenum_,
tty ? "\033[0m" : "",
stream_.str().c_str());
}
if(rv < 0) { if(rv < 0) {
return; return;

View File

@ -71,7 +71,7 @@ class Downstream;
(Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ") (Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ")
enum SeverityLevel { enum SeverityLevel {
INFO, WARNING, ERROR, FATAL INFO, NOTICE, WARNING, ERROR, FATAL
}; };
class Log { class Log {

View File

@ -943,8 +943,10 @@ bool check_http2_requirement(SSL *ssl)
case TLS1_2_VERSION: case TLS1_2_VERSION:
break; break;
default: default:
LOG(INFO) << "TLSv1.2 was not negotiated. " if(LOG_ENABLED(INFO)) {
<< "HTTP/2 must not be negotiated."; LOG(INFO) << "TLSv1.2 was not negotiated. "
<< "HTTP/2 must not be negotiated.";
}
return false; return false;
} }

View File

@ -84,9 +84,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
} }
if(wev.type == GRACEFUL_SHUTDOWN) { if(wev.type == GRACEFUL_SHUTDOWN) {
if(LOG_ENABLED(INFO)) { LOG(NOTICE) << "Graceful shutdown commencing";
LOG(INFO) << "Graceful shutdown commencing";
}
worker_config->graceful_shutdown = true; worker_config->graceful_shutdown = true;