-- 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 HttpService = TS.import(script, TS.getModule(script, "@rbxts", "services")).HttpService local mergeConfigs = TS.import(script, script.Parent.Parent, "configuration").mergeConfigs local rLog = TS.import(script, script.Parent.Parent, "rlog").rLog local LogContextManager = TS.import(script, script.Parent, "log-context-manager").LogContextManager local function GenerateCorrelationID(config) if config.correlationGenerator then return config.correlationGenerator() end return `{DateTime.now().UnixTimestamp}_{HttpService:GenerateGUID(false)}` end --[[ * * Context for a collection of log entries. * * @remarks * * Provides a centrialized means for tracking correlation ids, * allowing you to create a linkage between log entries in individual * logic flows- enabling more streamlined debugging in high traffic or * asynchronous environments. * * @see {@link LogContext.start | start}, {@link RLog.ForceContextFlush | ForceContextFlush} * * @public ]] local LogContext do LogContext = setmetatable({}, { __tostring = function() return "LogContext" end, }) LogContext.__index = LogContext function LogContext.new(...) local self = setmetatable({}, LogContext) return self:constructor(...) or self end function LogContext:constructor(correlation_id, config) self.correlation_id = correlation_id self.config = config self._dead = false end function LogContext:IsDead() return self._dead end function LogContext:withConfig(config) if self._dead then error("Attempted to use a dead LogContext via `LogContext.withConfig`") end return LogContext.new(self.correlation_id, mergeConfigs(self.config, config)) end function LogContext:use(config) if self._dead then error("Attempted to use a dead LogContext via `LogContext.use`") end return rLog.new(config, self) end function LogContext:stop() self._dead = true LogContextManager.flush(self) end function LogContext:start(config) local finalConfig = mergeConfigs(config) local id = GenerateCorrelationID(finalConfig) return LogContext.new(id, finalConfig) end end return { LogContext = LogContext, }