forked from Hydra9268/ZGESO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.lua
68 lines (56 loc) · 1.43 KB
/
Log.lua
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
local ZGV = _G.ZGV
local tinsert,tremove,sort,min,max,floor,type,pairs,ipairs = table.insert,table.remove,table.sort,math.min,math.max,math.floor,type,pairs,ipairs
local print = ZGV.print
local Log = {}
ZGV.Log = Log
Log.entries = {}
Log.size = 150
Log.loud = false
-- Common functions
local GetTimeString = _G.GetTimeString
local GetFrameTimeSeconds = _G.GetFrameTimeSeconds
local GetFrameTimeMilliseconds = _G.GetFrameTimeMilliseconds
function Log:SetSize(size)
self.size = size
self:Trim()
end
function Log:Trim()
local len = #self.entries
if len>self.size then
for i=1,len-self.size,1 do
tremove(self.entries,1)
end
end
end
function Log:Add(frm,...)
local s = frm:format(...)
local debugms = (GetFrameTimeMilliseconds()*1000)%1000
local datestamp = ("%s.%03d.%03d"):format(GetTimeString(),(GetFrameTimeSeconds()%1)*1000,debugms)
tinsert(self.entries, datestamp .. " > "..s)
if #self.entries>self.size then
tremove(self.entries,1)
end
if self.loud then
print("|c8888ff".. datestamp ..">|r |cccccff"..s.."|r")
end
end
function Log:Print(n)
local len = #self.entries
if not n or n > len then
n = len
end
for i = len - n + 1, len, 1 do
print(self.entries[i])
end
end
function Log:Dump(n)
local t = ""
local len = #self.entries
if not n or n > len then
n = len
end
for i = len - n + 1, len, 1 do
t = t .. self.entries[i] .. "\n"
end
return t
end