Compare commits

..

No commits in common. "7f2d9a9b0f2326bd4d3b6ee050bddee54200e8ea" and "22d7d982aca19fb692c0e004f0083a570b88609c" have entirely different histories.

3 changed files with 4 additions and 40 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@navy.gif/logger",
"version": "2.4.0",
"version": "2.3.4",
"description": "Logging thing",
"author": "Navy.gif",
"license": "MIT",

View File

@ -43,7 +43,6 @@ const customStreams: string[] = [];
const customTypes: string[] = [];
const guard = '_logger';
const webhook: { url?: string, id?: string, token?: string } = {};
const pruneDays = 3;
type LogLevelType = {
debug: LogLevel,
@ -83,7 +82,6 @@ export type LoggerMasterOptions = SharedOptionsType & {
customColours?: { [key: string]: number | string },
broadcastLevel?: number,
webhook?: WebhookClientOptions,
pruneDays?: number
}
const MasterOptions: LoggerMasterOptions = {
@ -95,7 +93,6 @@ const MasterOptions: LoggerMasterOptions = {
customColours,
broadcastLevel: 4,
webhook,
pruneDays
};
export type LoggerClientOptions = SharedOptionsType;

View File

@ -49,8 +49,6 @@ class MasterLogger implements Logger
#rotationFreq: number;
#startDay: number;
#rotateTO: NodeJS.Timeout;
#pruneInterval: NodeJS.Timer;
#pruneDays: number;
constructor (config = Defaults.MasterOptions)
{
@ -58,7 +56,7 @@ class MasterLogger implements Logger
const {
directory, customTypes = [], customStreams = [], customTypeMapping,
customColours, guard, fileRotationFreq, logLevel, logLevelMapping,
webhook, broadcastLevel, pruneDays
webhook, broadcastLevel
} = { ...Defaults.MasterOptions, ...config };
if (!directory)
@ -66,7 +64,6 @@ class MasterLogger implements Logger
this.#directory = path.resolve(directory);
if (!fs.existsSync(this.#directory))
fs.mkdirSync(this.#directory, { recursive: true });
this.#_broadcastLevel = broadcastLevel as number;
this.#_logLevel = logLevel as number;
this.#_logLevelMapping = { ...Defaults.MasterOptions.logLevelMapping, ...logLevelMapping };
@ -115,9 +112,6 @@ class MasterLogger implements Logger
this.#rotationFreq = fileRotationFreq as number * DAY;
this.#startDay = Math.floor(Date.now() / this.#rotationFreq) * this.#rotationFreq;
this.#rotateTO = setTimeout(this.rotateLogFiles.bind(this), this.#startDay + this.#rotationFreq - Date.now());
this.#pruneDays = pruneDays as number;
this.#pruneInterval = setInterval(this.pruneLogFiles.bind(this), 60 * 60 * 1000);
this.pruneLogFiles();
if (webhook && webhook.url)
{
@ -127,16 +121,6 @@ class MasterLogger implements Logger
}
close ()
{
clearInterval(this.#pruneInterval);
const streams = Object.keys(this.#writeStreams);
for (const type of streams)
this.#writeStreams[type].end();
clearTimeout(this.#rotateTO);
}
get guard ()
{
return this.#_guard;
@ -152,23 +136,6 @@ class MasterLogger implements Logger
return Object.keys(this.#_logLevelMapping);
}
pruneLogFiles ()
{
const directory = fs.readdirSync(this.#directory, { withFileTypes: true });
const now = Date.now();
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))
continue;
const [ year, month, day ] = entry.name.split('-');
const date = new Date(parseInt(year), parseInt(month) - 1, parseInt(day)).getTime();
if ((now - date) < limit)
continue;
fs.unlinkSync(path.join(this.#directory, entry.name));
}
}
setLogLevel (level: number)
{
if (LogLevel[level] in this.#_logLevelMapping)