测试代码:
lua
#!/usr/bin/lua
require “lrsyslog”
print(“————————“)
losslog(“12|34|56|78|10000|gggggggggg|aaaaaaaaaaa|bbbbbbbbbbbbbbbb|ccccccccc|99999|222”)
——————————————————————————以下 lsyslog.c 代码片段———————————————————-
#include <syslog.h>
#include <ctype.h>
#include <string.h>
#include “lua.h”
#include “lualib.h”
#include “lauxlib.h”
static int l_lapplog(lua_State *L)
{
const char* log_content = luaL_checkstring(L, 1);
if (NULL == log_content) { return 0; }
syslog(LOG_DEBUG, “LAPPLOG|%s”, log_content);
return 0;
}
static int l_losslog(lua_State *L)
{
const char* log_content = luaL_checkstring(L, 1);
if (NULL == log_content) { return 0; }
syslog(LOG_DEBUG, “LOSSLOG|%s”, log_content);
return 0;
}
static const luaL_reg R[] =
{
{“losslog”,
l_losslog},
{“lapplog”,
l_lapplog},
{NULL,
NULL}
};
int luaopen_lrsyslog(lua_State *L)
{
lua_register(L, “losslog”, l_losslog);
lua_register(L, “lapplog”, l_lapplog);
return 0;
}