ngx_log_errno()

This commit is contained in:
Igor Sysoev 2009-04-27 13:17:33 +00:00
parent 70eb9fa979
commit 9c1308dd82
4 changed files with 38 additions and 88 deletions

View file

@ -965,27 +965,7 @@ ngx_conf_log_error(ngx_uint_t level, ngx_conf_t *cf, ngx_err_t err,
va_end(args);
if (err) {
if (p > last - 50) {
/* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
#if (NGX_WIN32)
p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_slprintf(p, last, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
*p++ = ')';
p = ngx_log_errno(p, last, err);
}
if (cf->conf_file == NULL) {

View file

@ -126,29 +126,7 @@ ngx_log_error_core(ngx_uint_t level, ngx_log_t *log, ngx_err_t err,
#endif
if (err) {
if (p > last - 50) {
/* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
#if (NGX_WIN32)
p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_slprintf(p, last, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
if (p < last) {
*p++ = ')';
}
p = ngx_log_errno(p, last, err);
}
if (level != NGX_LOG_DEBUG && log->handler) {
@ -236,34 +214,12 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...)
p = ngx_vslprintf(errstr, last, fmt, args);
va_end(args);
if (p > errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE) {
p = errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE;
if (err) {
p = ngx_log_errno(p, last, err);
}
if (err) {
if (p > last - 50) {
/* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
#if (NGX_WIN32)
p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
p = ngx_slprintf(p, last, " (%d: ", err);
#endif
p = ngx_strerror_r(err, p, last - p);
if (p < last) {
*p++ = ')';
}
if (p > last - NGX_LINEFEED_SIZE) {
p = last - NGX_LINEFEED_SIZE;
}
ngx_linefeed(p);
@ -272,6 +228,36 @@ ngx_log_stderr(ngx_err_t err, const char *fmt, ...)
}
u_char *
ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err)
{
if (buf > last - 50) {
/* leave a space for an error code */
buf = last - 50;
*buf++ = '.';
*buf++ = '.';
*buf++ = '.';
}
#if (NGX_WIN32)
buf = ngx_slprintf(buf, last, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
#else
buf = ngx_slprintf(buf, last, " (%d: ", err);
#endif
buf = ngx_strerror_r(err, buf, last - buf);
if (buf < last) {
*buf++ = ')';
}
return buf;
}
ngx_log_t *
ngx_log_init(u_char *prefix)
{

View file

@ -200,6 +200,7 @@ ngx_log_t *ngx_log_create_errlog(ngx_cycle_t *cycle, ngx_str_t *name);
char *ngx_set_error_log_levels(ngx_conf_t *cf, ngx_log_t *log);
void ngx_cdecl ngx_log_abort(ngx_err_t err, const char *fmt, ...);
void ngx_cdecl ngx_log_stderr(ngx_err_t err, const char *fmt, ...);
u_char *ngx_log_errno(u_char *buf, u_char *last, ngx_err_t err);
extern ngx_module_t ngx_errlog_module;

View file

@ -33,24 +33,7 @@ ngx_event_log(ngx_err_t err, const char *fmt, ...)
va_end(args);
if (err) {
if (p > last - 50) {
/* leave a space for an error code */
p = last - 50;
*p++ = '.';
*p++ = '.';
*p++ = '.';
}
p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
? " (%d: " : " (%Xd: ", err);
p = ngx_strerror_r(err, p, last - p);
if (p < last) {
*p++ = ')';
}
p = ngx_log_errno(p, last, err);
}
if (p > last - NGX_LINEFEED_SIZE - 1) {