Skip to content

Instantly share code, notes, and snippets.

@gaymeowing
Last active December 30, 2023 08:06
Show Gist options
  • Save gaymeowing/7dcf8f5b7a7ccf4121bcae3bc47d6aa5 to your computer and use it in GitHub Desktop.
Save gaymeowing/7dcf8f5b7a7ccf4121bcae3bc47d6aa5 to your computer and use it in GitHub Desktop.
--!strict
-- ConsoleFormatter
-- A utility module for easily formatting outputs for print, warn and errors!
-- @Kalrnlo
-- 30/12/2023
export type OutputType = "Critical" | "Warning" | "Error" | "Log" | "Debug" | "1" | "2" | "3" | "4" | "5"
local DefualtFormat = "[%s][%s] :: "
local OutputTypes = {
[1] = "Debug",
[2] = "Log",
[3] = "Warning",
[4] = "Error",
[5] = "Critical"
}
return function(Script: BaseScript | string, Format: string?)
local ScriptName = if typeof(Script) == "Instance" then Script.Name else Script
local Format = Format or DefualtFormat
return function(OutputType: OutputType | number, ...: any)
local OutputType = if tonumber(OutputType) then OutputTypes[OutputType :: number] else OutputType
return string.format(Format, ScriptName, OutputType), ...
end
end
--!strict
local ConsoleFormatter = require("ConsoleFormatter")
local Format = ConsoleFormatter(script)
print(Format "Log", "Hello World!") -- [script][Log] :: Hello World
ͺ
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment