aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-30 12:35:07 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2015-08-30 12:35:07 +0100
commit2308f4059c052ab4248c369305c2440468797105 (patch)
tree46affb801b2562ddc3ad6bf40781f1fb586fc428
parentaf05d946e5cdd634d05434ebd294f0a31264645b (diff)
downloadrspamd-2308f4059c052ab4248c369305c2440468797105.tar.gz
rspamd-2308f4059c052ab4248c369305c2440468797105.zip
Update lua code for the new logger.
-rw-r--r--src/lua/lua_cfg_file.c14
-rw-r--r--src/lua/lua_classifier.c4
-rw-r--r--src/lua/lua_common.c30
-rw-r--r--src/lua/lua_config.c39
-rw-r--r--src/lua/lua_task.c4
-rw-r--r--src/lua/lua_util.c4
6 files changed, 51 insertions, 44 deletions
diff --git a/src/lua/lua_cfg_file.c b/src/lua/lua_cfg_file.c
index 049118504..bc9bdb3ac 100644
--- a/src/lua/lua_cfg_file.c
+++ b/src/lua/lua_cfg_file.c
@@ -67,7 +67,7 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
*score = lua_tonumber (L, -1);
}
else {
- msg_warn ("cannot get weight of symbol: %s", symbol);
+ msg_warn_config("cannot get weight of symbol: %s", symbol);
continue;
}
lua_pop (L, 1);
@@ -85,13 +85,13 @@ lua_process_metric (lua_State *L, const gchar *name, struct rspamd_config *cfg)
*score = lua_tonumber (L, -1);
}
else {
- msg_warn ("cannot get weight of symbol: %s", symbol);
+ msg_warn_config("cannot get weight of symbol: %s", symbol);
continue;
}
/* Insert symbol */
if ((s =
g_hash_table_lookup (metric->symbols, symbol)) != NULL) {
- msg_info ("replacing weight for symbol %s: %.2f -> %.2f",
+ msg_info_config("replacing weight for symbol %s: %.2f -> %.2f",
symbol,
*s->weight_ptr,
*score);
@@ -184,7 +184,7 @@ rspamd_lua_post_load_config (struct rspamd_config *cfg)
sym = rspamd_mempool_strdup (cfg->cfg_pool, name);
if (!rspamd_parse_expression (val, 0, &composite_expr_subr, NULL,
cfg->cfg_pool, &err, &expr)) {
- msg_err ("cannot parse composite expression '%s': %s", val,
+ msg_err_config("cannot parse composite expression '%s': %s", val,
err->message);
g_error_free (err);
err = NULL;
@@ -194,7 +194,7 @@ rspamd_lua_post_load_config (struct rspamd_config *cfg)
if ((old_expr =
g_hash_table_lookup (cfg->composite_symbols,
name)) != NULL) {
- msg_info ("replacing composite symbol %s", name);
+ msg_info_config("replacing composite symbol %s", name);
g_hash_table_replace (cfg->composite_symbols, sym, expr);
}
else {
@@ -285,14 +285,14 @@ rspamd_lua_check_condition (struct rspamd_config *cfg, const gchar *condition)
g_strlcat (condbuf, condition, hostlen);
/* Evaluate condition */
if (luaL_dostring (L, condbuf) != 0) {
- msg_err ("eval of '%s' failed: '%s'", condition, lua_tostring (L, -1));
+ msg_err_config("eval of '%s' failed: '%s'", condition, lua_tostring (L, -1));
g_free (condbuf);
return FALSE;
}
/* Get global variable res to get result */
lua_getglobal (L, FAKE_RES_VAR);
if (!lua_isboolean (L, -1)) {
- msg_err ("bad string evaluated: %s, type: %s", condbuf,
+ msg_err_config("bad string evaluated: %s, type: %s", condbuf,
lua_typename (L, lua_type (L, -1)));
g_free (condbuf);
return FALSE;
diff --git a/src/lua/lua_classifier.c b/src/lua/lua_classifier.c
index c338fb294..e9aa3e0fd 100644
--- a/src/lua/lua_classifier.c
+++ b/src/lua/lua_classifier.c
@@ -98,7 +98,7 @@ call_classifier_pre_callback (struct rspamd_classifier_config *ccf,
lua_pushboolean (L, is_spam);
if (lua_pcall (L, 4, 1, 0) != 0) {
- msg_warn ("error running pre classifier callback %s",
+ msg_warn_task ("error running pre classifier callback %s",
lua_tostring (L, -1));
}
else {
@@ -194,7 +194,7 @@ rspamd_lua_call_cls_post_callbacks (struct rspamd_classifier_config *ccf,
lua_pushnumber (L, out);
if (lua_pcall (L, 3, 1, 0) != 0) {
- msg_warn ("error running function %s: %s", cd->name,
+ msg_warn_task ("error running function %s: %s", cd->name,
lua_tostring (L, -1));
}
else {
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c
index 4d13ec27d..2c8403e96 100644
--- a/src/lua/lua_common.c
+++ b/src/lua/lua_common.c
@@ -304,7 +304,7 @@ rspamd_init_lua_filters (struct rspamd_config *cfg)
}
if (luaL_loadfile (L, module->path) != 0) {
- msg_info ("load of %s failed: %s", module->path,
+ msg_info_config ("load of %s failed: %s", module->path,
lua_tostring (L, -1));
cur = g_list_next (cur);
continue;
@@ -318,14 +318,14 @@ rspamd_init_lua_filters (struct rspamd_config *cfg)
/* do the call (0 arguments, N result) */
if (lua_pcall (L, 0, LUA_MULTRET, 0) != 0) {
- msg_info ("init of %s failed: %s", module->path,
+ msg_info_config ("init of %s failed: %s", module->path,
lua_tostring (L, -1));
cur = g_list_next (cur);
continue;
}
if (lua_gettop (L) != 0) {
if (lua_tonumber (L, -1) == -1) {
- msg_info (
+ msg_info_config (
"%s returned -1 that indicates configuration error",
module->path);
}
@@ -356,12 +356,12 @@ rspamd_lua_call_filter (const gchar *function, struct rspamd_task *task)
*ptask = task;
if (lua_pcall (L, 1, 1, 0) != 0) {
- msg_info ("call to %s failed", function);
+ msg_info_task ("call to %s failed", function);
}
/* retrieve result */
if (!lua_isnumber (L, -1)) {
- msg_info ("function %s must return a number", function);
+ msg_info_task ("function %s must return a number", function);
}
result = lua_tonumber (L, -1);
lua_pop (L, 1); /* pop returned value */
@@ -385,12 +385,12 @@ rspamd_lua_call_chain_filter (const gchar *function,
lua_pushnumber (L, marks[i]);
}
if (lua_pcall (L, number, 1, 0) != 0) {
- msg_info ("call to %s failed", function);
+ msg_info_task ("call to %s failed", function);
}
/* retrieve result */
if (!lua_isnumber (L, -1)) {
- msg_info ("function %s must return a number", function);
+ msg_info_task ("function %s must return a number", function);
}
result = lua_tonumber (L, -1);
lua_pop (L, 1); /* pop returned value */
@@ -415,19 +415,23 @@ lua_consolidation_callback (gpointer key, gpointer value, gpointer arg)
struct symbol *s = (struct symbol *)value;
struct consolidation_callback_data *data =
(struct consolidation_callback_data *)arg;
- lua_State *L = data->task->cfg->lua_state;
+ lua_State *L;
+ struct rspamd_task *task;
+
+ L = data->task->cfg->lua_state;
+ task = data->task;
lua_getglobal (L, data->func);
lua_pushstring (L, (const gchar *)key);
lua_pushnumber (L, s->score);
if (lua_pcall (L, 2, 1, 0) != 0) {
- msg_info ("call to %s failed", data->func);
+ msg_info_task ("call to %s failed", data->func);
}
/* retrieve result */
if (!lua_isnumber (L, -1)) {
- msg_info ("function %s must return a number", data->func);
+ msg_info_task ("function %s must return a number", data->func);
}
res = lua_tonumber (L, -1);
lua_pop (L, 1); /* pop returned value */
@@ -467,7 +471,7 @@ rspamd_lua_normalize (struct rspamd_config *cfg, long double score, void *params
/* Call specified function and put input score on stack */
if (!p->data) {
- msg_info ("bad function name while calling normalizer");
+ msg_info_config ("bad function name while calling normalizer");
return score;
}
@@ -475,12 +479,12 @@ rspamd_lua_normalize (struct rspamd_config *cfg, long double score, void *params
lua_pushnumber (L, score);
if (lua_pcall (L, 1, 1, 0) != 0) {
- msg_info ("call to %s failed", p->data);
+ msg_info_config ("call to %s failed", p->data);
}
/* retrieve result */
if (!lua_isnumber (L, -1)) {
- msg_info ("function %s must return a number", p->data);
+ msg_info_config ("function %s must return a number", p->data);
}
res = lua_tonumber (L, -1);
lua_pop (L, 1);
diff --git a/src/lua/lua_config.c b/src/lua/lua_config.c
index 228849ff0..43a6fb135 100644
--- a/src/lua/lua_config.c
+++ b/src/lua/lua_config.c
@@ -597,7 +597,7 @@ rspamd_lua_call_post_filters (struct rspamd_task *task)
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
- msg_err ("call to %s failed: %s",
+ msg_err_task ("call to %s failed: %s",
cd->cb_is_ref ? "local function" :
cd->callback.name,
lua_tostring (cd->L, -1));
@@ -665,7 +665,7 @@ rspamd_lua_call_pre_filters (struct rspamd_task *task)
*ptask = task;
if (lua_pcall (cd->L, 1, 0, 0) != 0) {
- msg_info ("call to %s failed: %s",
+ msg_info_task ("call to %s failed: %s",
cd->cb_is_ref ? "local function" :
cd->callback.name,
lua_tostring (cd->L, -1));
@@ -718,7 +718,7 @@ lua_config_add_radix_map (lua_State *L)
*r = radix_create_compressed ();
if (!rspamd_map_add (cfg, map_line, description, rspamd_radix_read,
rspamd_radix_fin, (void **)r)) {
- msg_warn ("invalid radix map %s", map_line);
+ msg_warn_config ("invalid radix map %s", map_line);
radix_destroy_compressed (*r);
lua_pushnil (L);
return 1;
@@ -762,12 +762,13 @@ lua_config_radix_from_config (lua_State *L)
rspamd_lua_setclass (L, "rspamd{radix}", -1);
return 1;
} else {
- msg_warn ("Couldnt find config option [%s][%s]", mname, optname);
+ msg_warn_config ("Couldnt find config option [%s][%s]", mname,
+ optname);
lua_pushnil (L);
return 1;
}
} else {
- msg_warn ("Couldnt find config option");
+ msg_warn_config ("Couldnt find config option");
lua_pushnil (L);
return 1;
}
@@ -821,7 +822,7 @@ lua_config_add_kv_map (lua_State *L)
*r = g_hash_table_new (rspamd_strcase_hash, rspamd_strcase_equal);
if (!rspamd_map_add (cfg, map_line, description, rspamd_kv_list_read, rspamd_kv_list_fin,
(void **)r)) {
- msg_warn ("invalid hash map %s", map_line);
+ msg_warn_config ("invalid hash map %s", map_line);
g_hash_table_destroy (*r);
lua_pushnil (L);
return 1;
@@ -884,7 +885,7 @@ lua_metric_symbol_callback (struct rspamd_task *task, gpointer ud)
*ptask = task;
if (lua_pcall (cd->L, 1, LUA_MULTRET, 0) != 0) {
- msg_info ("call to (%s)%s failed: %s", cd->symbol,
+ msg_info_task ("call to (%s)%s failed: %s", cd->symbol,
cd->cb_is_ref ? "local function" : cd->callback.name,
lua_tostring (cd->L, -1));
}
@@ -1001,7 +1002,7 @@ lua_config_register_symbols (lua_State *L)
gdouble weight = 1.0;
if (lua_gettop (L) < 3) {
- msg_err ("not enough arguments to register a function");
+ msg_err_config ("not enough arguments to register a function");
return 0;
}
if (cfg) {
@@ -1209,7 +1210,7 @@ lua_config_set_metric_symbol (lua_State * L)
"group=S;one_shot=B;metric=S",
&name, &weight, &description,
&group, &one_shot, &metric_name)) {
- msg_err ("bad arguments: %e", err);
+ msg_err_config ("bad arguments: %e", err);
g_error_free (err);
return 0;
@@ -1236,7 +1237,7 @@ lua_config_set_metric_symbol (lua_State * L)
metric = g_hash_table_lookup (cfg->metrics, metric_name);
if (metric == NULL) {
- msg_err ("metric named %s is not defined", metric_name);
+ msg_err_config ("metric named %s is not defined", metric_name);
}
else if (name != NULL && weight > 0) {
rspamd_config_add_metric_symbol (cfg, metric_name, name,
@@ -1265,13 +1266,14 @@ lua_config_add_composite (lua_State * L)
if (name && expr_str) {
if (!rspamd_parse_expression (expr_str, 0, &composite_expr_subr,
NULL, cfg->cfg_pool, &err, &expr)) {
- msg_err ("cannot parse composite expression %s: %e", expr_str,
+ msg_err_config ("cannot parse composite expression %s: %e",
+ expr_str,
err);
g_error_free (err);
}
else {
if (g_hash_table_lookup (cfg->composite_symbols, name) != NULL) {
- msg_warn ("composite %s is redefined", name);
+ msg_warn_config ("composite %s is redefined", name);
new = FALSE;
}
composite = rspamd_mempool_alloc (cfg->cfg_pool,
@@ -1343,7 +1345,8 @@ lua_config_newindex (lua_State *L)
if (lua_type (L, -1) != LUA_TFUNCTION) {
lua_pop (L, 2);
- msg_info ("cannot find callback definition for %s", name);
+ msg_info_config ("cannot find callback definition for %s",
+ name);
return 0;
}
idx = luaL_ref (L, LUA_REGISTRYINDEX);
@@ -1380,7 +1383,7 @@ lua_config_newindex (lua_State *L)
type = SYMBOL_TYPE_CALLBACK;
}
else {
- msg_info ("unknown type: %s", type_str);
+ msg_info_config ("unknown type: %s", type_str);
}
}
@@ -1521,7 +1524,7 @@ lua_map_fin (rspamd_mempool_t * pool, struct map_cb_data *data)
cbdata = (struct lua_map_callback_data *)data->cur_data;
}
else {
- msg_err ("no data read for map");
+ msg_err_pool ("no data read for map");
return;
}
@@ -1530,7 +1533,7 @@ lua_map_fin (rspamd_mempool_t * pool, struct map_cb_data *data)
lua_pushlstring (cbdata->L, cbdata->data->str, cbdata->data->len);
if (lua_pcall (cbdata->L, 1, 0, 0) != 0) {
- msg_info ("call to %s failed: %s", "local function",
+ msg_info_pool ("call to %s failed: %s", "local function",
lua_tostring (cbdata->L, -1));
}
}
@@ -1567,7 +1570,7 @@ lua_config_add_map (lua_State *L)
*pcbdata = cbdata;
if (!rspamd_map_add (cfg, map_line, description, lua_map_read, lua_map_fin,
(void **)pcbdata)) {
- msg_warn ("invalid hash map %s", map_line);
+ msg_warn_config ("invalid hash map %s", map_line);
lua_pushboolean (L, false);
}
else {
@@ -1575,7 +1578,7 @@ lua_config_add_map (lua_State *L)
}
}
else {
- msg_warn ("invalid callback argument for map %s", map_line);
+ msg_warn_config ("invalid callback argument for map %s", map_line);
lua_pushboolean (L, false);
}
}
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index d40944cd8..201888c3c 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -801,7 +801,7 @@ lua_task_set_pre_result (lua_State * L)
else {
task->pre_result.str = "unknown";
}
- msg_info ("<%s>: set pre-result to %s: '%s'",
+ msg_info_task ("<%s>: set pre-result to %s: '%s'",
task->message_id, rspamd_action_to_str (action),
task->pre_result.str);
}
@@ -1870,7 +1870,7 @@ lua_task_learn (lua_State *L)
cl = rspamd_config_find_classifier (task->cfg, clname);
if (cl == NULL) {
- msg_warn ("classifier %s is not found", clname);
+ msg_warn_task ("classifier %s is not found", clname);
lua_pushboolean (L, FALSE);
lua_pushstring (L, "classifier not found");
ret = 2;
diff --git a/src/lua/lua_util.c b/src/lua/lua_util.c
index 4655399b4..8b3a13786 100644
--- a/src/lua/lua_util.c
+++ b/src/lua/lua_util.c
@@ -154,7 +154,7 @@ lua_util_load_rspamd_config (lua_State *L)
cfg->cache = rspamd_symbols_cache_new (cfg);
if (rspamd_config_read (cfg, cfg_name, NULL, NULL, NULL, NULL)) {
- msg_err ("cannot load config from %s", cfg_name);
+ msg_err_config ("cannot load config from %s", cfg_name);
lua_pushnil (L);
}
else {
@@ -188,7 +188,7 @@ lua_util_config_from_ucl (lua_State *L)
top = rspamd_rcl_config_init ();
if (!rspamd_rcl_parse (top, cfg, cfg->cfg_pool, cfg->rcl_obj, &err)) {
- msg_err ("rcl parse error: %s", err->message);
+ msg_err_config ("rcl parse error: %s", err->message);
ucl_object_unref (obj);
lua_pushnil (L);
}