UNPKG

@sapphire/plugin-logger

Version:

Plugin for @sapphire/framework to have pretty console output

52 lines (49 loc) 1.9 kB
'use strict'; var timestamp = require('@sapphire/timestamp'); var LoggerStyle_cjs = require('./LoggerStyle.cjs'); var __defProp = Object.defineProperty; var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value; var __name = (target, value) => __defProp(target, "name", { value, configurable: true }); var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value); var _LoggerTimestamp = class _LoggerTimestamp { constructor(options = {}) { /** * The timestamp used to format the current date. * @since 1.0.0 */ __publicField(this, "timestamp"); /** * Whether or not the logger will show a timestamp in UTC. * @since 1.0.0 */ __publicField(this, "utc"); /** * The logger style to apply the color to the timestamp. * @since 1.0.0 */ __publicField(this, "color"); /** * The final formatter. * @since 1.0.0 */ __publicField(this, "formatter"); this.timestamp = new timestamp.Timestamp(options.pattern ?? "YYYY-MM-DD HH:mm:ss"); this.utc = options.utc ?? false; this.color = options.color === null ? null : new LoggerStyle_cjs.LoggerStyle(options.color); this.formatter = options.formatter ?? ((timestamp) => `${timestamp} - `); } /** * Formats the current time. * @since 1.0.0 */ run() { const date = /* @__PURE__ */ new Date(); const result = this.utc ? this.timestamp.displayUTC(date) : this.timestamp.display(date); return this.formatter(this.color ? this.color.run(result) : result); } }; __name(_LoggerTimestamp, "LoggerTimestamp"); var LoggerTimestamp = _LoggerTimestamp; exports.LoggerTimestamp = LoggerTimestamp; //# sourceMappingURL=LoggerTimestamp.cjs.map //# sourceMappingURL=LoggerTimestamp.cjs.map