Skip to content

Print Utilities

Side: Shared (Client + Server)

Global print functions with color support and debug mode. These are registered as global functions (not under tw.*).

Functions

log(...)

Prints to the console. Tables are JSON-formatted for readability. No color applied.

ParameterTypeDescription
...anyValues to print. Tables are serialized to JSON

sprint(...) / eprint(...)

Prints in red text. Useful for errors.

ParameterTypeDescription
...anyValues to print

gprint(...)

Prints in green text. Useful for success messages.

ParameterTypeDescription
...anyValues to print

oprint(...) / wprint(...)

Prints in orange text. Useful for warnings.

ParameterTypeDescription
...anyValues to print

bprint(...)

Prints in blue text. Useful for informational messages.

ParameterTypeDescription
...anyValues to print

dprint(cb_or_msg, ...)

Debug print. Only outputs when Config.Debug is truthy. Supports %s/%d format strings.

ParameterTypeDescription
cb_or_msgfunction or stringIf a function, calls it and prints the return value. If a string, formats with remaining args
...anyFormat arguments (when cb_or_msg is a string)

Inline Colors

All print functions support inline color tags within strings:

TagColor
~red~Red
~green~Green
~orange~Orange
~blue~Blue

Examples

Basic logging

lua
log("Server started")
log("Player data:", { name = "John", job = "sheriff" })
-- Output: Server started
-- Output: Player data: {"name":"John","job":"sheriff"}

Colored output

lua
gprint("Successfully loaded", resource_name)
sprint("Failed to connect to database")
oprint("Warning: config value missing, using default")
bprint("Processing", #items, "items")

Debug print (only when Config.Debug is true)

lua
Config.Debug = true

-- Simple format string
dprint("Player %s collected %d items", player_name, count)

-- With a callback (evaluated only if debug is on)
dprint(function()
    return "Expensive debug info: " .. json.encode(large_table)
end)

Inline color tags

lua
log("Status: ~green~OK~red~ errors: 0")
oprint("Item ~blue~bandage~orange~ added to inventory")

Notes

  • log serializes tables to JSON automatically, making it convenient for inspecting data structures.
  • dprint checks Config.Debug before evaluating its arguments. When passing a function, the function is only called if debug mode is active, avoiding unnecessary computation in production.
  • Color output depends on terminal/console support. In the FiveM/RedM server console, ANSI colors are supported.

Premium RedM Scripts — Multi-Framework