1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
-- Gemeinschaft 5 module: log
-- (c) AMOOMA GmbH 2012-2013
--
module(...,package.seeall)
Log = {}
-- Create logger object
function Log.new(self, arg)
arg = arg or {}
object = arg.object or {}
setmetatable(object, self);
self.__index = self;
self.disabled = arg.disabled or false;
self.buffer = arg.buffer;
self.prefix = arg.prefix or '### ';
self.level_console = arg.level_console or 0;
self.level_alert = arg.level_alert or 1;
self.level_critical = arg.level_critical or 2;
self.level_error = arg.level_error or 3;
self.level_warning = arg.level_warning or 4;
self.level_notice = arg.level_notice or 5;
self.level_info = arg.level_info or 6;
self.level_debug = arg.level_debug or 7;
self.level_devel = arg.level_devel or 4;
return object;
end
function Log.message(self, log_level, message_arguments )
if self.disabled then
return
end
local message = tostring(self.prefix);
for index, value in pairs(message_arguments) do
if type(index) == 'number' then
if type(value) == 'table' then
require 'common.array';
message = message .. common.array.to_json(value, 3);
else
message = message .. tostring(value);
end
end
end
if self.buffer then
table.insert(self.buffer, message);
elseif freeswitch then
freeswitch.consoleLog(log_level, message .. '\n');
end
end
function Log.console(self, ...)
self:message(self.level_console, {...});
end
function Log.alert(self, ...)
self:message(self.level_alert, {...});
end
function Log.critical(self, ...)
self:message(self.level_critical, {...});
end
function Log.error(self, ...)
self:message(self.level_error, {...});
end
function Log.warning(self, ...)
self:message(self.level_warning, {...});
end
function Log.notice(self, ...)
self:message(self.level_notice, {...});
end
function Log.info(self, ...)
self:message(self.level_info, {...});
end
function Log.debug(self, ...)
self:message(self.level_debug, {...});
end
function Log.devel(self, ...)
local arguments = {...};
table.insert(arguments, 1, '**');
self:message(self.level_devel, arguments);
end
|