@rbxts/rlog
Version:
Context-based server-side logging solution for ROBLOX projects.
110 lines • 3.4 kB
TypeScript
/**
* @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.
*/
import { LogEntry, LogLevel } from "../common";
/**
* 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
*/
export type FormatMethodCallback = (entry: LogEntry) => LuaTuple<unknown[]>;
/**
* 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
*/
export type OutputMethodCallback = (entry: LogEntry, messages: LuaTuple<unknown[]>) => void;
/**
* Configuration options for {@link robloxConsoleSink}.
*
* @public
*/
export interface RobloxConsoleSinkConfig {
/**
* Optional method to convert log entries to output.
*
* @see {@link RobloxConsoleSinkConfig.outputMethod}
*
* @example
* ```ts
* export const customFormatMethod: FormatMethodCallback = (entry) => {
* return $tuple(entry.message, entry.encoded_data);
* };
* ```
*/
readonly formatMethod?: FormatMethodCallback;
/**
* Optional method to send output to the roblox console.
*
* By default, logs above {@link LogLevel.WARNING} will be sent
* through `warn`, and the rest through `print`.
*
* @see {@link RobloxConsoleSinkConfig.formatMethod}
*
* @example
* ```ts
* export const customOutputMethod: OutputMethodCallback = (entry, messages) => {
* print(...messages);
* };
* ```
*/
readonly outputMethod?: OutputMethodCallback;
/**
* The minimum {@link LogLevel} to send through to the roblox console.
*
* Any logs with a level below this will not be sent to the roblox console, but will
* still be sent to other sinks.
*/
readonly minLogLevel?: LogLevel;
/**
* Completely disable sending messages to the roblox console.
*
* Can be used for quick toggling in debug or conditionally toggling
* the roblox console.
*/
readonly disable?: boolean;
}
/**
* 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
*/
export declare function robloxConsoleSink(params?: RobloxConsoleSinkConfig): (entry: LogEntry) => true | undefined;
//# sourceMappingURL=roblox-console-sink.d.ts.map