寫日志函數為ngx_log_error_core,位於src/core/ngx_log.c:89行
核心代碼如下:
while (log) {
if (log->log_level < level && !debug_connection) {
break;
}
(void) ngx_write_fd(log->file->fd, errstr, p - errstr);
if (log->file->fd == ngx_stderr) {
wrote_stderr = 1;
}
log = log->next;
}
其中ngx_write_fd為
static ngx_inline ssize_t
ngx_write_fd(ngx_fd_t fd, void *buf, size_t n)
{
return write(fd, buf, n);
}
即nginx中寫日志是沒有作什么特別的優化處理,完全依賴操作系統提供的異步寫來保證性能