MINOR: hlua: Be able to disable logging from lua
Add core.silent (-1) value to be able to disable logging via
TXN:set_loglevel() call. Otherwise, there is no way to do so and it may be
handy. This special value cannot be used with TXN:log() function.
This patch may be backported if necessary.
(cherry picked from commit 31ec9f18bb73737fc8e96f8781e1f251ddc44522)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 65f5395d76a4745d985174b23f3c8c53fd5c56ea)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 12a5ee786a34f7d5c40ea5cf4b57edc343d2019e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 8e8cd4d467e27ce173e2ff89fd186495aedc0696)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit ee314746923d12ff7ccdca95ad26cd01f84c6f11)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
diff --git a/doc/lua-api/index.rst b/doc/lua-api/index.rst
index 9797ece..61557c7 100644
--- a/doc/lua-api/index.rst
+++ b/doc/lua-api/index.rst
@@ -118,6 +118,13 @@
The "core" class is static, it is not possible to create a new object of this
type.
+.. js:attribute:: core.silent
+
+ :returns: integer
+
+ This attribute is an integer, it contains the value -1. It is a special value
+ used to disable logging.
+
.. js:attribute:: core.emerg
:returns: integer
@@ -1845,12 +1852,12 @@
.. js:function:: TXN.set_loglevel(txn, loglevel)
Is used to change the log level of the current request. The "loglevel" must
- be an integer between 0 and 7.
+ be an integer between 0 and 7 or the special value -1 to disable logging.
:param class_txn txn: The class txn object containing the data.
:param integer loglevel: The required log level. This variable can be one of
- :see: :js:attr:`core.emerg`, :js:attr:`core.alert`, :js:attr:`core.crit`,
- :js:attr:`core.err`, :js:attr:`core.warning`, :js:attr:`core.notice`,
+ :see: :js:attr:`core.silent`, :js:attr:`core.emerg`, :js:attr:`core.alert`,
+ :js:attr:`core.crit`, :js:attr:`core.err`, :js:attr:`core.warning`, :js:attr:`core.notice`,
:js:attr:`core.info`, :js:attr:`core.debug` (log level definitions)
.. js:function:: TXN.set_tos(txn, tos)
diff --git a/src/hlua.c b/src/hlua.c
index 9337448..40e337e 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -5697,10 +5697,12 @@
htxn = MAY_LJMP(hlua_checktxn(L, 1));
ll = MAY_LJMP(luaL_checkinteger(L, 2));
- if (ll < 0 || ll > 7)
- WILL_LJMP(luaL_argerror(L, 2, "Bad log level. It must be between 0 and 7"));
+ if (ll < -1 || ll > NB_LOG_LEVELS)
+ WILL_LJMP(luaL_argerror(L, 2, "Bad log level. It must be one of the following value:"
+ " core.silent(-1), core.emerg(0), core.alert(1), core.crit(2), core.error(3),"
+ " core.warning(4), core.notice(5), core.info(6) or core.debug(7)"));
- htxn->s->logs.level = ll + 1;
+ htxn->s->logs.level = (ll == -1) ? ll : ll + 1;
return 0;
}
@@ -8956,6 +8958,7 @@
hlua_class_const_int(L, "thread", thread_num);
/* Push the loglevel constants. */
+ hlua_class_const_int(L, "silent", -1);
for (i = 0; i < NB_LOG_LEVELS; i++)
hlua_class_const_int(L, log_levels[i], i);