Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syslog improvements #325

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions components/lua/modules/sys/loslib_adds.inc
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,33 @@ static int os_setrsyslog(lua_State *L) {
}
#endif

#if CONFIG_LUA_RTOS_LUA_USE_MQTT
static int os_setmsyslog(lua_State *L) {
if (lua_gettop(L) > 0) {
if (lua_type(L, 1) == LUA_TNIL) {
syslog_setlogmqtt(0, NULL);
return 0;
}
const char *topic = luaL_optstring(L, 2, NULL); //order matters
luaL_checktype(L, 1, LUA_TUSERDATA);
lua_pushvalue(L, 1);
int mqtt_ref = luaL_ref(L, LUA_REGISTRYINDEX);
const int ret = syslog_setlogmqtt(mqtt_ref, topic);
if (ret) {
lua_rawgeti(L, LUA_REGISTRYINDEX, ret);
return 1;
}
return 0;
}
const int ret = syslog_getlogmqtt();
if (ret) {
lua_rawgeti(L, LUA_REGISTRYINDEX, ret);
return 1;
}
return 0;
}
#endif

static int os_stats(lua_State *L) {
const char *stat = luaL_optstring(L, 1, NULL);

Expand Down
3 changes: 3 additions & 0 deletions components/lua/src/loslib.c
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ static const LUA_REG_TYPE syslib[] =
{ LSTRKEY( "syslog" ), LFUNCVAL( os_syslog ) },
#if CONFIG_LUA_RTOS_USE_RSYSLOG
{ LSTRKEY( "rsyslog" ), LFUNCVAL( os_setrsyslog ) },
#endif
#if CONFIG_LUA_RTOS_LUA_USE_MQTT
{ LSTRKEY( "msyslog" ), LFUNCVAL( os_setmsyslog ) },
#endif
{ LSTRKEY( "stats" ), LFUNCVAL( os_stats ) },
{ LSTRKEY( "format" ), LFUNCVAL( os_format ) },
Expand Down
7 changes: 7 additions & 0 deletions components/sys/sys/syslog.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,12 @@ void syslog(int, const char *, ...);
void vsyslog(int, const char *, va_list);
int getlogmask();
int getlogstat();
#if CONFIG_LUA_RTOS_USE_RSYSLOG
const char *syslog_setloghost (const char *host);
const char *syslog_getloghost ();
#endif
#if CONFIG_LUA_RTOS_LUA_USE_MQTT
int syslog_setlogmqtt (const int mqtt_ref, const char *topic);
int syslog_getlogmqtt ();
#endif

Loading