Add LOG_NOTICE level logging for application lifecycle events
This commit is contained in:
parent
03a2828fcf
commit
a067eb02a5
26
src/shrpx.cc
26
src/shrpx.cc
|
@ -190,9 +190,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
|
|||
// Otherwise, close fd, and create server socket as usual.
|
||||
|
||||
if(port == get_config()->port) {
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Listening on port " << get_config()->port;
|
||||
}
|
||||
LOG(NOTICE) << "Listening on port " << get_config()->port;
|
||||
|
||||
return new_evlistener(handler, fd);
|
||||
}
|
||||
|
@ -279,9 +277,7 @@ evconnlistener* create_evlistener(ListenHandler *handler, int family)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Listening on " << host << ", port " << get_config()->port;
|
||||
}
|
||||
LOG(NOTICE) << "Listening on " << host << ", port " << get_config()->port;
|
||||
|
||||
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);
|
||||
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Executing new binary";
|
||||
}
|
||||
LOG(NOTICE) << "Executing new binary";
|
||||
|
||||
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);
|
||||
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Graceful shutdown signal received";
|
||||
}
|
||||
LOG(NOTICE) << "Graceful shutdown signal received";
|
||||
|
||||
worker_config->graceful_shutdown = true;
|
||||
|
||||
|
@ -1132,8 +1124,8 @@ Mode:
|
|||
Logging:
|
||||
-L, --log-level=<LEVEL>
|
||||
Set the severity level of log output. <LEVEL>
|
||||
must be one of INFO, WARNING, ERROR and FATAL.
|
||||
Default: WARNING
|
||||
must be one of INFO, NOTICE, WARNING, ERROR and FATAL.
|
||||
Default: NOTICE
|
||||
--accesslog-file=<PATH>
|
||||
Set path to write access log. To reopen file,
|
||||
send USR1 signal to nghttpx.
|
||||
|
@ -1216,7 +1208,7 @@ Misc:
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
Log::set_severity_level(WARNING);
|
||||
Log::set_severity_level(NOTICE);
|
||||
create_config();
|
||||
fill_default_config();
|
||||
|
||||
|
@ -1887,9 +1879,7 @@ int main(int argc, char **argv)
|
|||
|
||||
event_loop();
|
||||
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Shutdown momentarily";
|
||||
}
|
||||
LOG(NOTICE) << "Shutdown momentarily";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -45,20 +45,21 @@ namespace shrpx {
|
|||
|
||||
namespace {
|
||||
const char *SEVERITY_STR[] = {
|
||||
"INFO", "WARN", "ERROR", "FATAL"
|
||||
"INFO", "NOTICE", "WARN", "ERROR", "FATAL"
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace {
|
||||
const char *SEVERITY_COLOR[] = {
|
||||
"\033[1;32m", // INFO
|
||||
"\033[1;36m", // NOTICE
|
||||
"\033[1;33m", // WARN
|
||||
"\033[1;31m", // ERROR
|
||||
"\033[1;35m", // FATAL
|
||||
};
|
||||
} // namespace
|
||||
|
||||
int Log::severity_thres_ = WARNING;
|
||||
int Log::severity_thres_ = NOTICE;
|
||||
|
||||
void Log::set_severity_level(int severity)
|
||||
{
|
||||
|
@ -81,6 +82,8 @@ int severity_to_syslog_level(int severity)
|
|||
switch(severity) {
|
||||
case(INFO):
|
||||
return LOG_INFO;
|
||||
case(NOTICE):
|
||||
return LOG_NOTICE;
|
||||
case(WARNING):
|
||||
return LOG_WARNING;
|
||||
case(ERROR):
|
||||
|
@ -110,9 +113,14 @@ Log::~Log()
|
|||
}
|
||||
|
||||
if(get_config()->errorlog_syslog) {
|
||||
if (severity_ == NOTICE) {
|
||||
syslog(severity_to_syslog_level(severity_), "[%s] %s",
|
||||
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;
|
||||
}
|
||||
|
@ -122,6 +130,16 @@ Log::~Log()
|
|||
|
||||
auto cached_time = get_config()->cached_time;
|
||||
|
||||
if (severity_ == NOTICE) {
|
||||
rv = snprintf(buf, sizeof(buf),
|
||||
"%s PID%d [%s%s%s] %s\n",
|
||||
cached_time->c_str(),
|
||||
getpid(),
|
||||
tty ? SEVERITY_COLOR[severity_] : "",
|
||||
SEVERITY_STR[severity_],
|
||||
tty ? "\033[0m" : "",
|
||||
stream_.str().c_str());
|
||||
} else {
|
||||
rv = snprintf(buf, sizeof(buf),
|
||||
"%s PID%d [%s%s%s] %s%s:%d%s %s\n",
|
||||
cached_time->c_str(),
|
||||
|
@ -133,6 +151,7 @@ Log::~Log()
|
|||
filename_, linenum_,
|
||||
tty ? "\033[0m" : "",
|
||||
stream_.str().c_str());
|
||||
}
|
||||
|
||||
if(rv < 0) {
|
||||
return;
|
||||
|
|
|
@ -71,7 +71,7 @@ class Downstream;
|
|||
(Log(SEVERITY, __FILE__, __LINE__) << "[DHTTP2:" << HTTP2 << "] ")
|
||||
|
||||
enum SeverityLevel {
|
||||
INFO, WARNING, ERROR, FATAL
|
||||
INFO, NOTICE, WARNING, ERROR, FATAL
|
||||
};
|
||||
|
||||
class Log {
|
||||
|
|
|
@ -943,8 +943,10 @@ bool check_http2_requirement(SSL *ssl)
|
|||
case TLS1_2_VERSION:
|
||||
break;
|
||||
default:
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "TLSv1.2 was not negotiated. "
|
||||
<< "HTTP/2 must not be negotiated.";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -84,9 +84,7 @@ void ThreadEventReceiver::on_read(bufferevent *bev)
|
|||
}
|
||||
|
||||
if(wev.type == GRACEFUL_SHUTDOWN) {
|
||||
if(LOG_ENABLED(INFO)) {
|
||||
LOG(INFO) << "Graceful shutdown commencing";
|
||||
}
|
||||
LOG(NOTICE) << "Graceful shutdown commencing";
|
||||
|
||||
worker_config->graceful_shutdown = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue