93
103
p = errstr + ngx_cached_err_log_time.len;
95
p = ngx_snprintf(p, last - p, " [%s] ", err_levels[level]);
105
p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
98
p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ",
108
p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ",
99
109
ngx_log_pid, ngx_log_tid);
101
111
if (log->connection) {
102
p = ngx_snprintf(p, last - p, "*%uA ", log->connection);
112
p = ngx_slprintf(p, last, "*%uA ", log->connection);
105
117
#if (NGX_HAVE_VARIADIC_MACROS)
107
119
va_start(args, fmt);
108
p = ngx_vsnprintf(p, last - p, fmt, args);
120
p = ngx_vslprintf(p, last, fmt, args);
113
p = ngx_vsnprintf(p, last - p, fmt, args);
125
p = ngx_vslprintf(p, last, fmt, args);
121
/* leave a space for an error code */
131
if ((unsigned) err >= 0x80000000) {
132
p = ngx_snprintf(p, last - p, " (%Xd: ", err);
135
p = ngx_snprintf(p, last - p, " (%d: ", err);
140
p = ngx_snprintf(p, last - p, " (%d: ", err);
144
p = ngx_strerror_r(err, p, last - p);
130
p = ngx_log_errno(p, last, err);
151
133
if (level != NGX_LOG_DEBUG && log->handler) {
195
ngx_log_abort(ngx_err_t err, const char *text)
197
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err, text);
190
ngx_log_abort(ngx_err_t err, const char *fmt, ...)
194
u_char errstr[NGX_MAX_CONF_ERRSTR];
197
p = ngx_vsnprintf(errstr, sizeof(errstr) - 1, fmt, args);
200
ngx_log_error(NGX_LOG_ALERT, ngx_cycle->log, err,
201
"%*s", p - errstr, errstr);
206
ngx_log_stderr(ngx_err_t err, const char *fmt, ...)
210
u_char errstr[NGX_MAX_ERROR_STR];
212
last = errstr + NGX_MAX_ERROR_STR;
215
ngx_memcpy(errstr, "nginx: ", 7);
218
p = ngx_vslprintf(p, last, fmt, args);
222
p = ngx_log_errno(p, last, err);
225
if (p > last - NGX_LINEFEED_SIZE) {
226
p = last - NGX_LINEFEED_SIZE;
231
(void) ngx_write_console(ngx_stderr, errstr, p - errstr);
236
ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err)
238
if (buf > last - 50) {
240
/* leave a space for an error code */
249
buf = ngx_slprintf(buf, last, ((unsigned) err < 0x80000000)
250
? " (%d: " : " (%Xd: ", err);
252
buf = ngx_slprintf(buf, last, " (%d: ", err);
255
buf = ngx_strerror(err, buf, last - buf);
266
ngx_log_init(u_char *prefix)
204
ngx_log.file = &ngx_stderr;
271
ngx_log.file = &ngx_log_file;
205
272
ngx_log.log_level = NGX_LOG_NOTICE;
209
ngx_stderr_fileno = GetStdHandle(STD_ERROR_HANDLE);
211
ngx_stderr.fd = ngx_open_file(NGX_ERROR_LOG_PATH, NGX_FILE_RDWR,
212
NGX_FILE_CREATE_OR_OPEN|NGX_FILE_APPEND, 0);
214
if (ngx_stderr.fd == NGX_INVALID_FILE) {
215
ngx_message_box("nginx", MB_OK, ngx_errno,
216
"Could not open error log file: "
217
ngx_open_file_n " \"" NGX_ERROR_LOG_PATH "\" failed");
221
if (ngx_file_append_mode(ngx_stderr.fd) == NGX_ERROR) {
222
ngx_message_box("nginx", MB_OK, ngx_errno,
223
"Could not open error log file: "
224
ngx_file_append_mode_n " \"" NGX_ERROR_LOG_PATH
231
ngx_stderr.fd = STDERR_FILENO;
274
name = (u_char *) NGX_ERROR_LOG_PATH;
277
* we use ngx_strlen() here since BCC warns about
278
* condition is always false and unreachable code
281
nlen = ngx_strlen(name);
284
ngx_log_file.fd = ngx_stderr;
291
if (name[1] != ':') {
293
if (name[0] != '/') {
297
plen = ngx_strlen(prefix);
301
prefix = (u_char *) NGX_PREFIX;
302
plen = ngx_strlen(prefix);
309
name = malloc(plen + nlen + 2);
314
p = ngx_cpymem(name, prefix, plen);
316
if (!ngx_path_separator(*(p - 1))) {
320
ngx_cpystrn(p, (u_char *) NGX_ERROR_LOG_PATH, nlen + 1);
326
ngx_log_file.fd = ngx_open_file(name, NGX_FILE_APPEND,
327
NGX_FILE_CREATE_OR_OPEN,
328
NGX_FILE_DEFAULT_ACCESS);
330
if (ngx_log_file.fd == NGX_INVALID_FILE) {
331
ngx_log_stderr(ngx_errno,
332
"[alert] could not open error log file: "
333
ngx_open_file_n " \"%s\" failed", name);
335
ngx_event_log(ngx_errno,
336
"could not open error log file: "
337
ngx_open_file_n " \"%s\" failed", name);
340
ngx_log_file.fd = ngx_stderr;
240
ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_array_t *args)
352
ngx_log_create(ngx_cycle_t *cycle, ngx_str_t *name)
243
ngx_str_t *value, *name;
253
356
log = ngx_pcalloc(cycle->pool, sizeof(ngx_log_t));
254
357
if (log == NULL) {
268
ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log)
371
ngx_log_set_levels(ngx_conf_t *cf, ngx_log_t *log)
373
ngx_uint_t i, n, d, found;
271
374
ngx_str_t *value;
273
376
value = cf->args->elts;
275
378
for (i = 2; i < cf->args->nelts; i++) {
277
381
for (n = 1; n <= NGX_LOG_DEBUG; n++) {
278
if (ngx_strcmp(value[i].data, err_levels[n]) == 0) {
382
if (ngx_strcmp(value[i].data, err_levels[n].data) == 0) {
280
384
if (log->log_level != 0) {
281
385
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
282
"duplicate log level \"%s\"",
386
"duplicate log level \"%V\"",
284
388
return NGX_CONF_ERROR;
287
391
log->log_level = n;
322
ngx_set_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
429
ngx_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
431
ngx_str_t *value, name;
433
if (cf->cycle->new_log.file) {
434
return "is duplicate";
326
437
value = cf->args->elts;
328
if (value[1].len == 6 && ngx_strcmp(value[1].data, "stderr") == 0) {
329
cf->cycle->new_log->file->fd = ngx_stderr.fd;
330
cf->cycle->new_log->file->name.len = 0;
331
cf->cycle->new_log->file->name.data = NULL;
439
if (ngx_strcmp(value[1].data, "stderr") == 0) {
334
cf->cycle->new_log->file->name = value[1];
336
if (ngx_conf_full_name(cf->cycle, &cf->cycle->new_log->file->name, 0)
339
return NGX_CONF_ERROR;
343
return ngx_set_error_log_levels(cf, cf->cycle->new_log);
446
cf->cycle->new_log.file = ngx_conf_open_file(cf->cycle, &name);
447
if (cf->cycle->new_log.file == NULL) {
451
if (cf->args->nelts == 2) {
452
cf->cycle->new_log.log_level = NGX_LOG_ERR;
456
cf->cycle->new_log.log_level = 0;
458
return ngx_log_set_levels(cf, &cf->cycle->new_log);