// struct ngx_log_s
// 日志结构 {{{
struct ngx_log_s {
ngx_uint_t log_level; // 日志等级
ngx_open_file_t *file; // 日志文件信息
ngx_atomic_uint_t connection; // 引用该日志对象的连接数
ngx_log_handler_pt handler; // 输出日志时需要调用的回调函数
void *data; // 回调函数所需要的参数
ngx_log_writer_pt writer;
void *wdata;
/*
* we declare "action" as "char *" because the actions are usually
* the static strings and in the "u_char *" case we have to override
* their types all the time
*/
char *action; // 日志记录前,保存当前正在进行的动作
ngx_log_t *next; // 指向下一日志对象
}; // }}}
#define NGX_LOG_STDERR 0 #define NGX_LOG_EMERG 1 #define NGX_LOG_ALERT 2 #define NGX_LOG_CRIT 3 #define NGX_LOG_ERR 4 #define NGX_LOG_WARN 5 #define NGX_LOG_NOTICE 6 #define NGX_LOG_INFO 7 #define NGX_LOG_DEBUG 8
// struct ngx_open_file_s
// 打开文件结构 {{{
struct ngx_open_file_s {
ngx_fd_t fd;
ngx_str_t name;
void (*flush)(ngx_open_file_t *file, ngx_log_t *log);
// 文件刷新时调用的回调
void *data; // 回调函数使用的参数
}; // }}}
// ngx_log_t *ngx_log_init(u_char *prefix);
// 初始化 ngx_log 结构,创建 errlog 文件 {{{
ngx_log_t *
ngx_log_init(u_char *prefix)
{
u_char *p, *name;
size_t nlen, plen;
ngx_log.file = &ngx_log_file;
ngx_log.log_level = NGX_LOG_NOTICE;
name = (u_char *) NGX_ERROR_LOG_PATH;
/*
* we use ngx_strlen() here since BCC warns about
* condition is always false and unreachable code
*/
nlen = ngx_strlen(name);
if (nlen == 0) {
ngx_log_file.fd = ngx_stderr;
return &ngx_log;
}
p = NULL;
// 判断是否是绝对路径
#if (NGX_WIN32)
if (name[1] != ':') {
#else
if (name[0] != '/') {
#endif
if (prefix) {
plen = ngx_strlen(prefix);
} else {
#ifdef NGX_PREFIX
prefix = (u_char *) NGX_PREFIX;
plen = ngx_strlen(prefix);
#else
plen = 0;
#endif
}
if (plen) {
name = malloc(plen + nlen + 2);
if (name == NULL) {
return NULL;
}
p = ngx_cpymem(name, prefix, plen);
if (!ngx_path_separator(*(p - 1))) {
*p++ = '/';
}
ngx_cpystrn(p, (u_char *) NGX_ERROR_LOG_PATH, nlen + 1);
p = name;
}
}
ngx_log_file.fd = ngx_open_file(name, NGX_FILE_APPEND,
NGX_FILE_CREATE_OR_OPEN,
NGX_FILE_DEFAULT_ACCESS);
if (ngx_log_file.fd == NGX_INVALID_FILE) {
ngx_log_stderr(ngx_errno,
"[alert] could not open error log file: "
ngx_open_file_n " \"%s\" failed", name);
#if (NGX_WIN32)
ngx_event_log(ngx_errno,
"could not open error log file: "
ngx_open_file_n " \"%s\" failed", name);
#endif
ngx_log_file.fd = ngx_stderr;
}
if (p) {
ngx_free(p);
}
return &ngx_log;
}
// }}}
{
log_level = 6,
file = 0x80e3000 <ngx_log_file>,
connection = 0,
handler = 0x0,
data = 0x0,
writer = 0x0,
wdata = 0x0,
action = 0x0,
next = 0x0
}
{
fd = 3,
name = {
len = 0,
data = 0x0
},
flush = 0x0,
data = 0x0
}
./configure --add-module=/var/local/ngx_log_if-master
server {
location / {
access_log_bypass_if ($status = 404); #不记录404状态的所有日志信息
access_log_bypass_if ($uri ~* 'images'); #不记录uri中所有images目录下文件的日志信息
access_log_bypass_if ($uri = '/index.html'); #不记录uri为/index.html的日志信息
access_log_bypass_if ($host ~* 'tonv.cc'); #不记录host为tonv.cc的所有日志信息
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有