summaryrefslogtreecommitdiff
path: root/misc/freeswitch/scripts/common/log.lua
blob: e6aa7fabe7227d02ecbc6704f5bf962c7e793caf (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
70
71
72
73
-- 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.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 )
  if self.disabled then
    return
  end
  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, {...});
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