feature Prints now auto formats json to go downwards in prints so its easier to read
`useCase`
```lua
Prints.Debug('GTA', 5, {is = true, cool = true})
```
This commit is contained in:
1 parent
d7c58b6bf4
commit
b96a64f371
1 file changed
+47
-16
@@ -1,34 +1,65 @@
|
||||
Prints = Prints or {}
|
||||
local function printMessage(level, color, message)
|
||||
if type(message) == 'table' then
|
||||
message = json.encode(message)
|
||||
|
||||
local function handle(result, value)
|
||||
if type(value) == 'function' then
|
||||
return tostring(value)
|
||||
end
|
||||
print(color .. '[' .. level .. ']:', message)
|
||||
return result
|
||||
end
|
||||
|
||||
|
||||
---This will print a colored message to the console with the designated prefix.
|
||||
---@param message string
|
||||
Prints.Info = function(message)
|
||||
printMessage('INFO', '^5', message)
|
||||
local function format(color, ...)
|
||||
local data = {...}
|
||||
for i = 1, #data do
|
||||
if data[i] == nil then
|
||||
data[i] = 'nil'
|
||||
end
|
||||
end
|
||||
local newForm = {}
|
||||
local jsonDecode = {sort_keys = true, indent = true, exception = handle}
|
||||
for k, v in pairs(data) do
|
||||
local formatted
|
||||
if type(v) == 'table' then
|
||||
formatted = json.encode(v, jsonDecode)
|
||||
elseif type(v) == 'number' then
|
||||
formatted = tostring(v)
|
||||
elseif type(v) == 'boolean' then
|
||||
formatted = tostring(v)
|
||||
elseif type(v) == 'nil' then
|
||||
formatted = 'nil Value'
|
||||
elseif type(v) == 'string' then
|
||||
formatted = v
|
||||
elseif type(v) == 'function' then
|
||||
formatted = tostring(v)
|
||||
else
|
||||
formatted = tostring(v)
|
||||
end
|
||||
table.insert(newForm, color .. formatted)
|
||||
end
|
||||
return table.concat(newForm, color .. ' \n ')
|
||||
end
|
||||
|
||||
---This will print a colored message to the console with the designated prefix.
|
||||
---@param message string
|
||||
Prints.Warn = function(message)
|
||||
printMessage('WARN', '^3', message)
|
||||
Prints.Info = function(...)
|
||||
print('^5 [INFO] '.. format('^5 ', ...))
|
||||
end
|
||||
|
||||
---This will print a colored message to the console with the designated prefix.
|
||||
---@param message string
|
||||
Prints.Error = function(message)
|
||||
printMessage('ERROR', '^1', message)
|
||||
Prints.Warn = function(...)
|
||||
print('^3 [WARN] '.. format('^3', ...))
|
||||
end
|
||||
|
||||
---This will print a colored message to the console with the designated prefix.
|
||||
---@param message string
|
||||
Prints.Debug = function(message)
|
||||
printMessage('DEBUG', '^2', message)
|
||||
Prints.Error = function(...)
|
||||
print('^1 [ERROR] '.. format('^1', ...))
|
||||
end
|
||||
|
||||
return Prints
|
||||
---This will print a colored message to the console with the designated prefix.
|
||||
---@param message string
|
||||
Prints.Debug = function(...)
|
||||
print('^2 [DEBUG] '.. format('^2', ...))
|
||||
end
|
||||
|
||||
return Prints
|
||||
Reference in new issue
Block a user