-- Compiled with roblox-ts v2.3.0-dev-30dae68 local TS = _G[script] --[[ * * @license * Copyright 2024 Daymon Littrell-Reyes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. ]] local Object = TS.import(script, TS.getModule(script, "@rbxts", "object-utils")) local HttpService = TS.import(script, TS.getModule(script, "@rbxts", "services")).HttpService local LogLevel = TS.import(script, script.Parent.Parent, "common").LogLevel --[[ * * Type representing a callback function for converting log entries to output. * * @param entry - The log entry to convert. * * @returns A tuple of arguments to output in the entry's place * * @public ]] --[[ * * Type representing a callback function for sending a log to the roblox console. * * @param entry - The entry from where this log came from. * @param messages - A tuple of arguments to output in the entry's place. * * @public ]] --[[ * * Configuration options for {@link robloxConsoleSink}. * * @public ]] --[[ * * The default sink for sending messages to the roblox console. * * @remarks * * By default, this is already applied at the root level through the default instance. * * @param params - {@link RobloxConsoleSinkConfig} options for this sink. * * @returns A sink that should be added to a config. * * @example * ```ts * const logger = new rLog({ * sinks: [ * robloxConsoleSink({ formatMethod: myCustomMethod }), * ], * }); * ``` * * @public ]] local defaultFormatEntry, defaultOutputEntry local function robloxConsoleSink(params) if params == nil then params = {} end local _binding = params local formatMethod = _binding.formatMethod local outputMethod = _binding.outputMethod local minLogLevel = _binding.minLogLevel local disable = _binding.disable return function(entry) if disable then return nil end if minLogLevel ~= nil and entry.level < minLogLevel then return nil end local formatEntry = formatMethod or defaultFormatEntry local outputEntry = outputMethod or defaultOutputEntry local output = { formatEntry(entry) } outputEntry(entry, output) return true end end defaultOutputEntry = function(entry, messages) if entry.level >= LogLevel.WARNING then warn(unpack(messages)) else print(unpack(messages)) end end function defaultFormatEntry(entry) local tag = if entry.config.tag ~= nil then `{entry.config.tag} -> ` else "" local _object = {} local _left = "correlation_id" local _result = entry.context if _result ~= nil then _result = _result.correlation_id end _object[_left] = _result _object.timestamp = entry.timestamp _object.data = if Object.isEmpty(entry.encoded_data) then nil else entry.encoded_data local data = _object return `[{LogLevel[entry.level]}]:`, `{tag}{entry.message}\n{HttpService:JSONEncode(data)}` end return { robloxConsoleSink = robloxConsoleSink, }