File: log.lua

package info (click to toggle)
eja 9.5.20-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, stretch
  • size: 1,340 kB
  • ctags: 3,142
  • sloc: ansic: 15,010; makefile: 255
file content (51 lines) | stat: -rw-r--r-- 944 bytes parent folder | download
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
-- Copyright (C) 2007-2014 by Ubaldo Porcheddu <ubaldo@eja.it>


eja.opt.logFile='/dev/stderr'
eja.opt.logLevel=0
eja.help.logFile='log file {stderr}'
eja.help.logLevel='log level'


function ejaLog(level,message)
 local fd=io.open(eja.opt.logFile,'a')
 fd:write(os.date("%Y-%m-%d %T")..' '..level..' '..message..'\n')
 fd:close()
end


function ejaError(value,...)
 if ejaNumber(eja.opt.logLevel) >= 1 then
  ejaLog("E",string.format(value,...))
 end
end


function ejaWarn(value,...)
 if ejaNumber(eja.opt.logLevel) >= 2 then 
  ejaLog("W",string.format(value,...))
 end
end


function ejaInfo(value,...)
 if ejaNumber(eja.opt.logLevel) >= 3 then 
  ejaLog("I",string.format(value,...))
 end
end


function ejaDebug(value,...)
 if ejaNumber(eja.opt.logLevel) >= 4 then 
  ejaLog("D",string.format(value,...))
 end
end


function ejaTrace(value,...)
 if ejaNumber(eja.opt.logLevel) >= 5 then 
  ejaLog("T",string.format(value,...))
 end
end