Skip to content

Commit 2161ae0

Browse files
committed
feat: add lua method for umd_log
1 parent 31118e5 commit 2161ae0

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/services/sysagent/umlua.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ int mink_lua_do_perf_set(lua_State *L);
7979
int mink_lua_do_perf_match(lua_State *L);
8080
int mink_lua_do_db_set(lua_State *L);
8181
int mink_lua_do_db_get(lua_State *L);
82+
int mink_lua_log(lua_State *L);
8283

8384
// registered lua module methods
8485
static const struct luaL_Reg mink_lualib[] = {
@@ -90,6 +91,7 @@ static const struct luaL_Reg mink_lualib[] = {
9091
{ "perf_match", &mink_lua_do_perf_match },
9192
{ "db_set", &mink_lua_do_db_set },
9293
{ "db_get", &mink_lua_do_db_get },
94+
{ "log", &mink_lua_log },
9395
{ NULL, NULL }
9496
};
9597

src/services/sysagent/umlua_m.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,3 +715,37 @@ mink_lua_do_db_get(lua_State *L)
715715
return 1;
716716
}
717717

718+
/*******/
719+
/* log */
720+
/*******/
721+
int
722+
mink_lua_log(lua_State *L)
723+
{
724+
// level, message
725+
if (lua_gettop(L) < 2) {
726+
return 0;
727+
}
728+
729+
// string values required
730+
if (!(lua_isstring(L, 1) && lua_isstring(L, 2))) {
731+
return 0;
732+
}
733+
734+
// get values
735+
const char *l = lua_tostring(L, 1);
736+
const char *m = lua_tostring(L, 2);
737+
738+
// default level
739+
int i_l = UMD_LLT_INFO;
740+
741+
if (strcmp(l, "warn") == 0) {
742+
i_l = UMD_LLT_WARNING;
743+
} else if (strcmp(l, "error") == 0) {
744+
i_l = UMD_LLT_ERROR;
745+
}
746+
747+
umd_log(UMD, i_l, m);
748+
749+
return 0;
750+
751+
}

0 commit comments

Comments
 (0)