UNPKG

@sapphire/plugin-logger

Version:

Plugin for @sapphire/framework to have pretty console output

1 lines 2.69 kB
{"version":3,"sources":["../../../src/lib/LoggerLevel.ts"],"names":[],"mappings":";;;;;;;;;AAAA,SAAS,mBAA+C;AACxD,SAAS,uBAAoD;AAMtD,IAAM,eAAN,MAAM,aAAY;AAAA,EAmBjB,YAAY,UAA8B,CAAC,GAAG;AAdrD;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAMP;AAAA;AAAA;AAAA;AAAA,wBAAO;AAGN,SAAK,YAAY,QAAQ,cAAc,OAAO,OAAO,IAAI,gBAAgB,QAAQ,SAAS;AAC1F,SAAK,QAAQ,QAAQ,SAAS;AAC9B,SAAK,UAAU,QAAQ,YAAY,OAAO,OAAO,IAAI,YAAY,QAAQ,OAAO;AAAA,EACjF;AAAA,EAEO,IAAI,SAAiB;AAC3B,UAAM,UAAU,KAAK,WAAW,IAAI,KAAK,MAAM,KAAK;AAEpD,QAAI,OAAO,QAAQ;AAClB,YAAM,YAAY,KAAK,UACpB,CAAC,SAAiB,SAAS,KAAK,QAAS,IAAI,IAAI,IACjD,CAAC,SAAiB,SAAS;AAC9B,aAAO,QAAQ,MAAM,IAAI,EAAE,IAAI,SAAS,EAAE,KAAK,IAAI;AAAA,IACpD;AAEA,WAAO,KAAK,UAAU,KAAK,QAAQ,IAAI,OAAO,IAAI;AAAA,EACnD;AACD;AArCyB;AAAlB,IAAM,cAAN","sourcesContent":["import { LoggerStyle, type LoggerStyleResolvable } from './LoggerStyle';\nimport { LoggerTimestamp, type LoggerTimestampOptions } from './LoggerTimestamp';\n\n/**\n * Logger utility that stores and applies a full style into the message.\n * @since 1.0.0\n */\nexport class LoggerLevel {\n\t/**\n\t * The timestamp formatter.\n\t * @since 1.0.0\n\t */\n\tpublic timestamp: LoggerTimestamp | null;\n\n\t/**\n\t * The infix, added between the timestamp and the message.\n\t * @since 1.0.0\n\t */\n\tpublic infix: string;\n\n\t/**\n\t * The style formatter for the message.\n\t * @since 1.0.0\n\t */\n\tpublic message: LoggerStyle | null;\n\n\tpublic constructor(options: LoggerLevelOptions = {}) {\n\t\tthis.timestamp = options.timestamp === null ? null : new LoggerTimestamp(options.timestamp);\n\t\tthis.infix = options.infix ?? '';\n\t\tthis.message = options.message === null ? null : new LoggerStyle(options.message);\n\t}\n\n\tpublic run(content: string) {\n\t\tconst prefix = (this.timestamp?.run() ?? '') + this.infix;\n\n\t\tif (prefix.length) {\n\t\t\tconst formatter = this.message //\n\t\t\t\t? (line: string) => prefix + this.message!.run(line)\n\t\t\t\t: (line: string) => prefix + line;\n\t\t\treturn content.split('\\n').map(formatter).join('\\n');\n\t\t}\n\n\t\treturn this.message ? this.message.run(content) : content;\n\t}\n}\n\n/**\n * The options for {@link LoggerLevel}.\n * @since 1.0.0\n */\nexport interface LoggerLevelOptions {\n\t/**\n\t * The timestamp options. Set to `null` to disable timestamp parsing.\n\t * @since 1.0.0\n\t * @default {}\n\t */\n\ttimestamp?: LoggerTimestampOptions | null;\n\n\t/**\n\t * The infix to be included between the timestamp and the message.\n\t * @since 1.0.0\n\t * @default ''\n\t */\n\tinfix?: string;\n\n\t/**\n\t * The style options for the message.\n\t * @since 1.0.0\n\t * @default colorette.clear\n\t */\n\tmessage?: LoggerStyleResolvable | null;\n}\n"]}