comparison src/core/ngx_log.c @ 2764:d4a717592877

use ngx_vslprintf(), ngx_slprintf()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 27 Apr 2009 13:06:20 +0000
parents 77264e0157ad
children 6d358aeaa989
comparison
equal deleted inserted replaced
2763:819bea4e964e 2764:d4a717592877
99 ngx_memcpy(errstr, ngx_cached_err_log_time.data, 99 ngx_memcpy(errstr, ngx_cached_err_log_time.data,
100 ngx_cached_err_log_time.len); 100 ngx_cached_err_log_time.len);
101 101
102 p = errstr + ngx_cached_err_log_time.len; 102 p = errstr + ngx_cached_err_log_time.len;
103 103
104 p = ngx_snprintf(p, last - p, " [%V] ", &err_levels[level]); 104 p = ngx_slprintf(p, last, " [%V] ", &err_levels[level]);
105 105
106 /* pid#tid */ 106 /* pid#tid */
107 p = ngx_snprintf(p, last - p, "%P#" NGX_TID_T_FMT ": ", 107 p = ngx_slprintf(p, last, "%P#" NGX_TID_T_FMT ": ",
108 ngx_log_pid, ngx_log_tid); 108 ngx_log_pid, ngx_log_tid);
109 109
110 if (log->connection) { 110 if (log->connection) {
111 p = ngx_snprintf(p, last - p, "*%uA ", log->connection); 111 p = ngx_slprintf(p, last, "*%uA ", log->connection);
112 } 112 }
113 113
114 msg = p; 114 msg = p;
115 115
116 #if (NGX_HAVE_VARIADIC_MACROS) 116 #if (NGX_HAVE_VARIADIC_MACROS)
117 117
118 va_start(args, fmt); 118 va_start(args, fmt);
119 p = ngx_vsnprintf(p, last - p, fmt, args); 119 p = ngx_vslprintf(p, last, fmt, args);
120 va_end(args); 120 va_end(args);
121 121
122 #else 122 #else
123 123
124 p = ngx_vsnprintf(p, last - p, fmt, args); 124 p = ngx_vslprintf(p, last, fmt, args);
125 125
126 #endif 126 #endif
127 127
128 if (err) { 128 if (err) {
129 129
136 *p++ = '.'; 136 *p++ = '.';
137 *p++ = '.'; 137 *p++ = '.';
138 } 138 }
139 139
140 #if (NGX_WIN32) 140 #if (NGX_WIN32)
141 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) 141 p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
142 ? " (%d: " : " (%Xd: ", err); 142 ? " (%d: " : " (%Xd: ", err);
143 #else 143 #else
144 p = ngx_snprintf(p, last - p, " (%d: ", err); 144 p = ngx_slprintf(p, last, " (%d: ", err);
145 #endif 145 #endif
146 146
147 p = ngx_strerror_r(err, p, last - p); 147 p = ngx_strerror_r(err, p, last - p);
148 148
149 if (p < last) { 149 if (p < last) {
228 { 228 {
229 u_char *p, *last; 229 u_char *p, *last;
230 va_list args; 230 va_list args;
231 u_char errstr[NGX_MAX_ERROR_STR]; 231 u_char errstr[NGX_MAX_ERROR_STR];
232 232
233 last = errstr + NGX_MAX_ERROR_STR;
234
233 va_start(args, fmt); 235 va_start(args, fmt);
234 p = ngx_vsnprintf(errstr, NGX_MAX_ERROR_STR, fmt, args); 236 p = ngx_vslprintf(errstr, last, fmt, args);
235 va_end(args); 237 va_end(args);
236 238
237 if (p > errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE) { 239 if (p > errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE) {
238 p = errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE; 240 p = errstr + NGX_MAX_ERROR_STR - NGX_LINEFEED_SIZE;
239 } 241 }
240 242
241 if (err) { 243 if (err) {
242 244
243 last = errstr + NGX_MAX_ERROR_STR;
244
245 if (p > last - 50) { 245 if (p > last - 50) {
246 246
247 /* leave a space for an error code */ 247 /* leave a space for an error code */
248 248
249 p = last - 50; 249 p = last - 50;
251 *p++ = '.'; 251 *p++ = '.';
252 *p++ = '.'; 252 *p++ = '.';
253 } 253 }
254 254
255 #if (NGX_WIN32) 255 #if (NGX_WIN32)
256 p = ngx_snprintf(p, last - p, ((unsigned) err < 0x80000000) 256 p = ngx_slprintf(p, last, ((unsigned) err < 0x80000000)
257 ? " (%d: " : " (%Xd: ", err); 257 ? " (%d: " : " (%Xd: ", err);
258 #else 258 #else
259 p = ngx_snprintf(p, last - p, " (%d: ", err); 259 p = ngx_slprintf(p, last, " (%d: ", err);
260 #endif 260 #endif
261 261
262 p = ngx_strerror_r(err, p, last - p); 262 p = ngx_strerror_r(err, p, last - p);
263 263
264 if (p < last) { 264 if (p < last) {