{"version":3,"file":"log-channel.mjs","names":[],"sources":["../../../../../../@warlock.js/logger/src/log-channel.ts"],"sourcesContent":["import type {\r\n  BasicLogConfigurations,\r\n  LogContract,\r\n  LoggingData,\r\n  RedactConfig,\r\n} from \"./types\";\r\n\r\nexport abstract class LogChannel<\r\n  Options extends BasicLogConfigurations = BasicLogConfigurations,\r\n> implements LogContract {\r\n  /**\r\n   * Channel name\r\n   */\r\n  public name!: string;\r\n\r\n  /**\r\n   * Channel description\r\n   */\r\n  public description?: string;\r\n\r\n  /**\r\n   * Determine if channel is logging in terminal\r\n   */\r\n  public terminal = false;\r\n\r\n  /**\r\n   * Default Configurations\r\n   */\r\n  protected defaultConfigurations: Options = {} as Options;\r\n\r\n  /**\r\n   * Channel configurations\r\n   */\r\n  protected channelConfigurations: Options = {} as Options; //\r\n\r\n  /**\r\n   * Determine whether the channel is fully initialized\r\n   */\r\n  protected isInitialized = false;\r\n\r\n  /**\r\n   * Constructor\r\n   */\r\n  public constructor(configurations?: Options) {\r\n    if (configurations) {\r\n      this.setConfigurations(configurations);\r\n    }\r\n\r\n    setTimeout(async () => {\r\n      if (this.init) {\r\n        await this.init();\r\n      }\r\n\r\n      this.isInitialized = true;\r\n    }, 0);\r\n  }\r\n\r\n  /**\r\n   * Initialize the channel\r\n   */\r\n  protected init?(): void | Promise<void>;\r\n\r\n  /**\r\n   * Get config value\r\n   */\r\n  protected config<K extends keyof Options>(key: K): Options[K] {\r\n    return (\r\n      this.channelConfigurations[key] ?? (this.defaultConfigurations ?? {})[key]\r\n    );\r\n  }\r\n\r\n  /**\r\n   * Set configurations\r\n   */\r\n  protected setConfigurations(configurations: Options) {\r\n    this.channelConfigurations = {\r\n      ...this.channelConfigurations,\r\n      ...configurations,\r\n    };\r\n\r\n    return this;\r\n  }\r\n\r\n  /**\r\n   * Determine if the message should be logged\r\n   */\r\n  protected shouldBeLogged(data: LoggingData): boolean {\r\n    // check for debug mode\r\n    const allowedLevels = this.config(\"levels\");\r\n\r\n    if (allowedLevels?.length && !allowedLevels.includes(data.type))\r\n      return false;\r\n\r\n    const filter = this.config(\"filter\");\r\n\r\n    if (filter) {\r\n      return filter(data);\r\n    }\r\n\r\n    return true;\r\n  }\r\n\r\n  /**\r\n   * Log the given message\r\n   */\r\n  public abstract log(data: LoggingData): void | Promise<void>;\r\n\r\n  /**\r\n   * Synchronously flush messages\r\n   */\r\n  public flushSync?(): void;\r\n\r\n  /**\r\n   * Asynchronously flush buffered messages.\r\n   *\r\n   * Optional — channels that write synchronously per entry (e.g. `ConsoleLog`)\r\n   * don't implement it. Buffering channels override this to drain their buffer\r\n   * over async I/O so callers can `await log.flush()` on graceful shutdown.\r\n   */\r\n  public flush?(): void | Promise<void>;\r\n\r\n  /**\r\n   * Read the channel's redact config (if any). Used by `Logger` to apply\r\n   * per-channel additive redaction on top of the logger-wide floor.\r\n   * Subclasses normally don't override this — set `redact` in your channel\r\n   * configuration instead.\r\n   */\r\n  public getRedactConfig(): RedactConfig | undefined {\r\n    return this.config(\"redact\" as keyof Options) as RedactConfig | undefined;\r\n  }\r\n\r\n  /**\r\n   * Get date and time formats\r\n   */\r\n  protected getDateAndTimeFormat() {\r\n    const dateFormat = this.config(\"dateFormat\");\r\n    const date = dateFormat?.date ?? \"DD-MM-YYYY\";\r\n    const time = dateFormat?.time ?? \"HH:mm:ss\";\r\n\r\n    return { date, time };\r\n  }\r\n\r\n  /**\r\n   * get basic configurations with the given ones\r\n   */\r\n  protected withBasicConfigurations(configurations: Partial<Options>): Options {\r\n    return {\r\n      filter: () => true,\r\n      ...configurations,\r\n    } as any as Options;\r\n  }\r\n}\r\n"],"mappings":";AAOA,IAAsB,aAAtB,MAEyB;;;;CAkCvB,AAAO,YAAY,gBAA0B;kBApB3B;+BAKyB,CAAC;+BAKD,CAAC;uBAKlB;EAMxB,IAAI,gBACF,KAAK,kBAAkB,cAAc;EAGvC,WAAW,YAAY;GACrB,IAAI,KAAK,MACP,MAAM,KAAK,KAAK;GAGlB,KAAK,gBAAgB;EACvB,GAAG,CAAC;CACN;;;;CAUA,AAAU,OAAgC,KAAoB;EAC5D,OACE,KAAK,sBAAsB,SAAS,KAAK,yBAAyB,CAAC,EAAC,CAAE;CAE1E;;;;CAKA,AAAU,kBAAkB,gBAAyB;EACnD,KAAK,wBAAwB;GAC3B,GAAG,KAAK;GACR,GAAG;EACL;EAEA,OAAO;CACT;;;;CAKA,AAAU,eAAe,MAA4B;EAEnD,MAAM,gBAAgB,KAAK,OAAO,QAAQ;EAE1C,IAAI,eAAe,UAAU,CAAC,cAAc,SAAS,KAAK,IAAI,GAC5D,OAAO;EAET,MAAM,SAAS,KAAK,OAAO,QAAQ;EAEnC,IAAI,QACF,OAAO,OAAO,IAAI;EAGpB,OAAO;CACT;;;;;;;CA2BA,AAAO,kBAA4C;EACjD,OAAO,KAAK,OAAO,QAAyB;CAC9C;;;;CAKA,AAAU,uBAAuB;EAC/B,MAAM,aAAa,KAAK,OAAO,YAAY;EAI3C,OAAO;GAAE,MAHI,YAAY,QAAQ;GAGlB,MAFF,YAAY,QAAQ;EAEb;CACtB;;;;CAKA,AAAU,wBAAwB,gBAA2C;EAC3E,OAAO;GACL,cAAc;GACd,GAAG;EACL;CACF;AACF"}