nginx-0.0.2-2004-02-11-20:08:49 import
diff --git a/src/http/modules/ngx_http_gzip_filter.c b/src/http/modules/ngx_http_gzip_filter.c
index fae9c9e..34d872c 100644
--- a/src/http/modules/ngx_http_gzip_filter.c
+++ b/src/http/modules/ngx_http_gzip_filter.c
@@ -377,9 +377,11 @@
                 ctx->zstream.avail_out = conf->bufs.size;
             }
 
-ngx_log_debug(r->connection->log, "deflate(): %08x %08x %d %d %d" _
-              ctx->zstream.next_in _ ctx->zstream.next_out _
-              ctx->zstream.avail_in _ ctx->zstream.avail_out _ ctx->flush);
+            ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "deflate in: ni:%X no:%X ai:%d ao:%d fl:%d",
+                           ctx->zstream.next_in, ctx->zstream.next_out,
+                           ctx->zstream.avail_in, ctx->zstream.avail_out,
+                           ctx->flush);
 
             rc = deflate(&ctx->zstream, ctx->flush);
             if (rc != Z_OK && rc != Z_STREAM_END) {
@@ -388,9 +390,11 @@
                 return ngx_http_gzip_error(ctx);
             }
 
-ngx_log_debug(r->connection->log, "DEFLATE(): %08x %08x %d %d %d" _
-              ctx->zstream.next_in _ ctx->zstream.next_out _
-              ctx->zstream.avail_in _ ctx->zstream.avail_out _ rc);
+            ngx_log_debug5(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "deflate out: ni:%X no:%X ai:%d ao:%d rc:%d",
+                           ctx->zstream.next_in, ctx->zstream.next_out,
+                           ctx->zstream.avail_in, ctx->zstream.avail_out,
+                           rc);
 
             ctx->in_hunk->pos = (char *) ctx->zstream.next_in;
             ctx->out_hunk->last = (char *) ctx->zstream.next_out;
@@ -512,7 +516,6 @@
     int    alloc;
     void  *p;
 
-
     alloc = items * size;
     if (alloc % 512 != 0) {
 
@@ -527,10 +530,9 @@
         ctx->free_mem += alloc;
         ctx->allocated -= alloc;
 
-#if 1
-        ngx_log_debug(ctx->request->connection->log, "ALLOC: %d:%d:%d:%08X" _
-                      items _ size _ alloc _ p);
-#endif
+        ngx_log_debug4(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
+                       "gzip alloc: n:%d s:%d a:%d p:%08X",
+                       items, size, alloc, p);
 
         return p;
     }
@@ -550,7 +552,8 @@
     ngx_http_gzip_ctx_t *ctx = opaque;
 
 #if 0
-    ngx_log_debug(ctx->request->connection->log, "FREE: %08X" _ address);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ctx->request->connection->log, 0,
+                   "gzip free: %X", address);
 #endif
 }
 
diff --git a/src/http/modules/ngx_http_index_handler.c b/src/http/modules/ngx_http_index_handler.c
index edcf54a..029843e 100644
--- a/src/http/modules/ngx_http_index_handler.c
+++ b/src/http/modules/ngx_http_index_handler.c
@@ -286,7 +286,8 @@
     ctx->path.data[ctx->path.len - 1] = '\0';
     ctx->path.data[ctx->path.len] = '\0';
 
-ngx_log_debug(r->connection->log, "IS_DIR: %s" _ ctx->path.data);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http check dir: \"%s\"", ctx->path.data);
 
     if (ngx_file_info(ctx->path.data, &r->file.info) == -1) {
 
diff --git a/src/http/modules/ngx_http_not_modified_filter.c b/src/http/modules/ngx_http_not_modified_filter.c
index 11cc21c..e1a961f 100644
--- a/src/http/modules/ngx_http_not_modified_filter.c
+++ b/src/http/modules/ngx_http_not_modified_filter.c
@@ -49,8 +49,8 @@
     ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
                               r->headers_in.if_modified_since->value.len);
     
-    ngx_log_debug(r->connection->log, "%d %d" _
-                  ims _ r->headers_out.last_modified_time);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http ims:%d lm:%d", ims, r->headers_out.last_modified_time);
 
     /*
      * I think that the equality of the dates is correcter
diff --git a/src/http/modules/ngx_http_static_handler.c b/src/http/modules/ngx_http_static_handler.c
index 617bb4d..6997471 100644
--- a/src/http/modules/ngx_http_static_handler.c
+++ b/src/http/modules/ngx_http_static_handler.c
@@ -59,7 +59,8 @@
     char                        *last;
     uint32_t                     file_crc, redirect_crc;
     ngx_fd_t                     fd;
-    ngx_int_t                    rc, level;
+    ngx_int_t                    rc;
+    ngx_uint_t                   level;
     ngx_str_t                    name, location;
     ngx_err_t                    err;
     ngx_log_t                   *log;
diff --git a/src/http/modules/proxy/ngx_http_proxy_cache.c b/src/http/modules/proxy/ngx_http_proxy_cache.c
index 9661cff..ce2226d 100644
--- a/src/http/modules/proxy/ngx_http_proxy_cache.c
+++ b/src/http/modules/proxy/ngx_http_proxy_cache.c
@@ -167,8 +167,9 @@
 
     ngx_cpystrn(c->status_line.data, p->status_start, c->status_line.len + 1);
 
-    ngx_log_debug(r->connection->log, "http cache status %d '%s'" _ 
-                  c->status _ c->status_line.data);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http cache status %d \"%s\"", 
+                   c->status, c->status_line.data);
 
     /* TODO: ngx_init_table */
     c->headers_in.headers = ngx_create_table(r->pool, 20);
@@ -212,8 +213,9 @@
                 }
             }
 
-            ngx_log_debug(r->connection->log, "HTTP cache header: '%s: %s'" _
-                          h->key.data _ h->value.data);
+            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "http cache header: \"%s: %s\"",
+                           h->key.data, h->value.data);
 
             continue;
 
@@ -221,7 +223,8 @@
 
             /* a whole header has been parsed successfully */
 
-            ngx_log_debug(r->connection->log, "HTTP header done");
+            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                           "http cache header done");
 
             c->ctx.file_start = p->header_in->pos - p->header_in->start;
 
@@ -253,7 +256,8 @@
     rc = ngx_http_busy_lock_cachable(p->lcf->busy_lock, &p->busy_lock,
                                      p->try_busy_lock);
 
-ngx_log_debug(p->request->connection->log, "LOCK CACHABLE: %d" _ rc);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
+                   "http cache busy lock cachable: %d", rc);
 
     if (rc == NGX_OK) {
         if (p->try_busy_lock) {
@@ -354,8 +358,9 @@
         return;
     }
 
-ngx_log_debug(p->request->connection->log, "OLD: %d, NEW: %d" _
-              p->cache->ctx.file.fd _ ctx->file.fd);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
+                   "http cache old fd:%d, new fd:%d",
+                   p->cache->ctx.file.fd, ctx->file.fd);
 
     if (p->cache->ctx.file.fd != NGX_INVALID_FILE) {
         if (ngx_close_file(p->cache->ctx.file.fd) == NGX_FILE_ERROR) {
@@ -603,8 +608,9 @@
 
     ep = p->upstream->event_pipe;
 
-ngx_log_debug(p->request->connection->log, "LEN: " OFF_T_FMT ", " OFF_T_FMT _
-              p->cache->ctx.length _ ep->read_length);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
+                   "http cache update len: " OFF_T_FMT ":" OFF_T_FMT,
+                   p->cache->ctx.length, ep->read_length);
 
     if (p->cache->ctx.length == -1) {
         /* TODO: test rc */
diff --git a/src/http/modules/proxy/ngx_http_proxy_handler.c b/src/http/modules/proxy/ngx_http_proxy_handler.c
index 84396a9..59b1c06 100644
--- a/src/http/modules/proxy/ngx_http_proxy_handler.c
+++ b/src/http/modules/proxy/ngx_http_proxy_handler.c
@@ -346,7 +346,7 @@
     ngx_http_request_t    *r;
     ngx_http_proxy_ctx_t  *p;
 
-    ngx_log_debug(wev->log, "http proxy check client");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http proxy check client");
 
     c = wev->data;
     r = c->data;
@@ -362,14 +362,16 @@
 
         if (!p->cachable && p->upstream->peer.connection) {
             ngx_log_error(NGX_LOG_INFO, wev->log, wev->kq_errno,
-                          "client closed prematurely connection, "
+                          "kevent() reported that client have closed "
+                          "prematurely connection, "
                           "so upstream connection is closed too");
             ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
             return;
         }
 
         ngx_log_error(NGX_LOG_INFO, wev->log, wev->kq_errno,
-                      "client closed prematurely connection");
+                      "kevent() reported that client have closed "
+                      "prematurely connection");
 
         if (p->upstream == NULL || p->upstream->peer.connection == NULL) {
             ngx_http_proxy_finalize_request(p, NGX_HTTP_CLIENT_CLOSED_REQUEST);
@@ -385,7 +387,7 @@
     ngx_http_request_t    *r;
     ngx_http_proxy_ctx_t  *p;
 
-    ngx_log_debug(rev->log, "busy lock");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http proxy busy lock");
 
     c = rev->data;
     r = c->data;
@@ -412,11 +414,12 @@
         return;
     }
 
-    ngx_log_debug(rev->log, "client sent while busy lock");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
+                   "http proxy: client sent while busy lock");
 
     /*
      * TODO: kevent() notify about error, otherwise we need to
-     * call ngx_peek(): recv(MSG_PEEK) to get errno. THINK about aio
+     * call ngx_peek(): recv(MSG_PEEK) to get errno. THINK about aio.
      * if there's no error we need to disable event.
      */
 
@@ -452,7 +455,8 @@
 
     r = p->request;
 
-    ngx_log_debug(r->connection->log, "finalize http proxy request");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "finalize http proxy request");
 
     if (p->upstream && p->upstream->peer.connection) {
         ngx_http_proxy_close_connection(p);
@@ -470,12 +474,15 @@
     }
 
     if (p->upstream && p->upstream->event_pipe) {
-ngx_log_debug(r->connection->log, "TEMP FD: %d" _
-              p->upstream->event_pipe->temp_file->file.fd);
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http proxy temp fd: %d",
+                       p->upstream->event_pipe->temp_file->file.fd);
     }
 
     if (p->cache) {
-ngx_log_debug(r->connection->log, "CACHE FD: %d" _ p->cache->ctx.file.fd);
+        ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http proxy cache fd: %d",
+                       p->cache->ctx.file.fd);
     }
 
     if (p->upstream && p->upstream->event_pipe) {
@@ -504,7 +511,8 @@
         p->lcf->busy_lock->busy--;
     }
 
-    ngx_log_debug(c->log, "proxy close connection: %d" _ c->fd);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
+                   "http proxy close connection: %d", c->fd);
 
     if (c->fd == -1) {
 #if 0
diff --git a/src/http/modules/proxy/ngx_http_proxy_upstream.c b/src/http/modules/proxy/ngx_http_proxy_upstream.c
index d36cbee..a65b864 100644
--- a/src/http/modules/proxy/ngx_http_proxy_upstream.c
+++ b/src/http/modules/proxy/ngx_http_proxy_upstream.c
@@ -192,15 +192,19 @@
 
         *(h->last++) = CR; *(h->last++) = LF;
 
-        ngx_log_debug(r->connection->log, "proxy: '%s: %s'" _
-                      header[i].key.data _ header[i].value.data);
+        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http proxy header: \"%s: %s\"",
+                       header[i].key.data, header[i].value.data);
     }
 
     /* add "\r\n" at the header end */
     *(h->last++) = CR; *(h->last++) = LF;
 
-    /* STUB */ *(h->last) = '\0';
-    ngx_log_debug(r->connection->log, "PROXY:\n'%s'" _ h->pos);
+#if (NGX_DEBUG)
+    *(h->last) = '\0';
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http proxy header:\n\"%s\"", h->pos);
+#endif
 
     return chain;
 }
@@ -218,8 +222,9 @@
 
     r = p->request;
 
-ngx_log_debug(r->connection->log, "timer_set: %d" _
-              r->connection->read->timer_set);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                  "http proxy set timer: %d",
+                  r->connection->read->timer_set);
 
     if (r->connection->read->timer_set) {
         ngx_del_timer(r->connection->read);
@@ -588,7 +593,7 @@
 
 static void ngx_http_proxy_dummy_handler(ngx_event_t *wev)
 {
-    ngx_log_debug(wev->log, "dummy handler");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0, "http proxy dummy handler");
 }
 
 
@@ -603,7 +608,8 @@
     p = c->data;
     p->action = "reading upstream status line";
 
-    ngx_log_debug(rev->log, "http proxy process status line");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
+                   "http proxy process status line");
 
     if (rev->timedout) {
         ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT);
@@ -717,8 +723,9 @@
     ngx_cpystrn(p->upstream->status_line.data, p->status_start,
                 p->upstream->status_line.len + 1);
 
-    ngx_log_debug(rev->log, "http proxy status %d '%s'" _
-                  p->upstream->status _ p->upstream->status_line.data);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, rev->log, 0,
+                   "http proxy status %d \"%s\"",
+                   p->upstream->status, p->upstream->status_line.data);
 
     if (p->upstream->headers_in.headers) {
         p->upstream->headers_in.headers->nelts = 0;
@@ -747,7 +754,8 @@
     r = p->request;
     p->action = "reading upstream headers";
 
-    ngx_log_debug(rev->log, "http proxy process header line");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
+                   "http proxy process header line");
 
     if (rev->timedout) {
         ngx_http_proxy_next_upstream(p, NGX_HTTP_PROXY_FT_TIMEOUT);
@@ -818,8 +826,9 @@
                 }
             }
 
-            ngx_log_debug(c->log, "HTTP proxy header: '%s: %s'" _
-                          h->key.data _ h->value.data);
+            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
+                           "http proxy header: \"%s: %s\"",
+                           h->key.data, h->value.data);
 
             continue;
 
@@ -827,7 +836,8 @@
 
             /* a whole header has been parsed successfully */
 
-            ngx_log_debug(c->log, "HTTP header done");
+            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
+                           "http proxy header done");
 
             /* TODO: hook to process the upstream header */
 
@@ -1072,13 +1082,15 @@
     c = ev->data;
 
     if (ev->write) {
-        ngx_log_debug(ev->log, "http proxy process downstream");
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
+                       "http proxy process downstream");
         r = c->data;
         p = ngx_http_get_module_ctx(r, ngx_http_proxy_module);
         p->action = "sending to client";
 
     } else {
-        ngx_log_debug(ev->log, "http proxy process upstream");
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
+                       "http proxy process upstream");
         p = c->data;
         r = p->request;
         p->action = "reading upstream body";
@@ -1125,7 +1137,8 @@
         }
 
         if (ep->upstream_done || ep->upstream_eof || ep->upstream_error) {
-            ngx_log_debug(ev->log, "http proxy upstream exit");
+            ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
+                           "http proxy upstream exit");
             ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
             ngx_http_proxy_finalize_request(p, 0);
             return;
@@ -1133,30 +1146,12 @@
     }
 
     if (ep->downstream_error) {
-        ngx_log_debug(ev->log, "http proxy downstream error");
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0,
+                       "http proxy downstream error");
         if (!p->cachable && p->upstream->peer.connection) {
             ngx_http_proxy_finalize_request(p, 0);
         }
     }
-
-#if 0
-    if (ep->downstream_done) {
-        ngx_log_debug(ev->log, "http proxy downstream done");
-        ngx_http_proxy_finalize_request(p, 0);
-        return;
-    }
-
-    if (ep->downstream_error) {
-        ngx_log_debug(ev->log, "http proxy downstream error");
-        if (!p->cachable && p->upstream->peer.connection) {
-            ngx_http_proxy_close_connection(p);
-        }
- 
-        if (p->upstream->peer.connection == NULL) {
-            ngx_http_close_request(r);
-        }
-    }
-#endif
 }
 
 
@@ -1164,7 +1159,8 @@
 {
     int  status;
 
-ngx_log_debug(p->request->connection->log, "next upstream: %d" _ ft_type);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, p->request->connection->log, 0,
+                   "http proxy next upstream: %d", ft_type);
 
     ngx_http_busy_unlock(p->lcf->busy_lock, &p->busy_lock);
 
diff --git a/src/http/ngx_http.c b/src/http/ngx_http.c
index 0895814..234992d 100644
--- a/src/http/ngx_http.c
+++ b/src/http/ngx_http.c
@@ -589,23 +589,26 @@
         }
     }
 
-    /* DEBUG STUFF */
+#if (NGX_DEBUG)
     in_port = in_ports.elts;
     for (p = 0; p < in_ports.nelts; p++) {
-ngx_log_debug(cf->log, "port: %d %08x" _ in_port[p].port _ &in_port[p]);
+        ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
+                      "port: %d %08x", in_port[p].port, &in_port[p]);
         in_addr = in_port[p].addrs.elts;
         for (a = 0; a < in_port[p].addrs.nelts; a++) {
             char ip[20];
             ngx_inet_ntop(AF_INET, (char *) &in_addr[a].addr, ip, 20);
-ngx_log_debug(cf->log, "%s %08x" _ ip _ in_addr[a].core_srv_conf);
+            ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
+                           "%s %08x", ip, in_addr[a].core_srv_conf);
             s_name = in_addr[a].names.elts;
             for (n = 0; n < in_addr[a].names.nelts; n++) {
-ngx_log_debug(cf->log, "%s %08x" _ s_name[n].name.data _
-              s_name[n].core_srv_conf);
+                 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, cf->log, 0,
+                                "%s %08x", s_name[n].name.data,
+                                s_name[n].core_srv_conf);
             }
         }
     }
-    /**/
+#endif
 
     return NGX_CONF_OK;
 }
diff --git a/src/http/ngx_http_busy_lock.c b/src/http/ngx_http_busy_lock.c
index b4fdefe..30cec23 100644
--- a/src/http/ngx_http_busy_lock.c
+++ b/src/http/ngx_http_busy_lock.c
@@ -59,8 +59,9 @@
 
     rc = ngx_http_busy_lock_look_cachable(bl, bc, lock);
 
-ngx_log_debug(bc->event->log, "BUSYLOCK: %d %d:%d" _
-              rc _ bl->waiting _ bl->max_waiting);
+    ngx_log_debug3(NGX_LOG_DEBUG_HTTP, bc->event->log, 0,
+                   "http busylock: %d w:%d mw::%d",
+                   rc, bl->waiting, bl->max_waiting);
 
     if (rc == NGX_OK) {  /* no the same request, there's free slot */
         return NGX_OK;
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c
index ad5b3aa..20c7a55 100644
--- a/src/http/ngx_http_core_module.c
+++ b/src/http/ngx_http_core_module.c
@@ -305,7 +305,7 @@
     c = ev->data;
     r = c->data;
 
-    ngx_log_debug(ev->log, "phase event handler");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ev->log, 0, "phase event handler");
 
     ngx_http_run_phases(r);
 
@@ -612,19 +612,6 @@
 }
 
 
-int ngx_http_error(ngx_http_request_t *r, int error)
-{
-    /* STUB */
-    ngx_log_debug(r->connection->log, "http error: %d" _ error);
-
-    /* log request */
-
-    ngx_http_special_response_handler(r, error);
-    ngx_http_close_request(r, 0);
-    return NGX_OK;
-}
-
-
 ngx_int_t ngx_http_set_exten(ngx_http_request_t *r)
 {
     ngx_int_t  i;
@@ -706,13 +693,15 @@
     static int  on;
 
     if (on++ == 0) {
-        ngx_log_debug(r->connection->log, "SET http delay");
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "http set delay");
         ngx_add_timer(r->connection->write, 10000);
         return NGX_AGAIN;
     }
 
     r->connection->write->timedout = 0;
-    ngx_log_debug(r->connection->log, "RESET http delay");
+    ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http reset delay");
     return NGX_DECLINED;
 }
 
diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h
index 78de144..a6738e6 100644
--- a/src/http/ngx_http_core_module.h
+++ b/src/http/ngx_http_core_module.h
@@ -161,7 +161,6 @@
 
 int ngx_http_internal_redirect(ngx_http_request_t *r,
                                ngx_str_t *uri, ngx_str_t *args);
-int ngx_http_error(ngx_http_request_t *r, int error);
 
 
 #endif /* _NGX_HTTP_CORE_H_INCLUDED_ */
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
index b8a24db..038056f 100644
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -36,12 +36,14 @@
     ngx_md5_text(ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len,
                  ctx->md5);
 
-ngx_log_debug(r->connection->log, "URL: %s, md5: %s" _ ctx->key.data _
-              ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len);
+    ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+               "file cache uri: %s, md5: %s", ctx->key.data,
+               ctx->file.name.data + ctx->path->name.len + 1 + ctx->path->len);
 
     ngx_create_hashed_filename(&ctx->file, ctx->path);
 
-ngx_log_debug(r->connection->log, "FILE: %s" _ ctx->file.name.data);
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "file cache name: %s", ctx->file.name.data);
 
     /* TODO: look open files cache */
 
@@ -129,7 +131,10 @@
     ctx->buf->last += n;
 
     if (ctx->expires < ngx_time()) {
-ngx_log_debug(ctx->log, "EXPIRED");
+
+        ngx_log_debug0(NGX_LOG_DEBUG_HTTP, ctx->log, 0,
+                       "http file cache expired");
+
         return NGX_HTTP_CACHE_STALE;
     }
 
diff --git a/src/http/ngx_http_header_filter.c b/src/http/ngx_http_header_filter.c
index 8f8ffca..801ab99 100644
--- a/src/http/ngx_http_header_filter.c
+++ b/src/http/ngx_http_header_filter.c
@@ -333,10 +333,10 @@
         *(h->last++) = CR; *(h->last++) = LF;
     }
 
-    /* STUB */
+#if (NGX_DEBUG)
     *(h->last) = '\0';
-    ngx_log_debug(r->connection->log, "%s\n" _ h->pos);
-    /**/
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, "%s\n", h->pos);
+#endif
 
     /* the end of HTTP header */
     *(h->last++) = CR; *(h->last++) = LF;
diff --git a/src/http/ngx_http_headers.c b/src/http/ngx_http_headers.c
index 150ad1e..1287449 100644
--- a/src/http/ngx_http_headers.c
+++ b/src/http/ngx_http_headers.c
@@ -11,16 +11,17 @@
                          offsetof(ngx_http_headers_in_t, if_modified_since) },
     { ngx_string("User-Agent"), offsetof(ngx_http_headers_in_t, user_agent) },
     { ngx_string("Referer"), offsetof(ngx_http_headers_in_t, referer) },
-
     { ngx_string("Content-Length"),
                             offsetof(ngx_http_headers_in_t, content_length) },
-    { ngx_string("Accept-Encoding"),
-                           offsetof(ngx_http_headers_in_t, accept_encoding) },
+
     { ngx_string("Range"), offsetof(ngx_http_headers_in_t, range) },
 #if 0
     { ngx_string("If-Range"), offsetof(ngx_http_headers_in_t, if_range) },
 #endif
 
+    { ngx_string("Accept-Encoding"),
+                           offsetof(ngx_http_headers_in_t, accept_encoding) },
+
     { ngx_string("Authorization"),
                              offsetof(ngx_http_headers_in_t, authorization) },
 
diff --git a/src/http/ngx_http_parse.c b/src/http/ngx_http_parse.c
index 38ee9ec..ad9dac0 100644
--- a/src/http/ngx_http_parse.c
+++ b/src/http/ngx_http_parse.c
@@ -648,8 +648,8 @@
 
     while (p < r->uri_start + r->uri.len + 1) {
 
-ngx_log_debug(r->connection->log, "S: %d UN: '%x:%c', URI: '%c'" _
-              state _ ch _ ch _ *u);
+        ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                       "s:%d in:'%x:%c', out:'%c'", state, ch, ch, *u);
 
         switch (state) {
         case sw_usual:
diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
index ff53a7b..90605be 100644
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -84,7 +84,7 @@
     rev = c->read;
     rev->event_handler = ngx_http_init_request;
 
-    /* STUB: epoll */ c->write->event_handler = ngx_http_empty_handler;
+    /* STUB: epoll edge */ c->write->event_handler = ngx_http_empty_handler;
 
     if (rev->ready) {
         /* deferred accept, aio, iocp, epoll */
@@ -1180,6 +1180,8 @@
     }
 
     h = c->buffer;
+    wev = c->write;
+    wev->event_handler = ngx_http_empty_handler;
 
     if (h->pos < h->last) {
 
@@ -1214,8 +1216,6 @@
 
     h->pos = h->last = h->start;
     rev->event_handler = ngx_http_keepalive_handler;
-    wev = c->write;
-    wev->event_handler = ngx_http_empty_handler;
 
     if (wev->active) {
         if (ngx_event_flags & NGX_HAVE_KQUEUE_EVENT) {
@@ -1522,7 +1522,7 @@
 void ngx_http_close_connection(ngx_connection_t *c)
 {
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
-                   "close connection: %d", c->fd);
+                   "close http connection: %d", c->fd);
 
     if (c->pool == NULL) {
         ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed");
diff --git a/src/http/ngx_http_write_filter.c b/src/http/ngx_http_write_filter.c
index 271ed17..37e8abe 100644
--- a/src/http/ngx_http_write_filter.c
+++ b/src/http/ngx_http_write_filter.c
@@ -6,7 +6,7 @@
 
 
 typedef struct {
-    ssize_t  buffer_output;
+    ssize_t  postpone_output;
 } ngx_http_write_filter_conf_t;
 
 
@@ -23,11 +23,19 @@
 
 static ngx_command_t  ngx_http_write_filter_commands[] = {
 
+    /* STUB */
     { ngx_string("buffer_output"),
       NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
       ngx_conf_set_size_slot,
       NGX_HTTP_LOC_CONF_OFFSET,
-      offsetof(ngx_http_write_filter_conf_t, buffer_output),
+      offsetof(ngx_http_write_filter_conf_t, postpone_output),
+      NULL },
+
+    { ngx_string("postpone_output"),
+      NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
+      ngx_conf_set_size_slot,
+      NGX_HTTP_LOC_CONF_OFFSET,
+      offsetof(ngx_http_write_filter_conf_t, postpone_output),
       NULL },
 
       ngx_null_command
@@ -112,21 +120,19 @@
         }
     }
 
-#if (NGX_DEBUG_WRITE_FILTER)
-    ngx_log_debug(r->connection->log,
-                  "write filter: last:%d flush:%qd size:%qd" _
-                  last _ flush _ size);
-#endif
+    ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http write filter: l:%d f:" OFF_T_FMT " s:" OFF_T_FMT,
+                   last, flush, size);
 
     conf = ngx_http_get_module_loc_conf(r->main ? r->main : r,
                                         ngx_http_write_filter_module);
 
     /*
      * avoid the output if there is no last hunk, no flush point and
-     * the size of the hunks is smaller than "buffer_output" directive
+     * the size of the hunks is smaller than "postpone_output" directive
      */
 
-    if (!last && flush == 0 && size < conf->buffer_output) {
+    if (!last && flush == 0 && size < conf->postpone_output) {
         return NGX_OK;
     }
 
@@ -140,9 +146,8 @@
 
     chain = ngx_write_chain(r->connection, ctx->out);
 
-#if (NGX_DEBUG_WRITE_FILTER)
-    ngx_log_debug(r->connection->log, "write filter %x" _ chain);
-#endif
+    ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
+                   "http write filter %X", chain);
 
     if (chain == NGX_CHAIN_ERROR) {
         return NGX_ERROR;
@@ -166,7 +171,7 @@
                   ngx_palloc(cf->pool, sizeof(ngx_http_write_filter_conf_t)),
                   NULL);
 
-    conf->buffer_output = NGX_CONF_UNSET;
+    conf->postpone_output = NGX_CONF_UNSET;
 
     return conf;
 }
@@ -178,7 +183,8 @@
     ngx_http_write_filter_conf_t *prev = parent;
     ngx_http_write_filter_conf_t *conf = child;
 
-    ngx_conf_merge_size_value(conf->buffer_output, prev->buffer_output, 1460);
+    ngx_conf_merge_size_value(conf->postpone_output, prev->postpone_output,
+                              1460);
 
     return NULL;
 }