@sapphire/plugin-logger
Version:
Plugin for @sapphire/framework to have pretty console output
1 lines • 3.72 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/lib/LoggerTimestamp.ts"],"names":["Timestamp","LoggerStyle"],"mappings":";;;;;;;;;AAOO,IAAM,gBAAA,GAAN,MAAM,gBAAgB,CAAA;AAAA,EAyBrB,WAAA,CAAY,OAAkC,GAAA,EAAI,EAAA;AApBzD;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,OAAA,CAAA;AAMP;AAAA;AAAA;AAAA;AAAA,IAAO,aAAA,CAAA,IAAA,EAAA,WAAA,CAAA;AAGN,IAAA,IAAA,CAAK,SAAY,GAAA,IAAIA,mBAAU,CAAA,OAAA,CAAQ,WAAW,qBAAqB,CAAA;AACvE,IAAK,IAAA,CAAA,GAAA,GAAM,QAAQ,GAAO,IAAA,KAAA;AAC1B,IAAK,IAAA,CAAA,KAAA,GAAQ,QAAQ,KAAU,KAAA,IAAA,GAAO,OAAO,IAAIC,2BAAA,CAAY,QAAQ,KAAK,CAAA;AAC1E,IAAA,IAAA,CAAK,YAAY,OAAQ,CAAA,SAAA,KAAc,CAAC,SAAA,KAAc,GAAG,SAAS,CAAA,GAAA,CAAA,CAAA;AAAA;AACnE;AAAA;AAAA;AAAA;AAAA,EAMO,GAAM,GAAA;AACZ,IAAM,MAAA,IAAA,uBAAW,IAAK,EAAA;AACtB,IAAM,MAAA,MAAA,GAAS,IAAK,CAAA,GAAA,GAAM,IAAK,CAAA,SAAA,CAAU,UAAW,CAAA,IAAI,CAAI,GAAA,IAAA,CAAK,SAAU,CAAA,OAAA,CAAQ,IAAI,CAAA;AACvF,IAAO,OAAA,IAAA,CAAK,UAAU,IAAK,CAAA,KAAA,GAAQ,KAAK,KAAM,CAAA,GAAA,CAAI,MAAM,CAAA,GAAI,MAAM,CAAA;AAAA;AAEpE,CAAA;AAzC6B,MAAA,CAAA,gBAAA,EAAA,iBAAA,CAAA;AAAtB,IAAM,eAAN,GAAA","file":"LoggerTimestamp.cjs","sourcesContent":["import { Timestamp } from '@sapphire/timestamp';\nimport { LoggerStyle, type LoggerStyleResolvable } from './LoggerStyle';\n\n/**\n * Logger utility that formats a timestamp.\n * @since 1.0.0\n */\nexport class LoggerTimestamp {\n\t/**\n\t * The timestamp used to format the current date.\n\t * @since 1.0.0\n\t */\n\tpublic timestamp: Timestamp;\n\n\t/**\n\t * Whether or not the logger will show a timestamp in UTC.\n\t * @since 1.0.0\n\t */\n\tpublic utc: boolean;\n\n\t/**\n\t * The logger style to apply the color to the timestamp.\n\t * @since 1.0.0\n\t */\n\tpublic color: LoggerStyle | null;\n\n\t/**\n\t * The final formatter.\n\t * @since 1.0.0\n\t */\n\tpublic formatter: LoggerTimestampFormatter;\n\n\tpublic constructor(options: LoggerTimestampOptions = {}) {\n\t\tthis.timestamp = new Timestamp(options.pattern ?? 'YYYY-MM-DD HH:mm:ss');\n\t\tthis.utc = options.utc ?? false;\n\t\tthis.color = options.color === null ? null : new LoggerStyle(options.color);\n\t\tthis.formatter = options.formatter ?? ((timestamp) => `${timestamp} - `);\n\t}\n\n\t/**\n\t * Formats the current time.\n\t * @since 1.0.0\n\t */\n\tpublic run() {\n\t\tconst date = new Date();\n\t\tconst result = this.utc ? this.timestamp.displayUTC(date) : this.timestamp.display(date);\n\t\treturn this.formatter(this.color ? this.color.run(result) : result);\n\t}\n}\n\n/**\n * The options for {@link LoggerTimestamp}.\n * @since 1.0.0\n */\nexport interface LoggerTimestampOptions {\n\t/**\n\t * The {@link Timestamp} pattern.\n\t * @since 1.0.0\n\t * @default 'YYYY-MM-DD HH:mm:ss'\n\t * @example\n\t * ```typescript\n\t * 'YYYY-MM-DD HH:mm:ss'\n\t * // 2020-12-23 22:01:10\n\t * ```\n\t */\n\tpattern?: string;\n\n\t/**\n\t * Whether or not the date should be UTC.\n\t * @since 1.0.0\n\t * @default false\n\t */\n\tutc?: boolean;\n\n\t/**\n\t * The color to use.\n\t * @since 1.0.0\n\t * @default colorette.reset\n\t */\n\tcolor?: LoggerStyleResolvable | null;\n\n\t/**\n\t * The formatter. See {@link LoggerTimestampFormatter} for more information.\n\t * @since 1.0.0\n\t * @default (value) => `${value} - `\n\t */\n\tformatter?: LoggerTimestampFormatter;\n}\n\n/**\n * The formatter used for {@link LoggerTimestampOptions}. This will be run **after** applying the color to the formatter.\n * @since 1.0.0\n */\nexport interface LoggerTimestampFormatter {\n\t/**\n\t * @param timestamp The output of {@link LoggerStyle.run} on {@link Timestamp.display}/{@link Timestamp.displayUTC}.\n\t * @since 1.0.0\n\t */\n\t(timestamp: string): string;\n}\n"]}