Skip to content

Commit

Permalink
optimize: now ngx.log is much faster when the log level argument is l…
Browse files Browse the repository at this point in the history
…ower than the actual error_log level specified in nginx.conf. thanks Matthieu Tourne for providing the patch.
  • Loading branch information
agentzh committed May 11, 2012
1 parent 02b1db9 commit eeb1816
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/ngx_http_lua_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ static int ngx_http_lua_print(lua_State *L);
static int ngx_http_lua_ngx_log(lua_State *L);


static int log_wrapper(ngx_http_request_t *r, const char *ident, int level,
lua_State *L);
static int log_wrapper(ngx_http_request_t *r, const char *ident,
ngx_uint_t level, lua_State *L);

static void ngx_http_lua_inject_log_consts(lua_State *L);


Expand All @@ -37,7 +38,7 @@ ngx_http_lua_ngx_log(lua_State *L)
/* remove log-level param from stack */
lua_remove(L, 1);

return log_wrapper(r, "", level, L);
return log_wrapper(r, "", (ngx_uint_t) level, L);
}

dd("(lua-log) can't output log due to invalid logging context!");
Expand Down Expand Up @@ -75,7 +76,8 @@ ngx_http_lua_print(lua_State *L)


static int
log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L)
log_wrapper(ngx_http_request_t *r, const char *ident, ngx_uint_t level,
lua_State *L)
{
u_char *buf;
u_char *p;
Expand All @@ -85,6 +87,10 @@ log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L)
int type;
const char *msg;

if (level > r->connection->log->log_level) {
return 0;
}

nargs = lua_gettop(L);
if (nargs == 0) {
buf = NULL;
Expand Down Expand Up @@ -185,7 +191,7 @@ log_wrapper(ngx_http_request_t *r, const char *ident, int level, lua_State *L)
*p++ = '\0';

done:
ngx_log_error((ngx_uint_t) level, r->connection->log, 0,
ngx_log_error(level, r->connection->log, 0,
"%s%s", ident, (buf == NULL) ? (u_char *) "(null)" : buf);
return 0;
}
Expand Down

0 comments on commit eeb1816

Please sign in to comment.