log a failure of the writing to access_log once per minute

This commit is contained in:
Igor Sysoev 2007-01-21 19:01:01 +00:00
parent 300de4fb61
commit d0863c106d

View File

@ -42,6 +42,7 @@ typedef struct {
typedef struct {
ngx_open_file_t *file;
time_t disk_full_time;
time_t error_log_time;
ngx_array_t *ops; /* array of ngx_http_log_op_t */
} ngx_http_log_t;
@ -59,6 +60,9 @@ typedef struct {
} ngx_http_log_var_t;
static void ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log,
u_char *buf, size_t len);
static u_char *ngx_http_log_connection(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op);
static u_char *ngx_http_log_pipe(ngx_http_request_t *r, u_char *buf,
@ -183,9 +187,9 @@ static ngx_http_log_var_t ngx_http_log_vars[] = {
ngx_int_t
ngx_http_log_handler(ngx_http_request_t *r)
{
ngx_uint_t i, l;
u_char *line, *p;
size_t len;
ngx_uint_t i, l;
ngx_http_log_t *log;
ngx_open_file_t *file;
ngx_http_log_op_t *op;
@ -206,9 +210,9 @@ ngx_http_log_handler(ngx_http_request_t *r)
if (ngx_time() == log[l].disk_full_time) {
/*
* On FreeBSD writing to a full filesystem with enabled softupdates
* on FreeBSD writing to a full filesystem with enabled softupdates
* may block process for much longer time than writing to non-full
* filesystem, so we skip writing the log for one second.
* filesystem, so we skip writing to a log for one second
*/
continue;
@ -233,13 +237,8 @@ ngx_http_log_handler(ngx_http_request_t *r)
if (len > (size_t) (file->last - file->pos)) {
if (ngx_write_fd(file->fd, file->buffer,
file->pos - file->buffer)
== -1
&& ngx_errno == NGX_ENOSPC)
{
log[l].disk_full_time = ngx_time();
}
ngx_http_log_write(r, &log[l], file->buffer,
file->pos - file->buffer);
file->pos = file->buffer;
}
@ -273,17 +272,57 @@ ngx_http_log_handler(ngx_http_request_t *r)
ngx_linefeed(p);
if (ngx_write_fd(file->fd, line, p - line) == -1
&& ngx_errno == NGX_ENOSPC)
{
log[l].disk_full_time = ngx_time();
}
ngx_http_log_write(r, &log[l], line, p - line);
}
return NGX_OK;
}
static void
ngx_http_log_write(ngx_http_request_t *r, ngx_http_log_t *log, u_char *buf,
size_t len)
{
time_t now;
ssize_t n;
ngx_err_t err;
n = ngx_write_fd(log->file->fd, buf, len);
if (n == (ssize_t) len) {
return;
}
now = ngx_time();
if (n == -1) {
err = ngx_errno;
if (err == NGX_ENOSPC) {
log->disk_full_time = now;
}
if (now - log->error_log_time > 60) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, err,
ngx_write_fd_n " to \"%V\" failed",
&log->file->name);
log->error_log_time = now;
}
return;
}
if (now - log->error_log_time > 60) {
ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
ngx_write_fd_n " to \"%V\" was incomplete: %z of %uz",
&log->file->name, n, len);
log->error_log_time = now;
}
}
static u_char *
ngx_http_log_copy_short(ngx_http_request_t *r, u_char *buf,
ngx_http_log_op_t *op)
@ -547,6 +586,7 @@ ngx_http_log_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
}
log->disk_full_time = 0;
log->error_log_time = 0;
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_log_module);
fmt = lmcf->formats.elts;
@ -600,6 +640,7 @@ ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
}
log->disk_full_time = 0;
log->error_log_time = 0;
if (cf->args->nelts >= 3) {
name = value[2];