Linter pass + fix logger sometimes not pruning old files

This commit is contained in:
Erik 2024-10-08 22:32:09 +03:00
parent 8c0ae9170f
commit 9e6188d7c5
5 changed files with 102 additions and 101 deletions

View File

@ -117,27 +117,27 @@ class LoggerClient implements Logger
}
// These methods are dynamically implemented by the constructor, simply here to provide IDE hints
// eslint-disable-next-line @typescript-eslint/no-unused-vars
error (..._args: [...entries: Loggable[], options: WriteOptions|Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
warn (..._args: [...entries: Loggable[], options: WriteOptions|Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
status (..._args: [...entries: Loggable[], options: WriteOptions|Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
info (..._args: [...entries: Loggable[], options: WriteOptions|Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
debug (..._args: [...entries: Loggable[], options: WriteOptions|Loggable]): void
{
throw new Error('Method not implemented.');

View File

@ -168,7 +168,7 @@ class MasterLogger implements Logger
const limit = this.#pruneDays * 24 * 60 * 60 * 1000;
for (const entry of directory)
{
if (!entry.isFile() || !(/\d{4}-\d{2}-\d{2}-[a-z]+\.log/u).test(entry.name))
if (!entry.isFile() || !(/\d{4}-\d{2}-\d{2}-[a-z]+\.log/iu).test(entry.name))
continue;
const [ year, month, day ] = entry.name.split('-');
const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day)).getTime();
@ -238,7 +238,7 @@ class MasterLogger implements Logger
const maxChars = Math.max(...this.#types.map(t => t.length));
const spacer = ' '.repeat(maxChars - type.length);
if (this.#_logLevelMapping[type] >= this.#_logLevel)
if (this.#_logLevelMapping[type] >= this.#_logLevel || process.env.NODE_ENV === 'development')
{
const out = `${colour.func(type)}${spacer} ${colour.func(header)}: ${chalk.bold(subheader)}${text}`;
if (type === 'error')
@ -248,11 +248,12 @@ class MasterLogger implements Logger
}
if ((broadcast || (this.#_broadcastLevel <= this.#_logLevelMapping[type])) && this.#webhook)
{
const description = (subheader.length ? `**${subheader.trim()}**: ${process.env.NODE_ENV ?? 'production'}\n` : '') + `\`\`\`${text}\`\`\``;
const description = (subheader.length ? `**${subheader.trim()}**` : '**ENV**') + `: ${process.env.NODE_ENV ?? 'production'}`;
const content = `\`\`\`${text}\`\`\``;
this.#webhook.send({
embeds: [{
title: `[__${type.toUpperCase()}__] ${this._shard(shard)}`,
description,
description: `${description}\n${content}`,
color: colour.int,
footer: {
text: [ ...labels, ...this.#labels ].join(', ') ?? ''
@ -317,27 +318,27 @@ class MasterLogger implements Logger
}
// These methods are dynamically implemented by the constructor
// eslint-disable-next-line @typescript-eslint/no-unused-vars
error (..._args: [...entries: Loggable[], options: WriteOptions | Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
warn (..._args: [...entries: Loggable[], options: WriteOptions | Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
status (..._args: [...entries: Loggable[], options: WriteOptions | Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
info (..._args: [...entries: Loggable[], options: WriteOptions | Loggable]): void
{
throw new Error('Method not implemented.');
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
debug (..._args: [...entries: Loggable[], options: WriteOptions | Loggable]): void
{
throw new Error('Method not implemented.');