Skip to content

Commit a332884

Browse files
committed
Implement debug logging in Lua
Also change it to use X macros internally
1 parent 03b769f commit a332884

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/lib/lwan-lua.c

+9-15
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,9 @@ LWAN_LUA_METHOD(request_date)
346346
return 1;
347347
}
348348

349-
#define IMPLEMENT_LOG_FUNCTION(name) \
349+
#define FOR_EACH_LOG_FUNCTION(X) X(info) X(warning) X(error) X(critical) X(debug)
350+
351+
#define IMPLEMENT_FUNCTION(name) \
350352
static int lwan_lua_log_##name(lua_State *L) \
351353
{ \
352354
size_t log_str_len = 0; \
@@ -355,26 +357,18 @@ LWAN_LUA_METHOD(request_date)
355357
lwan_status_##name("%.*s", (int)log_str_len, log_str); \
356358
return 0; \
357359
}
358-
359-
IMPLEMENT_LOG_FUNCTION(info)
360-
IMPLEMENT_LOG_FUNCTION(warning)
361-
IMPLEMENT_LOG_FUNCTION(error)
362-
IMPLEMENT_LOG_FUNCTION(critical)
363-
364-
#undef IMPLEMENT_LOG_FUNCTION
360+
FOR_EACH_LOG_FUNCTION(IMPLEMENT_FUNCTION)
361+
#undef IMPLEMENT_FUNCTION
365362

366363
static int luaopen_log(lua_State *L)
367364
{
368365
static const char *metatable_name = "Lwan.log";
366+
#define LOG_FUNCTION(name) {#name, lwan_lua_log_##name},
369367
static const struct luaL_Reg functions[] = {
370-
#define LOG_FUNCTION(name) {#name, lwan_lua_log_##name}
371-
LOG_FUNCTION(info),
372-
LOG_FUNCTION(warning),
373-
LOG_FUNCTION(error),
374-
LOG_FUNCTION(critical),
375-
{},
376-
#undef LOG_FUNCTION
368+
FOR_EACH_LOG_FUNCTION(LOG_FUNCTION)
369+
{}
377370
};
371+
#undef LOG_FUNCTION
378372

379373
luaL_newmetatable(L, metatable_name);
380374
luaL_register(L, metatable_name, functions);

src/lib/lwan-status.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
__attribute__((noinline,cold)) \
2727
__VA_ARGS__;
2828

29-
#define lwan_status_debug(fmt, ...)
29+
#define lwan_status_debug(fmt, ...) do {} while(0)
3030
#else
3131
#define DECLARE_STATUS_PROTO(type_, ...) \
3232
void lwan_status_##type_##_debug(const char *file, const int line, \

0 commit comments

Comments
 (0)