comparison src/http/modules/ngx_http_log_module.c @ 571:458b6c3fea65 release-0.3.7

nginx-0.3.7-RELEASE import *) Feature: the "access_log" supports the "buffer=" parameter. *) Bugfix: nginx could not be built on platforms different from i386, amd64, sparc, and ppc; the bug had appeared in 0.3.2.
author Igor Sysoev <igor@sysoev.ru>
date Thu, 27 Oct 2005 15:46:13 +0000
parents 174f1e853e1e
children 58475592100c
comparison
equal deleted inserted replaced
570:2cdf120d8970 571:458b6c3fea65
94 NGX_HTTP_MAIN_CONF_OFFSET, 94 NGX_HTTP_MAIN_CONF_OFFSET,
95 0, 95 0,
96 NULL }, 96 NULL },
97 97
98 { ngx_string("access_log"), 98 { ngx_string("access_log"),
99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE12, 99 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE123,
100 ngx_http_log_set_log, 100 ngx_http_log_set_log,
101 NGX_HTTP_LOC_CONF_OFFSET, 101 NGX_HTTP_LOC_CONF_OFFSET,
102 0, 102 0,
103 NULL }, 103 NULL },
104 104
188 { 188 {
189 ngx_uint_t i, l; 189 ngx_uint_t i, l;
190 u_char *line, *p; 190 u_char *line, *p;
191 size_t len; 191 size_t len;
192 ngx_http_log_t *log; 192 ngx_http_log_t *log;
193 ngx_open_file_t *file;
193 ngx_http_log_op_t *op; 194 ngx_http_log_op_t *op;
194 ngx_http_log_loc_conf_t *lcf; 195 ngx_http_log_loc_conf_t *lcf;
195 #if (NGX_WIN32)
196 u_long written;
197 #endif
198 196
199 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 197 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
200 "http log handler"); 198 "http log handler");
201 199
202 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module); 200 lcf = ngx_http_get_module_loc_conf(r, ngx_http_log_module);
217 } else { 215 } else {
218 len += op[i].len; 216 len += op[i].len;
219 } 217 }
220 } 218 }
221 219
222 #if (NGX_WIN32) 220 len += NGX_LINEFEED_SIZE;
223 len += 2; 221
224 #else 222 file = log[l].file;
225 len++; 223
226 #endif 224 if (file->buffer) {
225
226 if (len > (size_t) (file->last - file->pos)) {
227
228 ngx_write_fd(file->fd, file->buffer, file->pos - file->buffer);
229
230 file->pos = file->buffer;
231 }
232
233 if (len <= (size_t) (file->last - file->pos)) {
234
235 p = file->pos;
236
237 for (i = 0; i < log[l].ops->nelts; i++) {
238 p = op[i].run(r, p, &op[i]);
239 }
240
241 ngx_linefeed(p);
242
243 file->pos = p;
244
245 continue;
246 }
247 }
227 248
228 line = ngx_palloc(r->pool, len); 249 line = ngx_palloc(r->pool, len);
229 if (line == NULL) { 250 if (line == NULL) {
230 return NGX_ERROR; 251 return NGX_ERROR;
231 } 252 }
234 255
235 for (i = 0; i < log[l].ops->nelts; i++) { 256 for (i = 0; i < log[l].ops->nelts; i++) {
236 p = op[i].run(r, p, &op[i]); 257 p = op[i].run(r, p, &op[i]);
237 } 258 }
238 259
239 #if (NGX_WIN32) 260 ngx_linefeed(p);
240 *p++ = CR; *p++ = LF; 261
241 WriteFile(log[l].file->fd, line, p - line, &written, NULL); 262 ngx_write_fd(file->fd, line, p - line);
242 #else
243 *p++ = LF;
244 write(log[l].file->fd, line, p - line);
245 #endif
246 } 263 }
247 264
248 return NGX_OK; 265 return NGX_OK;
249 } 266 }
250 267
940 static char * 957 static char *
941 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 958 ngx_http_log_set_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
942 { 959 {
943 ngx_http_log_loc_conf_t *llcf = conf; 960 ngx_http_log_loc_conf_t *llcf = conf;
944 961
962 ssize_t buf;
945 ngx_uint_t i; 963 ngx_uint_t i;
946 ngx_str_t *value, name; 964 ngx_str_t *value, name;
947 ngx_http_log_t *log; 965 ngx_http_log_t *log;
948 ngx_http_log_fmt_t *fmt; 966 ngx_http_log_fmt_t *fmt;
949 ngx_http_log_main_conf_t *lmcf; 967 ngx_http_log_main_conf_t *lmcf;
972 log->file = ngx_conf_open_file(cf->cycle, &value[1]); 990 log->file = ngx_conf_open_file(cf->cycle, &value[1]);
973 if (log->file == NULL) { 991 if (log->file == NULL) {
974 return NGX_CONF_ERROR; 992 return NGX_CONF_ERROR;
975 } 993 }
976 994
977 if (cf->args->nelts == 3) { 995 if (cf->args->nelts >= 3) {
978 name = value[2]; 996 name = value[2];
979 } else { 997 } else {
980 name.len = sizeof("combined") - 1; 998 name.len = sizeof("combined") - 1;
981 name.data = (u_char *) "combined"; 999 name.data = (u_char *) "combined";
982 } 1000 }
985 for (i = 0; i < lmcf->formats.nelts; i++) { 1003 for (i = 0; i < lmcf->formats.nelts; i++) {
986 if (fmt[i].name.len == name.len 1004 if (fmt[i].name.len == name.len
987 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0) 1005 && ngx_strcasecmp(fmt[i].name.data, name.data) == 0)
988 { 1006 {
989 log->ops = fmt[i].ops; 1007 log->ops = fmt[i].ops;
990 return NGX_CONF_OK; 1008 goto buffer;
991 } 1009 }
992 } 1010 }
993 1011
994 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, 1012 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
995 "unknown log format \"%V\"", &name); 1013 "unknown log format \"%V\"", &name);
996
997 return NGX_CONF_ERROR; 1014 return NGX_CONF_ERROR;
1015
1016 buffer:
1017
1018 if (cf->args->nelts == 4) {
1019 if (ngx_strncmp(value[3].data, "buffer=", 7) != 0) {
1020 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1021 "invalid parameter \"%V\"", &value[3]);
1022 return NGX_CONF_ERROR;
1023 }
1024
1025 name.len = value[3].len - 7;
1026 name.data = value[3].data + 7;
1027
1028 buf = ngx_parse_size(&name);
1029
1030 if (buf == NGX_ERROR) {
1031 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1032 "invalid parameter \"%V\"", &value[3]);
1033 return NGX_CONF_ERROR;
1034 }
1035
1036 if (log->file->buffer && log->file->last - log->file->pos != buf) {
1037 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
1038 "access_log \"%V\" already defined "
1039 "with different buffer size", &value[1]);
1040 return NGX_CONF_ERROR;
1041 }
1042
1043 log->file->buffer = ngx_palloc(cf->pool, buf);
1044 if (log->file->buffer == NULL) {
1045 return NGX_CONF_ERROR;
1046 }
1047
1048 log->file->pos = log->file->buffer;
1049 log->file->last = log->file->buffer + buf;
1050 }
1051
1052 return NGX_CONF_OK;
998 } 1053 }
999 1054
1000 1055
1001 static char * 1056 static char *
1002 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1057 ngx_http_log_set_format(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)