Deltarix Scripts
TebexDiscord
  • Information
    • About Me - Deltarix
  • Keymaster
    • FiveM Asset Escrow
    • Authentication
    • Transfers
  • Paid Assets
    • MDT V3
      • Setup Guide
      • Configurations
        • Settings
        • Graphics
        • Locales
        • Themes
      • Exports
        • Server
          • OpenMDT
          • CloseMDT
          • CreateLog
          • GetBoloByLinkedId
          • GetIdentifierByStateId
          • GetOfficerByBadgenumber
          • GetOfficerByStateId
          • GetOfficerExists
          • GetOfficerFiredByStateId
          • GetOfficerSuspendedByStateId
          • GetPlayerFullNameByStateId
          • GetStateIdBySource
          • GetWantedByLinkedId
      • Public
        • Bridges
          • Server
            • Framework
              • qbx_core
              • qb-core
              • es_extended
            • Garage
              • qbx_garages
              • qb-garages
              • jg-advancedgarages
            • Inventory
              • ox_inventory
            • Licence
              • qbx_core
              • qb-core
            • Media
              • fivemanage
            • Property
              • qbx_properties
              • qb-apartments
              • qb-houses
              • qb-apartments & qb-housing
              • nolag_properties
              • qbx_properties & nolag_properties
        • Functions
          • Server
            • Create Card
            • Log
            • Prints
          • Client
            • Waypoint
            • Anim
      • Dependencies
    • MDT V2
      • Setup
      • Locales
      • Configurations
        • Server
        • Client
        • Settings
        • 10 Codes
        • Commands
      • Exports
        • Server
          • OpenMDT
          • OpenVehicleDetailsInMDT
          • GetStateId
          • GetOfficer
          • GetPlayerWanted
          • GetPlateFlagged
          • GetOfficerSuspended
          • GetWeaponRegistered
          • GetOfficerClockedIn
          • GetClosestCamera
          • CreateWeapon
          • CreateOfficer
          • DeleteOfficer
          • UpdateCitizenData
          • UpdateCitizenPoints
          • ToggleCamera
          • ToggleCameraTimeout
          • ToggleClock
        • Client
          • OpenMDT
          • InsertPhotoToGallery
      • Bridges
        • Server
          • Framework
            • es_extended
            • qb-core
            • qbx_core
          • Garage
            • esx_garage
            • qb-garages
            • qbx_garages
          • Inventory
            • ox_inventory
            • qb-inventory
          • Licence
            • es_extended
            • qb-core
            • qbx_core
          • Property
            • esx_property
            • qb-apartments
            • qbx_apartments
          • Utilities
            • Logger
        • Client
          • Garage
            • esx_garage
            • qb-garages
            • qbx_garages
          • Utilities
            • Camera
      • Dependencies
      • Known Bugs
      • Common Issues and Troubleshooting
    • Dispatch
      • Exports
        • Server
          • Notifications
          • IsDispatcher
          • GetDispatchersByGroup
          • GetGroups
          • GetStateId
        • Client
          • defaultNotification
          • officerNotification
          • dispatchNotification
          • Copy of dispatchNotification
      • Dependencies
Powered by GitBook
On this page

Was this helpful?

  1. Paid Assets
  2. MDT V3
  3. Public
  4. Functions
  5. Server

Prints


--- Configuration options for print/logging functions.
-- @field enabled Enables or disables all logging.
-- @field info Enables informational messages.
-- @field warn Enables warning messages.
-- @field error Enables error messages.
-- @field success Enables success messages.
-- @field debug Enables debug messages.
local options = {
  enabled = true,
  info = true,
  warn = true,
  error = true,
  success = true,
  debug = true,
}

local prefixes = {
  info = '[^4INFO^7]',
  warn = '[^3WARN^7]',
  error = '[^1ERROR^7]',
  success = '[^2SUCCESS^7]',
  debug = '[^6DEBUG^7]',
}

local template = '^7%s - %s^7'

local function handleException(reason, value)
  if type(value) == 'function' then return tostring(value) end
  return reason
end

local jsonOptions = { sort_keys = true, indent = true, exception = handleException }

local function log(level, fmt, ...)
  if not options.enabled or not options[level] then return end

  local args = { ... }
  if #args == 0 then
    print(template:format(prefixes[level], fmt))
    return
  end

  for i = 1, #args do
    local arg = args[i]
    args[i] = type(arg) == 'table' and json.encode(arg, jsonOptions) or tostring(arg)
  end

  local message = string.format(fmt, table.unpack(args))
  print(template:format(prefixes[level], message))
end

prints = {
  info    = function(fmt, ...) log('info', fmt, ...) end,
  warn    = function(fmt, ...) log('warn', fmt, ...) end,
  error   = function(fmt, ...) log('error', fmt, ...) end,
  success = function(fmt, ...) log('success', fmt, ...) end,
  debug   = function(fmt, ...) log('debug', fmt, ...) end,
}

Last updated 5 days ago

Was this helpful?