TT#78651 log strings need to end with '\n'

Use shorter version of KSR.log when possible

Change-Id: I503a82714b50e5061d9cd2176ff938c592ca22df
changes/53/39453/2
Victor Seva 6 years ago
parent 48b0d4d018
commit 72b9ed4f81

@ -1,5 +1,5 @@
-- --
-- Copyright 2015 SipWise Team <development@sipwise.com> -- Copyright 2015-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -29,7 +29,7 @@ local NGCPConfig = {
__class__ = 'NGCPConfig' __class__ = 'NGCPConfig'
} }
local NGCPConfig_MT = { __index = NGCPConfig } local NGCPConfig_MT = { __index = NGCPConfig }
-- luacheck: globals KSR
function NGCPConfig:new() function NGCPConfig:new()
local t = { local t = {
db_host = "127.0.0.1", db_host = "127.0.0.1",
@ -97,11 +97,11 @@ local NGCPConfig_MT = { __index = NGCPConfig }
local ok,_ = pcall(check_connection, self.con) local ok,_ = pcall(check_connection, self.con)
if not ok then if not ok then
self.con = nil self.con = nil
KSR.log("dbg", "lost database connection. Reconnecting") KSR.dbg("lost database connection. Reconnecting\n")
end end
end end
if not self.con then if not self.con then
KSR.log("dbg","connecting to mysql") KSR.dbg("connecting to mysql\n")
self.con = self.env:connect( self.db_database, self.con = self.env:connect( self.db_database,
self.db_username, self.db_pass, self.db_host, self.db_port) self.db_username, self.db_pass, self.db_host, self.db_port)
end end

@ -1,5 +1,5 @@
-- --
-- Copyright 2014 SipWise Team <development@sipwise.com> -- Copyright 2014-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ NGCPDlgCounters_MT.__tostring = function (t)
utable.tostring(t.config), utable.tostring(t.central), utable.tostring(t.config), utable.tostring(t.central),
utable.tostring(t.pair)); utable.tostring(t.pair));
end end
-- luacheck: globals KSR
function NGCPDlgCounters.new() function NGCPDlgCounters.new()
local t = NGCPDlgCounters.init(); local t = NGCPDlgCounters.init();
setmetatable( t, NGCPDlgCounters_MT ); setmetatable( t, NGCPDlgCounters_MT );
@ -72,7 +72,7 @@ end
function NGCPDlgCounters._connect(config) function NGCPDlgCounters._connect(config)
local client = redis.connect(config.host,config.port); local client = redis.connect(config.host,config.port);
client:select(config.db); client:select(config.db);
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", KSR.dbg(string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db)); config.host, config.port, config.db));
return client; return client;
end end
@ -81,12 +81,14 @@ end
local res = self.central:decr(key); local res = self.central:decr(key);
if res == 0 then if res == 0 then
self.central:del(key); self.central:del(key);
KSR.log("dbg", string.format("central:del[%s] counter is 0\n", key)); KSR.dbg(string.format("central:del[%s] counter is 0\n", key));
elseif res < 0 and not self.config.allow_negative then elseif res < 0 and not self.config.allow_negative then
self.central:del(key); self.central:del(key);
KSR.log("warn", string.format("central:del[%s] counter was %s\n", key, tostring(res))); KSR.warn(string.format("central:del[%s] counter was %s\n",
key, tostring(res)));
else else
KSR.log("dbg", string.format("central:decr[%s]=>[%s]\n", key, tostring(res))); KSR.dbg(string.format("central:decr[%s]=>[%s]\n",
key, tostring(res)));
end end
return res; return res;
end end
@ -116,15 +118,17 @@ end
self.central = self._connect(self.config.central); self.central = self._connect(self.config.central);
end end
local res = self.central:incr(key); local res = self.central:incr(key);
KSR.log("dbg", string.format("central:incr[%s]=>%s\n", key, tostring(res))); KSR.dbg(string.format("central:incr[%s]=>%s\n", key, tostring(res)));
if not self._test_connection(self.pair) then if not self._test_connection(self.pair) then
self.pair = self._connect(self.config.pair); self.pair = self._connect(self.config.pair);
end end
if self.config.check_pair_dup and self:is_in_set(callid, key) then if self.config.check_pair_dup and self:is_in_set(callid, key) then
KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key)); local msg = "pair:check_pair_dup[%s]=>[%s] already there!\n";
KSR.warn(msg:format(callid, key));
end end
local pos = self.pair:lpush(callid, key); local pos = self.pair:lpush(callid, key);
KSR.log("dbg", string.format("pair:lpush[%s]=>[%s] %s\n", callid, key, tostring(pos))); KSR.dbg(string.format("pair:lpush[%s]=>[%s] %s\n",
callid, key, tostring(pos)));
end end
function NGCPDlgCounters:del_key(callid, key) function NGCPDlgCounters:del_key(callid, key)
@ -133,11 +137,12 @@ end
end end
local num = self.pair:lrem(callid, 1, key); local num = self.pair:lrem(callid, 1, key);
if num == 0 then if num == 0 then
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] no such key found in list, skipping decrement", local msg = "pair:lrem[%s]=>[%s] no such key found in list, " ..
callid, key)); "skipping decrement\n";
KSR.dbg(msg:format(callid, key));
return false; return false;
end end
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); KSR.dbg(string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
if not self._test_connection(self.central) then if not self._test_connection(self.central) then
self.central = self._connect(self.config.central); self.central = self._connect(self.config.central);
end end
@ -157,7 +162,7 @@ end
end end
while key do while key do
self:_decr(key); self:_decr(key);
KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key)); KSR.dbg(string.format("pair:lpop[%s]=>[%s]\n", callid, key));
key = self.pair:lpop(callid); key = self.pair:lpop(callid);
end end
end end
@ -167,7 +172,7 @@ end
self.central = self._connect(self.config.central); self.central = self._connect(self.config.central);
end end
local res = self.central:get(key); local res = self.central:get(key);
KSR.log("dbg", string.format("central:get[%s]=>%s\n", key, tostring(res))); KSR.dbg(string.format("central:get[%s]=>%s\n", key, tostring(res)));
return res; return res;
end end
-- class -- class

@ -1,5 +1,5 @@
-- --
-- Copyright 2015 SipWise Team <development@sipwise.com> -- Copyright 2015-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -34,7 +34,7 @@ NGCPDlgList_MT.__tostring = function (t)
utable.tostring(t.config), utable.tostring(t.central), utable.tostring(t.config), utable.tostring(t.central),
utable.tostring(t.pair)); utable.tostring(t.pair));
end end
-- luacheck: globals KSR
function NGCPDlgList.new() function NGCPDlgList.new()
local t = NGCPDlgList.init(); local t = NGCPDlgList.init();
setmetatable( t, NGCPDlgList_MT ); setmetatable( t, NGCPDlgList_MT );
@ -71,7 +71,7 @@ end
local function _connect(config) local function _connect(config)
local client = redis.connect(config.host,config.port); local client = redis.connect(config.host,config.port);
client:select(config.db); client:select(config.db);
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", KSR.dbg(string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db)); config.host, config.port, config.db));
return client; return client;
end end
@ -81,9 +81,9 @@ end
local num = self.central:llen(key); local num = self.central:llen(key);
if num == 0 then if num == 0 then
self.central:del(key); self.central:del(key);
KSR.log("dbg", string.format("central[%s] is empty. Removed\n", key)); KSR.dbg(string.format("central[%s] is empty. Removed\n", key));
else else
KSR.log("dbg", string.format("central:lrem[%s]=>[%s]\n", key, tostring(num))); KSR.dbg(string.format("central:lrem[%s]=>[%s]\n", key, tostring(num)));
end end
return num; return num;
end end
@ -113,15 +113,15 @@ end
self.central = _connect(self.config.central); self.central = _connect(self.config.central);
end end
local pos = self.central:rpush(key, callid); local pos = self.central:rpush(key, callid);
KSR.log("dbg", string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos))); KSR.dbg(string.format("central:rpush[%s]=>[%s] %s\n", key, callid, tostring(pos)));
if not _test_connection(self.pair) then if not _test_connection(self.pair) then
self.pair = _connect(self.config.pair); self.pair = _connect(self.config.pair);
end end
if self.config.check_pair_dup and self:is_in_set(callid, key) then if self.config.check_pair_dup and self:is_in_set(callid, key) then
KSR.log("warn", string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key)); KSR.warn(string.format("pair:check_pair_dup[%s]=>[%s] already there!\n", callid, key));
end end
pos = self.pair:lpush("list:"..callid, key); pos = self.pair:lpush("list:"..callid, key);
KSR.log("dbg", string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos))); KSR.dbg(string.format("pair:lpush[list:%s]=>[%s] %s\n", callid, key, tostring(pos)));
end end
function NGCPDlgList:del(callid, key) function NGCPDlgList:del(callid, key)
@ -130,10 +130,10 @@ end
end end
local num = self.pair:lrem("list:"..callid, 0, key); local num = self.pair:lrem("list:"..callid, 0, key);
if num == 0 then if num == 0 then
KSR.log("dbg", string.format("pair:lrem[list:%s] no such key %s found in list", callid, key)); KSR.dbg(string.format("pair:lrem[list:%s] no such key %s found in list\n", callid, key));
return false; return false;
end end
KSR.log("dbg", string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num)); KSR.dbg(string.format("pair:lrem[%s]=>[%s] %d\n", callid, key, num));
if not _test_connection(self.central) then if not _test_connection(self.central) then
self.central = _connect(self.config.central); self.central = _connect(self.config.central);
end end
@ -154,7 +154,7 @@ end
end end
while key do while key do
self:_del(key, callid); self:_del(key, callid);
KSR.log("dbg", string.format("pair:lpop[%s]=>[%s]\n", callid, key)); KSR.dbg(string.format("pair:lpop[%s]=>[%s]\n", callid, key));
key = self.pair:lpop("list:"..callid); key = self.pair:lpop("list:"..callid);
end end
end end

@ -1,5 +1,5 @@
-- --
-- Copyright 2016 SipWise Team <development@sipwise.com> -- Copyright 2016-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -33,7 +33,7 @@ NGCPLoop_MT.__tostring = function (t)
return string.format("config:%s", return string.format("config:%s",
utable.tostring(t.config)); utable.tostring(t.config));
end end
-- luacheck: globals KSR
function NGCPLoop.new() function NGCPLoop.new()
local t = NGCPLoop.init(); local t = NGCPLoop.init();
setmetatable( t, NGCPLoop_MT ); setmetatable( t, NGCPLoop_MT );
@ -63,7 +63,7 @@ end
local function _connect(config) local function _connect(config)
local client = redis.connect(config.host,config.port); local client = redis.connect(config.host,config.port);
client:select(config.db); client:select(config.db);
KSR.log("dbg", string.format("connected to redis server %s:%d at %s\n", KSR.dbg(string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db)); config.host, config.port, config.db));
return client; return client;
end end
@ -72,12 +72,14 @@ end
if not _test_connection(self.client) then if not _test_connection(self.client) then
self.client = _connect(self.config); self.client = _connect(self.config);
end end
local key = string.format("%s;%s;%s", tostring(fu), tostring(tu), tostring(ru)); local key = string.format("%s;%s;%s",
tostring(fu), tostring(tu), tostring(ru));
local res = self.client:incr(key); local res = self.client:incr(key);
if res == 1 then if res == 1 then
self.client:expire(key, self.config.expire); self.client:expire(key, self.config.expire);
end end
KSR.log("dbg", string.format("[%s]=>[%s] expires:%s\n", key, tostring(res), tostring(self.config.expires))); KSR.dbg(string.format("[%s]=>[%s] expires:%s\n",
key, tostring(res), tostring(self.config.expires)));
return res; return res;
end end

@ -34,7 +34,7 @@ function NGCPPrefs.__tostring(self)
end end
return output return output
end end
-- luacheck: globals KSR
function NGCPPrefs:init() function NGCPPrefs:init()
for _,v in pairs(self.levels) do for _,v in pairs(self.levels) do
NGCPXAvp.init(v, self.group) NGCPXAvp.init(v, self.group)
@ -49,8 +49,8 @@ function NGCPPrefs:_defaults()
local group = self.group:gsub('_prefs','') local group = self.group:gsub('_prefs','')
local defaults = self.config:get_defaults(group) local defaults = self.config:get_defaults(group)
local keys = {} local keys = {}
local msg = "defaults[%s]:%s\n"
KSR.dbg(string.format("defaults[%s]:%s", group, utable.tostring(defaults))) KSR.dbg(msg:format(group, utable.tostring(defaults)))
for k,_ in pairs(defaults) do for k,_ in pairs(defaults) do
table.insert(keys, k) table.insert(keys, k)
@ -66,7 +66,7 @@ function NGCPPrefs:_set_xavp(level, cur, query)
if utable.size(row) > 0 then if utable.size(row) > 0 then
while utable.size(row) > 0 do while utable.size(row) > 0 do
KSR.dbg(string.format("result:%s row:%s", KSR.dbg(string.format("result:%s row:%s\n",
utable.tostring(result), utable.tostring(row))) utable.tostring(result), utable.tostring(row)))
table.insert(result, row) table.insert(result, row)
utable.add(keys, row.attribute) utable.add(keys, row.attribute)
@ -74,13 +74,13 @@ function NGCPPrefs:_set_xavp(level, cur, query)
row = cur:fetch({}, "a") row = cur:fetch({}, "a")
end end
else else
KSR.dbg(string.format("no results for query:%s", query)) KSR.dbg(string.format("no results for query:%s\n", query))
end end
cur:close() cur:close()
local xavp = self:xavp(level, result) local xavp = self:xavp(level, result)
for k,v in pairs(defaults) do for k,v in pairs(defaults) do
KSR.dbg(string.format("setting default[%s]:%s", k, tostring(v))) KSR.dbg(string.format("setting default[%s]:%s\n", k, tostring(v)))
xavp(k, v) xavp(k, v)
end end
return keys return keys

@ -1,5 +1,5 @@
-- --
-- Copyright 2015 SipWise Team <development@sipwise.com> -- Copyright 2015-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -32,7 +32,7 @@ NGCPRecentCalls_MT.__tostring = function (t)
return string.format("config:%s central:%s", return string.format("config:%s central:%s",
utable.tostring(t.config), utable.tostring(t.central)) utable.tostring(t.config), utable.tostring(t.central))
end end
-- luacheck: globals KSR
function NGCPRecentCalls.new() function NGCPRecentCalls.new()
local t = NGCPRecentCalls.init(); local t = NGCPRecentCalls.init();
setmetatable( t, NGCPRecentCalls_MT ) setmetatable( t, NGCPRecentCalls_MT )
@ -64,7 +64,7 @@ end
function NGCPRecentCalls._connect(config) function NGCPRecentCalls._connect(config)
local client = redis.connect(config.host,config.port) local client = redis.connect(config.host,config.port)
client:select(config.db) client:select(config.db)
KSR.log("info", string.format("connected to redis server %s:%d at %s\n", KSR.info(string.format("connected to redis server %s:%d at %s\n",
config.host, config.port, config.db)) config.host, config.port, config.db))
return client return client
end end
@ -87,14 +87,14 @@ end
if res then if res then
self.central:expire(key, self.config.expire) self.central:expire(key, self.config.expire)
end end
KSR.log("info", string.format("central:hset[%s]=>[%s] callid: %s uuid: %s " .. local msg = "central:hset[%s]=>[%s] callid: %s uuid: %s " ..
"start_time: %s duration: %d caller: %s callee: %s source: %s expire: %d\n", "start_time: %s duration: %d caller: %s callee: %s source: %s expire: %d\n"
key, tostring(res), KSR.info(msg:format(key, tostring(res),
callid, uuid, callid, uuid,
start_time, duration, start_time, duration,
caller, callee, caller, callee,
source, source,
self.config.expire)) self.config.expire))
return res return res
end end
@ -107,10 +107,10 @@ end
if res then if res then
self.central:expire(key, self.config.out_expire) self.central:expire(key, self.config.out_expire)
end end
KSR.log("info", string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n", KSR.info(string.format("central:hset[%s]=>[%s] %s: %s expire: %d\n",
key, tostring(res), key, tostring(res),
element, tostring(value), element, tostring(value),
self.config.out_expire)) self.config.out_expire))
return res return res
end end
@ -121,7 +121,7 @@ end
local res = self.central:hgetall(key) local res = self.central:hgetall(key)
if res then if res then
KSR.log("info", string.format("central:hget[%s]=>[%s]\n", KSR.info(string.format("central:hget[%s]=>[%s]\n",
key, tostring(res[element]))) key, tostring(res[element])))
return res[element] return res[element]
@ -136,7 +136,7 @@ end
end end
self.central:del(key) self.central:del(key)
KSR.log("info", string.format("central:del[%s] removed\n", key)); KSR.info(string.format("central:del[%s] removed\n", key));
return 0 return 0
end end

@ -123,7 +123,7 @@ function NGCPRealPrefs:_usr_load(level, keys)
if value then if value then
real_values[v] = value real_values[v] = value
else else
KSR.err(string.format("key:%s not in user, profile or domain", v)) KSR.err(string.format("key:%s not in user, profile or domain\n", v))
end end
end end
local real_keys = {} local real_keys = {}

@ -1,5 +1,5 @@
-- --
-- Copyright 2013-2015 SipWise Team <development@sipwise.com> -- Copyright 2013-2020 SipWise Team <development@sipwise.com>
-- --
-- This program is free software: you can redistribute it and/or modify -- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by -- it under the terms of the GNU General Public License as published by
@ -27,6 +27,7 @@ local NGCPXAvp = {
local NGCPXAvp_MT = { local NGCPXAvp_MT = {
__index = NGCPXAvp __index = NGCPXAvp
} }
-- luacheck: globals KSR
function NGCPXAvp:new(level,group,l) function NGCPXAvp:new(level,group,l)
local t = NGCPXAvp.init(level,group,l) local t = NGCPXAvp.init(level,group,l)
NGCPXAvp_MT.__call = function(s, key, value) NGCPXAvp_MT.__call = function(s, key, value)
@ -34,16 +35,15 @@ local NGCPXAvp_MT = {
error("key is empty") error("key is empty")
end end
local id = string.format("$xavp(%s[0]=>%s)", s.name, key) local id = string.format("$xavp(%s[0]=>%s)", s.name, key)
--print(string.format("id:%s", id))
if not value then if not value then
return KSR.pv.get(id) return KSR.pv.get(id)
elseif type(value) == "number" then elseif type(value) == "number" then
utable.add(s.keys, key) utable.add(s.keys, key)
--sr.log("dbg", string.format("seti: [%s]:%d", id, value)) --KSR.dbg(string.format("seti: [%s]:%d\n", id, value))
KSR.pv.seti(id, value) KSR.pv.seti(id, value)
elseif type(value) == "string" then elseif type(value) == "string" then
utable.add(s.keys, key) utable.add(s.keys, key)
--sr.log("dbg", string.format("sets: [%s]:%s", id, value)) --KSR.dbg(string.format("sets: [%s]:%s\n", id, value))
KSR.pv.sets(id, value) KSR.pv.sets(id, value)
elseif type(value) == "table" then elseif type(value) == "table" then
utable.add(s.keys, key) utable.add(s.keys, key)
@ -68,7 +68,7 @@ local NGCPXAvp_MT = {
if ll then if ll then
output = utable.tostring(ll) output = utable.tostring(ll)
end end
KSR.log("dbg", string.format("output:%s", output)) KSR.dbg(string.format("output:%s\n", output))
return output return output
end end
setmetatable( t, NGCPXAvp_MT ) setmetatable( t, NGCPXAvp_MT )
@ -100,7 +100,7 @@ local NGCPXAvp_MT = {
vtype = tonumber(vtype) vtype = tonumber(vtype)
end end
if vtype == 0 then if vtype == 0 then
KSR.log("dbg",string.format("sr.pv.sets->%s:%s", id, value)) KSR.dbg(string.format("KSR.pv.sets->%s:%s\n", id, value))
if type(value) == 'number' then if type(value) == 'number' then
value = tostring(value) value = tostring(value)
end end
@ -111,7 +111,7 @@ local NGCPXAvp_MT = {
end end
KSR.pv.seti(id, value) KSR.pv.seti(id, value)
else else
KSR.log("err",string.format("can't set value:%s of type:%s", KSR.err(string.format("can't set value:%s of type:%s\n",
tostring(value), tostring(vtype))) tostring(value), tostring(vtype)))
end end
if value and id then if value and id then
@ -120,9 +120,9 @@ local NGCPXAvp_MT = {
if type(check) == 'table' then if type(check) == 'table' then
utable.tostring(check) utable.tostring(check)
end end
else else
--error(string.format("%s:nil", id)) --error(string.format("%s:nil", id))
KSR.log("err", string.format("%s:nil", id)) KSR.err(string.format("%s:nil\n", id))
end end
end end
end end
@ -131,7 +131,8 @@ local NGCPXAvp_MT = {
local name = string.format("$xavp(%s=>dummy)", self.name) local name = string.format("$xavp(%s=>dummy)", self.name)
if not KSR.pv.get(name) then if not KSR.pv.get(name) then
NGCPXAvp._setvalue(name, 0, self.level) NGCPXAvp._setvalue(name, 0, self.level)
KSR.log("dbg",string.format("%s created with dummy value:%s", name, self.level)) KSR.dbg(string.format("%s created with dummy value:%s\n",
name, self.level))
end end
for i=1,#l do for i=1,#l do
name = string.format("$xavp(%s[0]=>%s)", tostring(self.name), tostring(l[i].attribute)) name = string.format("$xavp(%s[0]=>%s)", tostring(self.name), tostring(l[i].attribute))

Loading…
Cancel
Save