浏览代码

optimize some log level and msg desc (#721)

宅の士 8 月之前
父节点
当前提交
3cb7c1654b
共有 6 个文件被更改,包括 24 次插入11 次删除
  1. 1 1
      event/hevent.c
  2. 2 2
      event/nio.c
  3. 1 1
      http/HttpMessage.cpp
  4. 2 1
      http/HttpParser.cpp
  5. 5 5
      http/server/HttpHandler.cpp
  6. 13 1
      ssl/openssl.c

+ 1 - 1
event/hevent.c

@@ -597,7 +597,7 @@ static void __write_timeout_cb(htimer_t* timer) {
         if (io->io_type & HIO_TYPE_SOCKET) {
             char localaddrstr[SOCKADDR_STRLEN] = {0};
             char peeraddrstr[SOCKADDR_STRLEN] = {0};
-            hlogw("write timeout [%s] <=> [%s]",
+            hlogi("write timeout [%s] <=> [%s]",
                     SOCKADDR_STR(io->localaddr, localaddrstr),
                     SOCKADDR_STR(io->peeraddr, peeraddrstr));
         }

+ 2 - 2
event/nio.c

@@ -80,7 +80,7 @@ static void ssl_server_handshake(hio_t* io) {
         }
     }
     else {
-        hloge("ssl handshake failed: %d", ret);
+        hloge("ssl server handshake failed: %d", ret);
         io->error = ERR_SSL_HANDSHAKE;
         hio_close(io);
     }
@@ -101,7 +101,7 @@ static void ssl_client_handshake(hio_t* io) {
         }
     }
     else {
-        hloge("ssl handshake failed: %d", ret);
+        hloge("ssl client handshake failed: %d", ret);
         io->error = ERR_SSL_HANDSHAKE;
         hio_close(io);
     }

+ 1 - 1
http/HttpMessage.cpp

@@ -92,7 +92,7 @@ bool HttpCookie::parse(const std::string& str) {
                 httponly = true;
             }
             else {
-                hlogw("Unrecognized key '%s'", key.c_str());
+                hlogi("Cookie Unrecognized key '%s'", key.c_str());
             }
         }
 

+ 2 - 1
http/HttpParser.cpp

@@ -2,6 +2,7 @@
 
 #include "Http1Parser.h"
 #include "Http2Parser.h"
+#include "hlog.h"
 
 HttpParser* HttpParser::New(http_session_type type, http_version version) {
     HttpParser* hp = NULL;
@@ -12,7 +13,7 @@ HttpParser* HttpParser::New(http_session_type type, http_version version) {
 #ifdef WITH_NGHTTP2
         hp = new Http2Parser(type);
 #else
-        fprintf(stderr, "Please recompile WITH_NGHTTP2!\n");
+        hlogi("Please recompile WITH_NGHTTP2!\n");
 #endif
     }
 

+ 5 - 5
http/server/HttpHandler.cpp

@@ -895,7 +895,7 @@ int HttpHandler::sendFile() {
     int readbytes = MIN(file->buf.len, resp->content_length);
     size_t nread = file->read(file->buf.base, readbytes);
     if (nread <= 0) {
-        hloge("read file error!");
+        hloge("read file: %s error!", file->filepath);
         error = ERR_READ_FILE;
         writer->close(true);
         return nread;
@@ -967,7 +967,7 @@ int HttpHandler::upgradeWebSocket() {
     if (iter_protocol != req->headers.end()) {
         hv::StringList subprotocols = hv::split(iter_protocol->second, ',');
         if (subprotocols.size() > 0) {
-            hlogw("%s: %s => just select first protocol %s", SEC_WEBSOCKET_PROTOCOL, iter_protocol->second.c_str(), subprotocols[0].c_str());
+            hlogw("[%s:%d] %s: %s => just select first protocol %s", ip, port, SEC_WEBSOCKET_PROTOCOL, iter_protocol->second.c_str(), subprotocols[0].c_str());
             resp->headers[SEC_WEBSOCKET_PROTOCOL] = subprotocols[0];
         }
     }
@@ -997,7 +997,7 @@ int HttpHandler::upgradeHTTP2() {
     SendHttpResponse();
 
     if (!SwitchHTTP2()) {
-        hloge("[%s:%d] unsupported HTTP2", ip, port);
+        hlogw("[%s:%d] unsupported HTTP2", ip, port);
         return SetError(ERR_INVALID_PROTOCOL);
     }
 
@@ -1024,7 +1024,7 @@ int HttpHandler::handleForwardProxy() {
     if (service && service->enable_forward_proxy) {
         return connectProxy(req->url);
     } else {
-        hlogw("Forbidden to forward proxy %s", req->url.c_str());
+        hlogw("[%s:%d] Forbidden to forward proxy %s", ip, port, req->url.c_str());
         SetError(HTTP_STATUS_FORBIDDEN, HTTP_STATUS_FORBIDDEN);
     }
     return 0;
@@ -1057,7 +1057,7 @@ int HttpHandler::connectProxy(const std::string& strUrl) {
     }
 
     if (forward_proxy && !service->IsTrustProxy(url.host.c_str())) {
-        hlogw("Forbidden to proxy %s", url.host.c_str());
+        hlogw("[%s:%d] Forbidden to proxy %s", ip, port, url.host.c_str());
         SetError(HTTP_STATUS_FORBIDDEN, HTTP_STATUS_FORBIDDEN);
         return 0;
     }

+ 13 - 1
ssl/openssl.c

@@ -1,5 +1,5 @@
 #include "hssl.h"
-
+#include "hlog.h"
 #ifdef WITH_OPENSSL
 
 #include "openssl/ssl.h"
@@ -117,6 +117,12 @@ int hssl_accept(hssl_t ssl) {
     else if (err == SSL_ERROR_WANT_WRITE) {
         return HSSL_WANT_WRITE;
     }
+    else if (err == SSL_ERROR_SYSCALL) {
+        hloge("SSL_accept errno:%d,error:%s", errno, strerror(errno));
+    }
+    else {
+        hloge("SSL_accept: %s", ERR_error_string(ERR_get_error(), NULL));
+    }
     return err;
 }
 
@@ -131,6 +137,12 @@ int hssl_connect(hssl_t ssl) {
     else if (err == SSL_ERROR_WANT_WRITE) {
         return HSSL_WANT_WRITE;
     }
+    else if (err == SSL_ERROR_SYSCALL) {
+        hloge("SSL_connect errno:%d,error:%s", errno, strerror(errno));
+    }
+    else {
+        hloge("SSL_connect: %s", ERR_error_string(ERR_get_error(), NULL));
+    }
     return err;
 }