File: log.lua

package info (click to toggle)
cataclysm-dda 0.C%2Bgit20190228.faafa3a-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 181,636 kB
  • sloc: cpp: 256,609; python: 2,621; makefile: 862; sh: 495; perl: 37; xml: 33
file content (43 lines) | stat: -rw-r--r-- 795 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
local log = {

  output_path = "./config/lua-log.log",
  datetime_format= "%Y-%m-%d %H:%M:%S"

}

log.init = function(output_path)

  if (output_path ~= nil) then
    log.output_path = output_path
  end
  return log

end

log.clear = function()

    local output_file = io.open (log.output_path, "w+")
    io.close(output_file)

end

log.message = function(message_text, ...)

  local message_text_formatted = ""

  if (#{...} > 0) then
    message_text_formatted = string.format(message_text, ...)
  else
    message_text_formatted = tostring(message_text)
  end

  local output_text = os.date(log.datetime_format).."|"..message_text_formatted.."\n"
  local output_file = io.open (log.output_path, "a")

  io.output(output_file)
  io.write(output_text)
  io.close(output_file)

end

return log