From 659a0c889cd00507b7bb5c1a550adb8524ae073a Mon Sep 17 00:00:00 2001 From: Kit Chan Date: Sat, 19 Sep 2020 13:27:48 -0700 Subject: [PATCH] Add support for TS API for Note, Status, Warning, Alert --- doc/admin-guide/plugins/lua.en.rst | 40 +++++++++++++++++++ plugins/lua/ts_lua_misc.c | 64 ++++++++++++++++++++++++++++++ 2 files changed, 104 insertions(+) diff --git a/doc/admin-guide/plugins/lua.en.rst b/doc/admin-guide/plugins/lua.en.rst index c282da6e887..e876a7306bc 100644 --- a/doc/admin-guide/plugins/lua.en.rst +++ b/doc/admin-guide/plugins/lua.en.rst @@ -299,6 +299,46 @@ Here is an example: :ref:`TOP ` +ts.status +--------- +**syntax:** *ts.status(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as status + +:ref:`TOP ` + +ts.note +------- +**syntax:** *ts.note(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as note + +:ref:`TOP ` + +ts.warning +---------- +**syntax:** *ts.warning(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as warning + +:ref:`TOP ` + +ts.alert +-------- +**syntax:** *ts.alert(MESSAGE)* + +**context:** global + +**description**: Log the MESSAGE to error.log as alert + +:ref:`TOP ` + TS Basic Internal Information ----------------------------- **syntax:** *ts.get_install_dir()* diff --git a/plugins/lua/ts_lua_misc.c b/plugins/lua/ts_lua_misc.c index 057ef07e96c..d65ec5ec524 100644 --- a/plugins/lua/ts_lua_misc.c +++ b/plugins/lua/ts_lua_misc.c @@ -26,6 +26,10 @@ static int ts_lua_debug(lua_State *L); static int ts_lua_error(lua_State *L); static int ts_lua_emergency(lua_State *L); static int ts_lua_fatal(lua_State *L); +static int ts_lua_status(lua_State *L); +static int ts_lua_note(lua_State *L); +static int ts_lua_warning(lua_State *L); +static int ts_lua_alert(lua_State *L); static int ts_lua_sleep(lua_State *L); static int ts_lua_host_lookup(lua_State *L); static int ts_lua_schedule(lua_State *L); @@ -74,6 +78,22 @@ ts_lua_inject_misc_api(lua_State *L) lua_pushcfunction(L, ts_lua_fatal); lua_setfield(L, -2, "fatal"); + /* ts.status(...) */ + lua_pushcfunction(L, ts_lua_status); + lua_setfield(L, -2, "status"); + + /* ts.note(...) */ + lua_pushcfunction(L, ts_lua_note); + lua_setfield(L, -2, "note"); + + /* ts.warning(...) */ + lua_pushcfunction(L, ts_lua_warning); + lua_setfield(L, -2, "warning"); + + /* ts.alert(...) */ + lua_pushcfunction(L, ts_lua_alert); + lua_setfield(L, -2, "alert"); + /* ts.sleep(...) */ lua_pushcfunction(L, ts_lua_sleep); lua_setfield(L, -2, "sleep"); @@ -195,6 +215,50 @@ ts_lua_fatal(lua_State *L) return 0; } +static int +ts_lua_status(lua_State *L) +{ + const char *msg; + size_t len = 0; + + msg = luaL_checklstring(L, 1, &len); + TSStatus("%.*s", (int)len, msg); + return 0; +} + +static int +ts_lua_note(lua_State *L) +{ + const char *msg; + size_t len = 0; + + msg = luaL_checklstring(L, 1, &len); + TSNote("%.*s", (int)len, msg); + return 0; +} + +static int +ts_lua_warning(lua_State *L) +{ + const char *msg; + size_t len = 0; + + msg = luaL_checklstring(L, 1, &len); + TSWarning("%.*s", (int)len, msg); + return 0; +} + +static int +ts_lua_alert(lua_State *L) +{ + const char *msg; + size_t len = 0; + + msg = luaL_checklstring(L, 1, &len); + TSAlert("%.*s", (int)len, msg); + return 0; +} + static int ts_lua_schedule(lua_State *L) {