UNPKG

@bracketed/logger

Version:

An alternative to your run-of-the-mill node console logging functions!

1 lines 2.38 kB
{"version":3,"sources":["../../../src/Logger/Level.ts"],"names":["LoggerLevel","timestamp","message","options","infix","run","prefix","line","split","map","formatter","join","content"],"mappings":"gKAQO,IAAA,CAAA,CAAA,KARP,CAAA,OAQaA,mBAAAA,CAAAA,IAAAA,CAAAA,aAKLC,EAAAA,CAAAA,eAYAC,CAAAA,OAEP,CAAA,WAAiD,CAAC,EAAG,EACpD,CAAA,CAAA,cAAyBD,CAAAA,CAAAA,CAAAA,SAAc,OAAO,CAAA,IAAO,CAAA,IAAoBE,6BAAQF,YACjF,CAAA,CAAA,UAAqBG,CAAAA,CAAAA,CAAAA,OACrB,EAAA,CAAA,IAAKF,CAAAA,OAAkBA,CAAAA,CAAAA,CAAAA,OAAY,OAAO,CAAA,IAAO,CAAA,IAAgBC,qBAAQD,CAAAA,CAAAA,CAAAA,OAGnEG,EAAAA,CAAAA,GAAqB,CAC3B,OAAgB,CAAA,CAAA,CAAA,cAAgBA,EAAAA,GAAAA,MAAe,EAAA,IAAKD,CAAAA,KAEpD,CAAIE,WACH,CAAA,CAAA,IAAkB,CAAA,CAAA,IAAKJ,CAAAA,QACFI,CAAAA,EAAS,CAAA,CAAA,IAAKJ,CAAAA,OAASG,CAAAA,GAAIE,CAC5CA,CAAAA,CAAAA,CAAiBD,GAASC,CAC9B,CAAA,CAAA,CAAA,OAAeC,CAAAA,CAAAA,KAAM,CAAA;CAAA,CAAA,CAAMC,GAAAA,CAAIC,CAAAA,CAAAA,CAAWC,IAAAA,CAAK;CAAA,CAChD,CAEA,OAAO,IAAA,CAAKT,OAAAA,CAAU,IAAA,CAAKA,QAAQG,GAAAA,CAAIO,CAAAA,CAAAA,CAAWA,CACnD,CACD","file":"Level.cjs","sourcesContent":["import { LoggerStyle } from '../Style/Style';\nimport { LoggerTimestamp } from '../Utilities/Timestamp';\nimport type { LoggerLevelOptions } from './LevelOptions';\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"]}