Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit dbabd5e

Browse files
committed
Logger
1 parent fa181c2 commit dbabd5e

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

lua/autorun/!!!sh_plib.lua

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,90 @@ do
117117

118118
end
119119

120+
-- Logger
121+
do
122+
123+
local meta = {}
124+
meta.__index = meta
125+
126+
-- Logs name
127+
function meta:GetName()
128+
return self.Name
129+
end
130+
131+
function meta:SetName( str )
132+
ArgAssert( str, 1, 'string' )
133+
self.Name = str
134+
end
135+
136+
-- Logs name color
137+
function meta:GetColor()
138+
return self.Color
139+
end
140+
141+
function meta:SetColor( color )
142+
ArgAssert( color, 1, 'table' )
143+
self.Color = color
144+
end
145+
146+
-- Logs basic text colot
147+
function meta:GetTextColor()
148+
return self.TextColor
149+
end
150+
151+
function meta:SetTextColor( color )
152+
ArgAssert( color, 1, 'table' )
153+
self.TextColor = color
154+
end
155+
156+
-- Debug options
157+
function meta:GetDebugFilter()
158+
return self.DebugFilter
159+
end
160+
161+
function meta:SetDebugFilter( func )
162+
ArgAssert( func, 1, 'function' )
163+
self.DebugFilter = func
164+
end
165+
166+
-- Log print functions
167+
do
168+
local color = GetColor( 'info' )
169+
function meta:Info( str, ... )
170+
Log( color, ' INFO', self:GetColor(), self:GetName(), str, ... )
171+
end
172+
end
173+
174+
do
175+
local color = GetColor( 'warn' )
176+
function meta:Warn( str, ... )
177+
Log( color, ' WARN', self:GetColor(), self:GetName(), str, ... )
178+
end
179+
end
180+
181+
do
182+
local color = GetColor( 'error' )
183+
function meta:Error( str, ... )
184+
Log( color, 'ERROR', self:GetColor(), self:GetName(), str, ... )
185+
end
186+
end
187+
188+
do
189+
local color = GetColor( 'debug' )
190+
function meta:Debug( str, ... )
191+
if DeveloperMode then
192+
Log( color, 'DEBUG', self:GetColor(), self:GetName(), str, ... )
193+
end
194+
end
195+
end
196+
197+
local plibColor = GetColor( 'plib' )
198+
function Logger( name, color )
199+
ArgAssert( name, 1, 'string' )
200+
return setmetatable({
201+
['Color'] = color or plibColor,
202+
['Name'] = name
203+
}, meta)
120204
end
121205

122206
end

0 commit comments

Comments
 (0)