-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlog.lua
More file actions
57 lines (55 loc) · 1.21 KB
/
log.lua
File metadata and controls
57 lines (55 loc) · 1.21 KB
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
LOG =
{
num = 0,
event = {},
time = {},
date = {},
}
-----------------
LOG_mt =
{
__index = LOG,
__gc =
function(self)
end
}
-----------------
function LOG:new()
local log = {}
setmetatable(log, LOG_mt)
return log
end
-----------------
-- adds a log event
function LOG:add(event)
self.num = self.num + 1
self.event[self.num] = event
self.time[self.num] = os.date("%X %p")
self.date[self.num] = os.date(" %A %m-%d-%y") -- %b(abbr. month)
end
-----------------
LOG.add_event = LOG.add
-----------------
-- saves all log events in a text file
function LOG:update()
filename = ("log.txt")
local cevent = self.event
if not io.open(filename, "w") then
local file = assert(io.open(filename, "w")); -- write to file
end
for s, i in pairs(cevent) do
file = assert(io.open(filename, "a+")); -- attach new data, save data
file:write(tostring(i), " " , self.date[s], " ", self.time[s], "\n");
file:close(filename);
end
end
-----------------
-- displays all the log events
function LOG:show()
for _, n in pairs(self.event) do
print(n, self.time[_])
end
end
-----------------
LOG:add("Last launch.")
--LOG:update()