Skip to content

Commit 3d584dd

Browse files
committed
Optimize log format, fix typo
1 parent 9d61e9b commit 3d584dd

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed

ext-src/php_swoole.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ PHP_MINIT_FUNCTION(swoole) {
688688
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_EOF_PROTOCOL", SW_TRACE_EOF_PROTOCOL);
689689
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_LENGTH_PROTOCOL", SW_TRACE_LENGTH_PROTOCOL);
690690
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_CLOSE", SW_TRACE_CLOSE);
691-
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_WEBSOCEKT", SW_TRACE_WEBSOCEKT);
691+
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_WEBSOCKET", SW_TRACE_WEBSOCKET);
692692
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_REDIS_CLIENT", SW_TRACE_REDIS_CLIENT);
693693
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_MYSQL_CLIENT", SW_TRACE_MYSQL_CLIENT);
694694
SW_REGISTER_LONG_CONSTANT("SWOOLE_TRACE_HTTP_CLIENT", SW_TRACE_HTTP_CLIENT);

include/swoole_log.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ swoole::Logger *sw_logger();
116116
#define swWarn(str, ...) \
117117
do { \
118118
if (SW_LOG_WARNING >= sw_logger()->get_level()) { \
119-
size_t _sw_error_len = sw_snprintf(sw_error, SW_ERROR_MSG_SIZE, "%s: " str, __func__, ##__VA_ARGS__); \
119+
size_t _sw_error_len = sw_snprintf(sw_error, SW_ERROR_MSG_SIZE, str, ##__VA_ARGS__); \
120120
sw_logger()->put(SW_LOG_WARNING, sw_error, _sw_error_len); \
121121
} \
122122
} while (0)
@@ -169,7 +169,7 @@ swoole::Logger *sw_logger();
169169
swoole_set_last_error(__errno); \
170170
if (level >= sw_logger()->get_level()) { \
171171
size_t _sw_error_len = \
172-
sw_snprintf(sw_error, SW_ERROR_MSG_SIZE, "%s (ERRNO %d): " str, __func__, __errno, ##__VA_ARGS__); \
172+
sw_snprintf(sw_error, SW_ERROR_MSG_SIZE, "(ERRNO %d): " str, __errno, ##__VA_ARGS__); \
173173
sw_logger()->put(level, sw_error, _sw_error_len); \
174174
} \
175175
} while (0)
@@ -222,7 +222,7 @@ enum swTrace_type {
222222
SW_TRACE_EOF_PROTOCOL = 1u << 12,
223223
SW_TRACE_LENGTH_PROTOCOL = 1u << 13,
224224
SW_TRACE_CLOSE = 1u << 14,
225-
SW_TRACE_WEBSOCEKT = 1u << 15,
225+
SW_TRACE_WEBSOCKET = 1u << 15,
226226
/**
227227
* Client
228228
*/

src/coroutine/socket.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1486,7 +1486,13 @@ ssize_t Socket::recv_packet_with_length_protocol() {
14861486
goto _recv_header;
14871487
} else if (packet_len > protocol.package_max_length) {
14881488
read_buffer->clear();
1489-
set_err(SW_ERROR_PACKAGE_LENGTH_TOO_LARGE, "remote packet is too big");
1489+
swoole_error_log(SW_LOG_WARNING,
1490+
SW_ERROR_PACKAGE_LENGTH_TOO_LARGE,
1491+
"packet length is too big, remote_addr=%s:%d, length=%zu",
1492+
socket->info.get_ip(),
1493+
socket->info.get_port(),
1494+
packet_len);
1495+
set_err(SW_ERROR_PACKAGE_LENGTH_TOO_LARGE, sw_error);
14901496
return -1;
14911497
}
14921498

src/protocol/websocket.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,12 @@ bool decode(Frame *frame, char *data, size_t length) {
180180
header_length += 8;
181181
}
182182

183+
swTraceLog(SW_TRACE_WEBSOCKET,
184+
"decode frame, payload_length=%ld, mask=%d, opcode=%d",
185+
payload_length,
186+
frame->header.MASK,
187+
frame->header.OPCODE);
188+
183189
if (payload_length == 0) {
184190
frame->header_length = header_length;
185191
frame->payload_length = 0;

src/server/master.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,13 +1004,13 @@ int Server::send_to_connection(SendData *_send) {
10041004
if (_send->info.type == SW_SERVER_EVENT_RECV_DATA) {
10051005
swoole_error_log(SW_LOG_NOTICE,
10061006
SW_ERROR_SESSION_NOT_EXIST,
1007-
"send %d byte failed, session#%ld does not exist",
1007+
"Server::send(): send %d byte failed, session#%ld does not exist",
10081008
_send_length,
10091009
session_id);
10101010
} else {
10111011
swoole_error_log(SW_LOG_NOTICE,
10121012
SW_ERROR_SESSION_NOT_EXIST,
1013-
"send event[%d] failed, session#%ld does not exist",
1013+
"Server::send(): send event[%d] failed, session#%ld does not exist",
10141014
_send->info.type,
10151015
session_id);
10161016
}
@@ -1129,16 +1129,19 @@ int Server::send_to_connection(SendData *_send) {
11291129
else {
11301130
// connection is closed
11311131
if (conn->peer_closed) {
1132-
swWarn("connection#%d is closed by client", fd);
1132+
swoole_error_log(
1133+
SW_LOG_NOTICE, SW_ERROR_SESSION_CLOSED_BY_CLIENT, "Server::send(): socket#%d is closed by client", fd);
11331134
return false;
11341135
}
11351136
// connection output buffer overflow
11361137
if (_socket->out_buffer->length() >= _socket->buffer_size) {
11371138
if (send_yield) {
11381139
swoole_set_last_error(SW_ERROR_OUTPUT_SEND_YIELD);
11391140
} else {
1140-
swoole_error_log(
1141-
SW_LOG_WARNING, SW_ERROR_OUTPUT_BUFFER_OVERFLOW, "connection#%d output buffer overflow", fd);
1141+
swoole_error_log(SW_LOG_WARNING,
1142+
SW_ERROR_OUTPUT_BUFFER_OVERFLOW,
1143+
"Server::send(): connection#%d output buffer overflow",
1144+
fd);
11421145
}
11431146
conn->overflow = 1;
11441147
if (onBufferEmpty && onBufferFull == nullptr) {

0 commit comments

Comments
 (0)