@future-widget-lab/logger
Version:
A good enough logger for client-side oriented applications.
113 lines (112 loc) • 3.33 kB
TypeScript
import { LogLevelDesc } from 'loglevel';
import type { ShouldDebug } from '../should-debug/should-debug.helper';
type OnMessageOptions = {
level: LogLevelDesc;
timestamp: string;
payload: object;
message: string;
};
type OnAfterMessageOptions = {
level: LogLevelDesc;
timestamp: string;
payload: object;
message: string;
};
type CreateLoggerOptions = {
/**
* @description
* Use this to set the default log level.
*
* Note: Debug level logs are controlled via URL search parameters. Please check `allTag` and `debugSearchParameterName` if you wish to customize the behavior.
*/
level: LogLevelDesc;
/**
* @description
* Use this to set the "catch-all" tag for debugging purposes.
*
* Defaults to "all".
*
* @example
* const logger = createLogger({
* allTag: "all" // or any other joker string you'd like to use.
* });
*
* // You are able to see all the debug level logs by setting your search params to `?debug=all`.
*/
allTag?: string;
/**
* @description
* Use this to set the name of the search parameter which signals the debug logs should be printed.
*
* Defaults to "debug".
*
* @example
* const logger = createLogger({
* ...,
* debugSearchParameterName: "debug" // or any other string you'd like to use.
* });
*
* logger.debug("auth-module", { ok: true }, "Systems online.")
*
* // In order to print the log you'd need to update your URL with this search parameter `?debug=auth-module`.
*/
debugSearchParameterName?: string;
/**
* @description
* Use this to set a custom function that determines if a debug level log should be printed or not.
*/
shouldDebug?: ShouldDebug;
/**
* @description
* Use this to set an emoji for the debug level logs.
*
* Defaults to 🕵️.
*/
debugEmoji?: string;
/**
* @description
* Use this to set an emoji for the error logs.
*
* Defaults to 📕.
*/
errorEmoji?: string;
/**
* @description
* Use this to set an emoji for the info level logs.
*
* Defaults to 📘.
*/
infoEmoji?: string;
/**
* @description
* Use this to set an emoji for the trace level logs.
*
* Defaults to 📓.
*/
traceEmoji?: string;
/**
* @description
* Use this to set an emoji for the warn level logs.
*
* Defaults to 📒.
*/
warnEmoji?: string;
/**
* @description
* Use this to have fine-graned control over the message being rendered.
*/
onMessage?: (options: OnMessageOptions) => string;
/**
* @description
* Use this to perform a side-effect once the message has been printed.
*/
onAfterMessage?: (options: OnAfterMessageOptions) => void;
};
export declare const createLogger: (options: CreateLoggerOptions) => {
readonly debug: (tag: string, object: object, message: string) => void;
readonly error: (object: object, message: string) => void;
readonly info: (object: object, message: string) => void;
readonly trace: (object: object, message: string) => void;
readonly warn: (object: object, message: string) => void;
};
export {};