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 {}
|
Prints = Prints or {}
|
||||||
local function printMessage(level, color, message)
|
|
||||||
if type(message) == 'table' then
|
local function handle(result, value)
|
||||||
message = json.encode(message)
|
if type(value) == 'function' then
|
||||||
|
return tostring(value)
|
||||||
end
|
end
|
||||||
print(color .. '[' .. level .. ']:', message)
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function format(color, ...)
|
||||||
---This will print a colored message to the console with the designated prefix.
|
local data = {...}
|
||||||
---@param message string
|
for i = 1, #data do
|
||||||
Prints.Info = function(message)
|
if data[i] == nil then
|
||||||
printMessage('INFO', '^5', message)
|
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
|
end
|
||||||
|
|
||||||
---This will print a colored message to the console with the designated prefix.
|
---This will print a colored message to the console with the designated prefix.
|
||||||
---@param message string
|
---@param message string
|
||||||
Prints.Warn = function(message)
|
Prints.Info = function(...)
|
||||||
printMessage('WARN', '^3', message)
|
print('^5 [INFO] '.. format('^5 ', ...))
|
||||||
end
|
end
|
||||||
|
|
||||||
---This will print a colored message to the console with the designated prefix.
|
---This will print a colored message to the console with the designated prefix.
|
||||||
---@param message string
|
---@param message string
|
||||||
Prints.Error = function(message)
|
Prints.Warn = function(...)
|
||||||
printMessage('ERROR', '^1', message)
|
print('^3 [WARN] '.. format('^3', ...))
|
||||||
end
|
end
|
||||||
|
|
||||||
---This will print a colored message to the console with the designated prefix.
|
---This will print a colored message to the console with the designated prefix.
|
||||||
---@param message string
|
---@param message string
|
||||||
Prints.Debug = function(message)
|
Prints.Error = function(...)
|
||||||
printMessage('DEBUG', '^2', message)
|
print('^1 [ERROR] '.. format('^1', ...))
|
||||||
end
|
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