Console
A package that helps to organise the Roblox output, primarily offering developers quality of life features over the default Roblox output behaviour.
Properties
id
Console.id <string (opens in a new tab)>
level
Console.level <number (opens in a new tab)>
schema
Console.schema <string (opens in a new tab)>
enabled
Console.enabled <boolean (opens in a new tab)>
logs
Console.logs <{ }>
Methods
Assert
Console:Assert(
condition
boolean? (opens in a new tab),message
... ) -> nil (opens in a new tab)
Assertions, however written through our Console, if the condition isn't met, the Console will call :error on itself with the given message.
local Console = Console.new("Console")
Console:Assert(1 == 1, "Hello, World!") -- > will output: nothing
Console:Assert(1 == 2, "Hello, World!") -- > will output: [Console][error]: "Hello, World!" <stack attached>
Critical
Console:Critical(
message
... ) -> nil (opens in a new tab)
Create a new log for 'critical', critical being deployed in a situation where something has gone terribly wrong.
local Console = Console.new("Console")
Console:Critical("Hello, World!") -- > will output: [Console][critical]: "Hello, World!" <stack attached>
Error
Console:Error(
message
... ) -> nil (opens in a new tab)
Create a new log for 'error', this is for errors raised through a developers code on purpose.
local Console = Console.new("Console")
Console:Error("Hello, World!") -- > will output: [Console][error]: "Hello, World!" <stack attached>
Warn
Console:Warn(
message
... ) -> nil (opens in a new tab)
Create a new log for 'warn', this is for informing developers about something which takes precedence over a log
local Console = Console.new("Console")
Console:Warn("Hello, World!") -- > will output: [Console][warn]: "Hello, World!"
Log
Console:Log(
message
... ) -> nil (opens in a new tab)
Create a new log for 'log', this is for general logging - ideally what we would use in-place of print.
local Console = Console.new("Console")
Console:Log("Hello, World!") -- > will output: [Console][log]: "Hello, World!"
Debug
Console:Debug(
message
... ) -> nil (opens in a new tab)
Create a new log for 'debug', typically we should only use 'debug' when debugging code or leaving hints for developers.
local Console = Console.new("Console")
Console:Debug("Hello, World!") -- > will output: [Console][debug]: "Hello, World!"
SetLogLevel
Console:SetLogLevel(
logLevel
number (opens in a new tab) ) -> nil (opens in a new tab)
Set an log level for this Console, log levels assigned per Console override the global log level.
LogLevels that are by default set in Console
:
- 1 = Debug
- 2 = Log
- 3 = Warn
- 4 = Error
- 5 = Critical
As an alternative, Console provides a LogLevel
enum, you can access this enum like: Console.LogLevel.Debug
local Console = ConsoleModule.new("Console")
ConsoleModule.setGlobalLogLevel(Console.LogLevel.Warn)
Console:Log("Hello, World!") -- this will NOT output anything
Console:Warn("Hello, World!") -- this will output something
Console:SetLogLevel(Console.LogLevel.Log)
Console:Log("Hello, World!") -- this will output something
Console:Warn("Hello, World!") -- this will output something
SetTracebackEnabled
Console:SetTracebackEnabled(
traceback
boolean (opens in a new tab) ) -> nil (opens in a new tab)
Enable/Disable traceback logging for the 'Console' object
local reporter = Console.new("🔥 CoolReporter")
reporter:SetTracebackEnabled(true)
reporter:Log("Hello, World") --[[
["🔥 CoolReporter"]["log"]: "Hello, World"
["🔥 CoolReporter"]["traceback"]: begin
Script 'ServerScriptService.Place.Services.GameLoopService', Line 30 - function OnGameStateBlocking
Script 'ServerScriptService.Place.Services.GameLoopService', Line 48
Script 'ReplicatedStorage.Packages._Index.sleitnick_signal@1.5.0.signal', Line 56 - function acquireRunnerThreadAndCallEventHandler
Script 'ReplicatedStorage.Packages._Index.sleitnick_signal@1.5.0.signal', Line 67 - function runEventHandlerInFreeThread
["🔥 CoolReporter"]["traceback"]: end
]]
SetState
Console:SetState(
state:
boolean (opens in a new tab) ) -> nil (opens in a new tab)
Sets the state of the Console, state depicts if the Console can log messages into the output.
local Console = Console.new("Console")
Console:Log("Hello, World!") -- > will output: [Console][log]: "Hello, World!"
Console:SetState(false)
Console:Log("Hello, World!") -- > will output: nothing
FetchLogs
Console:FetchLogs(
count:
number? (opens in a new tab) ) -> { [number]: { logType: string, message: string, logId: string } }
Fetch an array of logs generated through this Console
local Console = Console.new("Console")
Console:Log("Hello, World!") -- > [Console][log]: "Hello, World!"
Console:FetchLogs() -- > [[
{
logType = "log",
message = "[Console][log]: \"Hello, World!\"",
logId = "Console"
}
]]--
ToString
Console:ToString() -> string (opens in a new tab)
Returns a prettified string version of the Console table.
local Value = State.new(0)
print(tostring(Value)) -- Value<0>
Functions
setGlobalLogLevel
Console.setGlobalLogLevel(
logLevel
number (opens in a new tab) ) -> nil (opens in a new tab)
Set the global log level for all Consoles, a log level is the priority of a log, priorities are represented by a number.
LogLevels that are by default set in Console
:
- 1 = Debug
- 2 = Log
- 3 = Warn
- 4 = Error
- 5 = Critical
As an alternative, Console provides a LogLevel
enum, you can access this enum like: Console.LogLevel.Debug
Console.setGlobalLogLevel(Console.LogLevel.Warn)
Console:log("Hello, World!") -- this will NOT output anything
Console:warn("Hello, World!") -- this will output something
setGlobalSchema
Console.setGlobalSchema(
schema
string (opens in a new tab) ) -> nil (opens in a new tab)
Set the global schema for all Consoles, a schema is how the log is displayed in the console.
Console.setGlobalSchema("[%s][%s]: %s")
Console:log("Hello, World!") -- > [<ReporterName>][log]: Hello, World!
get
Console.get(
logId
string (opens in a new tab) ) -> Console?
Fetch a Console
object through it's given logId
Console.get("Console"):log("Hello, World!") -- > [Console][log]: "Hello, World!"
new
Console.new(
logId
string? (opens in a new tab),schema
string? (opens in a new tab) ) -> Console
Constructor to generate a Console
prototype
Console.new("Example"):log("Hello, World!") -- > [Example][log]: "Hello, World!"
newOrphaned
Console.newOrphaned(
logId
string? (opens in a new tab),schema
string? (opens in a new tab) ) -> Console
Constructor to generate an orphaned Console
prototype, orphaned in this case meaning a console object that the Console library will
not track or monitor, thus any global console updates will not be applied to this console object.
This should be used when using Console
in a library so that any game Consoles
are isolated from the libraries Consoles
Console.newOrphaned("Example"):log("Hello, World!") -- > [Example][log]: "Hello, World!"
Only avaliable in version 2.0.4 and above
is
Console.is(
object
Console? ) -> boolean (opens in a new tab)
Validate if an object is a 'Console' object
local object = Console.new("Test")
if Console.is(object) then
...
end