summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/log.lua
blob: 5aff2b86dcc5877543308c5ff6f8197491e069ee (plain)
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
-- 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.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;

  return object;
end

function Log.message(self, log_level, message_arguments )
  local message = tostring(self.prefix);
  for index, value in pairs(message_arguments) do
    if type(index) == 'number' then
      message = message .. tostring(value);
    end
  end
  freeswitch.consoleLog(log_level, message .. '\n');
end

function Log.console(self, ...)
  self:message(self.level_console, arg);
end

function Log.alert(self, ...)
  self:message(self.level_alert, arg);
end

function Log.critical(self, ...)
  self:message(self.level_critical, arg);
end

function Log.error(self, ...)
  self:message(self.level_error, arg);
end

function Log.warning(self, ...)
  self:message(self.level_warning, arg);
end

function Log.notice(self, ...)
  self:message(self.level_notice, arg);
end

function Log.info(self, ...)
  self:message(self.level_info, arg);
end

function Log.debug(self, ...)
  self:message(self.level_debug, arg);
end