suricata
util-lua-log.c
Go to the documentation of this file.
1 /* Copyright (C) 2025 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 #include "suricata-common.h"
19 #include "util-lua-log.h"
20 #include "util-lua.h"
21 #include "util-debug.h"
22 
23 #include "lauxlib.h"
24 
25 static int LuaLogInfo(lua_State *L)
26 {
27  const char *msg = luaL_checkstring(L, 1);
28  SCLogInfo("%s", msg);
29  return 0;
30 }
31 
32 static int LuaLogNotice(lua_State *L)
33 {
34  const char *msg = luaL_checkstring(L, 1);
35  SCLogNotice("%s", msg);
36  return 0;
37 }
38 
39 static int LuaLogWarning(lua_State *L)
40 {
41  const char *msg = luaL_checkstring(L, 1);
42  SCLogWarning("%s", msg);
43  return 0;
44 }
45 
46 static int LuaLogError(lua_State *L)
47 {
48  const char *msg = luaL_checkstring(L, 1);
49  SCLogError("%s", msg);
50  return 0;
51 }
52 
53 static int LuaLogDebug(lua_State *L)
54 {
55 #ifdef DEBUG
56  const char *msg = luaL_checkstring(L, 1);
57  SCLogDebug("%s", msg);
58 #endif
59  return 0;
60 }
61 
62 static int LuaLogConfig(lua_State *L)
63 {
64  const char *msg = luaL_checkstring(L, 1);
65  SCLogConfig("%s", msg);
66  return 0;
67 }
68 
69 static int LuaLogPerf(lua_State *L)
70 {
71  const char *msg = luaL_checkstring(L, 1);
72  SCLogPerf("%s", msg);
73  return 0;
74 }
75 
76 static const struct luaL_Reg loglib[] = {
77  // clang-format off
78  { "info", LuaLogInfo },
79  { "notice", LuaLogNotice },
80  { "warning", LuaLogWarning },
81  { "error", LuaLogError },
82  { "debug", LuaLogDebug },
83  { "config", LuaLogConfig },
84  { "perf", LuaLogPerf },
85  { NULL, NULL }
86  // clang-format on
87 };
88 
90 {
91  luaL_newlib(L, loglib);
92  return 1;
93 }
util-lua-log.h
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:270
util-lua.h
SCLuaLoadLogLib
int SCLuaLoadLogLib(lua_State *L)
Definition: util-lua-log.c:89
lua_State
struct lua_State lua_State
Definition: suricata-common.h:523
util-debug.h
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:250
SCLogInfo
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Definition: util-debug.h:225
suricata-common.h
SCLogPerf
#define SCLogPerf(...)
Definition: util-debug.h:231
SCLogConfig
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:262
SCLogNotice
#define SCLogNotice(...)
Macro used to log NOTICE messages.
Definition: util-debug.h:238