lua: print lua script func/line/file in SCLog* funcs

Instead of printing the func/line/file of the C code SCLog* wrappers,
print them from inside the lua script. They are not always available.
pull/2020/head
Victor Julien 9 years ago
parent 1c8775b340
commit 554080cced

@ -198,43 +198,37 @@ extern int sc_log_module_initialized;
extern int sc_log_module_cleaned;
#define SCLog(x, ...) \
#define SCLog(x, file, func, line, ...) \
do { \
if (sc_log_global_log_level >= x && \
(sc_log_fg_filters_present == 0 || \
SCLogMatchFGFilterWL(__FILE__, __FUNCTION__, __LINE__) == 1 || \
SCLogMatchFGFilterBL(__FILE__, __FUNCTION__, __LINE__) == 1) && \
SCLogMatchFGFilterWL(file, func, line) == 1 || \
SCLogMatchFGFilterBL(file, func, line) == 1) && \
(sc_log_fd_filters_present == 0 || \
SCLogMatchFDFilter(__FUNCTION__) == 1)) \
SCLogMatchFDFilter(func) == 1)) \
{ \
char _sc_log_msg[SC_LOG_MAX_LOG_MSG_LEN]; \
\
snprintf(_sc_log_msg, SC_LOG_MAX_LOG_MSG_LEN, __VA_ARGS__); \
\
SCLogMessage(x, \
__FILE__, \
__LINE__, \
__FUNCTION__, SC_OK, _sc_log_msg); \
SCLogMessage(x, file, line, func, SC_OK, _sc_log_msg); \
} \
} while(0)
#define SCLogErr(x, err, ...) \
#define SCLogErr(x, file, func, line, err, ...) \
do { \
if (sc_log_global_log_level >= x && \
(sc_log_fg_filters_present == 0 || \
SCLogMatchFGFilterWL(__FILE__, __FUNCTION__, __LINE__) == 1 || \
SCLogMatchFGFilterBL(__FILE__, __FUNCTION__, __LINE__) == 1) && \
SCLogMatchFGFilterWL(file, func, line) == 1 || \
SCLogMatchFGFilterBL(file, func, line) == 1) && \
(sc_log_fd_filters_present == 0 || \
SCLogMatchFDFilter(__FUNCTION__) == 1)) \
SCLogMatchFDFilter(func) == 1)) \
{ \
char _sc_log_msg[SC_LOG_MAX_LOG_MSG_LEN]; \
\
snprintf(_sc_log_msg, SC_LOG_MAX_LOG_MSG_LEN, __VA_ARGS__); \
\
SCLogMessage(x, \
__FILE__, \
__LINE__, \
__FUNCTION__, err, _sc_log_msg); \
SCLogMessage(x, file, line, func, err, _sc_log_msg); \
} \
} while(0)
@ -243,14 +237,20 @@ extern int sc_log_module_cleaned;
*
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogInfo(...) SCLog(SC_LOG_INFO, __VA_ARGS__)
#define SCLogInfo(...) SCLog(SC_LOG_INFO, \
__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define SCLogInfoRaw(file, func, line, ...) SCLog(SC_LOG_INFO, \
(file), (func), (line), __VA_ARGS__)
/**
* \brief Macro used to log NOTICE messages.
*
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogNotice(...) SCLog(SC_LOG_NOTICE, __VA_ARGS__)
#define SCLogNotice(...) SCLog(SC_LOG_NOTICE, \
__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
#define SCLogNoticeRaw(file, func, line, ... ) SCLog(SC_LOG_NOTICE, \
(file), (func), (line), __VA_ARGS__)
/**
* \brief Macro used to log WARNING messages.
@ -259,8 +259,12 @@ extern int sc_log_module_cleaned;
* warning message
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogWarning(err_code, ...) SCLogErr(SC_LOG_WARNING, err_code, \
__VA_ARGS__)
#define SCLogWarning(err_code, ...) SCLogErr(SC_LOG_WARNING, \
__FILE__, __FUNCTION__, __LINE__, \
err_code, __VA_ARGS__)
#define SCLogWarningRaw(err_code, file, func, line, ...) \
SCLogErr(SC_LOG_WARNING, (file), (func), (line), err_code, __VA_ARGS__)
/**
* \brief Macro used to log ERROR messages.
*
@ -268,8 +272,12 @@ extern int sc_log_module_cleaned;
* error message
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogError(err_code, ...) SCLogErr(SC_LOG_ERROR, err_code, \
__VA_ARGS__)
#define SCLogError(err_code, ...) SCLogErr(SC_LOG_ERROR, \
__FILE__, __FUNCTION__, __LINE__, \
err_code, __VA_ARGS__)
#define SCLogErrorRaw(err_code, file, func, line, ...) SCLogErr(SC_LOG_ERROR, \
(file), (func), (line), err_code, __VA_ARGS__)
/**
* \brief Macro used to log CRITICAL messages.
*
@ -277,8 +285,9 @@ extern int sc_log_module_cleaned;
* critical message
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogCritical(err_code, ...) SCLogErr(SC_LOG_CRITICAL, err_code, \
__VA_ARGS__)
#define SCLogCritical(err_code, ...) SCLogErr(SC_LOG_CRITICAL, \
__FILE__, __FUNCTION__, __LINE__, \
err_code, __VA_ARGS__)
/**
* \brief Macro used to log ALERT messages.
*
@ -286,8 +295,9 @@ extern int sc_log_module_cleaned;
* alert message
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogAlert(err_code, ...) SCLogErr(SC_LOG_ALERT, err_code, \
__VA_ARGS__)
#define SCLogAlert(err_code, ...) SCLogErr(SC_LOG_ALERT, \
__FILE__, __FUNCTION__, __LINE__, \
err_code, __VA_ARGS__)
/**
* \brief Macro used to log EMERGENCY messages.
*
@ -295,8 +305,9 @@ extern int sc_log_module_cleaned;
* emergency message
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogEmerg(err_code, ...) SCLogErr(SC_LOG_EMERGENCY, err_code, \
__VA_ARGS__)
#define SCLogEmerg(err_code, ...) SCLogErr(SC_LOG_EMERGENCY, \
__FILE__, __FUNCTION__, __LINE__, \
err_code, __VA_ARGS__)
/* Avoid the overhead of using the debugging subsystem, in production mode */
@ -332,7 +343,7 @@ extern int sc_log_module_cleaned;
*
* \retval ... Takes as argument(s), a printf style format message
*/
#define SCLogDebug(...) SCLog(SC_LOG_DEBUG, __VA_ARGS__)
#define SCLogDebug(...) SCLog(SC_LOG_DEBUG, __FILE__, __FUNCTION__, __LINE__, __VA_ARGS__)
/**
* \brief Macro used to log debug messages on function entry. Comes under the

@ -545,7 +545,12 @@ static int LuaCallbackLogInfo(lua_State *luastate)
const char *msg = LuaGetStringArgument(luastate, 1);
if (msg == NULL)
return LuaCallbackError(luastate, "1st argument missing, empty or wrong type");
SCLogInfo("%s", msg);
lua_Debug ar;
lua_getstack(luastate, 1, &ar);
lua_getinfo(luastate, "nSl", &ar);
const char *funcname = ar.name ? ar.name : ar.what;
SCLogInfoRaw(ar.short_src, funcname, ar.currentline, "%s", msg);
return 0;
}
@ -554,7 +559,12 @@ static int LuaCallbackLogNotice(lua_State *luastate)
const char *msg = LuaGetStringArgument(luastate, 1);
if (msg == NULL)
return LuaCallbackError(luastate, "1st argument missing, empty or wrong type");
SCLogNotice("%s", msg);
lua_Debug ar;
lua_getstack(luastate, 1, &ar);
lua_getinfo(luastate, "nSl", &ar);
const char *funcname = ar.name ? ar.name : ar.what;
SCLogNoticeRaw(ar.short_src, funcname, ar.currentline, "%s", msg);
return 0;
}
@ -563,7 +573,12 @@ static int LuaCallbackLogWarning(lua_State *luastate)
const char *msg = LuaGetStringArgument(luastate, 1);
if (msg == NULL)
return LuaCallbackError(luastate, "1st argument missing, empty or wrong type");
SCLogWarning(SC_WARN_LUA_SCRIPT, "%s", msg);
lua_Debug ar;
lua_getstack(luastate, 1, &ar);
lua_getinfo(luastate, "nSl", &ar);
const char *funcname = ar.name ? ar.name : ar.what;
SCLogWarningRaw(SC_WARN_LUA_SCRIPT, ar.short_src, funcname, ar.currentline, "%s", msg);
return 0;
}
@ -572,7 +587,11 @@ static int LuaCallbackLogError(lua_State *luastate)
const char *msg = LuaGetStringArgument(luastate, 1);
if (msg == NULL)
return LuaCallbackError(luastate, "1st argument missing, empty or wrong type");
SCLogError(SC_ERR_LUA_SCRIPT, "%s", msg);
lua_Debug ar;
lua_getstack(luastate, 1, &ar);
lua_getinfo(luastate, "nSl", &ar);
const char *funcname = ar.name ? ar.name : ar.what;
SCLogErrorRaw(SC_ERR_LUA_SCRIPT, ar.short_src, funcname, ar.currentline, "%s", msg);
return 0;
}

Loading…
Cancel
Save