UNPKG

mwn

Version:

JavaScript & TypeScript MediaWiki bot framework for Node.js

106 lines (105 loc) 3.04 kB
/** * semlog * A semantic logger that colors and formats messages automatically according to the content * * Adapted from https://github.com/Fannon/semlog * * @author Simon Heimler * @author Siddharth VP - removed use of globals and adapted to TypeScript, * also removed some unnecessary features like in-memory log retention * and keeping track of statistics */ import * as stream from 'node:stream'; export interface LogConfig { /** Whether debug level log (starting with [D]) should be printed */ printDebug?: boolean; /** Whether verbose logs (starting with [D]) should be printed */ printVerbose?: boolean; /** * The writable stream for logs. Defaults to stdout. To log to a file, use * ```js * fs.createWriteStream(__dirname + '/mwn.log', { * flags: 'a', * encoding: 'utf8' * }) * ``` */ stream?: stream.Writable; } /** * Configure global logging options. * * Note: To suppress API warnings, use `suppressAPIWarnings` flag in bot instance options instead. */ export declare function updateLoggingConfig(options: LogConfig): void; /** Type of item logged */ type item = any; /** * Custom Logging function * * Writes logs to console or file, stringifies objects first * * @param obj */ export declare function log(obj: item): void; export declare function message(msg: item): void; /** * Prints out debugging information for the current model object * @param obj */ export declare function debug(obj: item): void; /** * Prints errors * @param obj */ export declare function error(obj: Error): void; declare const colorMap: { readonly '[E]': "red"; readonly '[W]': "yellow"; readonly '[?]': "yellow"; readonly '[S]': "green"; readonly '[i]': "blue"; readonly '[+]': "green"; readonly '[-]': "red"; readonly '[C]': "cyan"; readonly '[U]': "gray"; readonly '[=]': "gray"; readonly '[/]': "gray"; readonly '[V]': "magenta"; readonly '[D]': "magenta"; readonly '[T]': "magenta"; readonly '[TODO]': "magenta"; }; /** * Colors the messages by searching for specific indicator strings * * @param {string} msg * @param {string} colorName * @returns {string} */ export declare function colorize(msg: item, colorName?: (typeof colorMap)[keyof typeof colorMap]): any; /** * Pad a number with n digits * * @param {number} number number to pad * @param {number} digits number of total digits * @returns {string} */ export declare function pad(number: number, digits: number): string; /** * Returns an array with date / time information * Starts with year at index 0 up to index 6 for milliseconds * * @param {Date} date Optional date object. If falsy, will take current time. * @returns {Array} */ export declare function getDateArray(date: Date): (string | number)[]; /** * Returns nicely formatted date-time * @example 2015-02-10 16:01:12 * * @param {object} [date] * @returns {string} */ export declare function humanDate(date?: Date): string; export {};