Compare commits

...

2 Commits

Author SHA1 Message Date
40f6bc572e
v2.4.3 2023-08-10 11:23:37 +03:00
115e832109
option to not write to file at all 2023-08-10 11:23:19 +03:00
3 changed files with 19 additions and 9 deletions

View File

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

View File

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

View File

@ -51,6 +51,7 @@ class MasterLogger implements Logger
#rotateTO: NodeJS.Timeout; #rotateTO: NodeJS.Timeout;
#pruneInterval: NodeJS.Timer; #pruneInterval: NodeJS.Timer;
#pruneDays: number; #pruneDays: number;
#skipFileWrite: boolean;
constructor (config = Defaults.MasterOptions) constructor (config = Defaults.MasterOptions)
{ {
@ -58,7 +59,7 @@ class MasterLogger implements Logger
const { const {
directory, customTypes = [], customStreams = [], customTypeMapping, directory, customTypes = [], customStreams = [], customTypeMapping,
customColours, guard, fileRotationFreq, logLevel, logLevelMapping, customColours, guard, fileRotationFreq, logLevel, logLevelMapping,
webhook, broadcastLevel, pruneDays webhook, broadcastLevel, pruneDays, skipFileWrite
} = { ...Defaults.MasterOptions, ...config }; } = { ...Defaults.MasterOptions, ...config };
if (!directory) if (!directory)
@ -76,6 +77,7 @@ class MasterLogger implements Logger
addLogLevel(name, level); addLogLevel(name, level);
}); });
this.#_guard = guard as string; this.#_guard = guard as string;
this.#skipFileWrite = skipFileWrite as boolean;
this.#types = [ ...customTypes, ...Defaults.Types ]; this.#types = [ ...customTypes, ...Defaults.Types ];
for (const type of this.#types) for (const type of this.#types)
@ -105,6 +107,9 @@ class MasterLogger implements Logger
this.#streamTypes = [ ...customStreams, 'error', 'default' ]; this.#streamTypes = [ ...customStreams, 'error', 'default' ];
this.#streamTypeMapping = { ...Defaults.TypeStream, ...customTypeMapping }; this.#streamTypeMapping = { ...Defaults.TypeStream, ...customTypeMapping };
if (this.#skipFileWrite)
this.#writeStreams = {};
else
this.#writeStreams = this.#streamTypes.reduce((acc, type) => this.#writeStreams = this.#streamTypes.reduce((acc, type) =>
{ {
acc[type] = this.loadFile(type); acc[type] = this.loadFile(type);
@ -232,6 +237,8 @@ class MasterLogger implements Logger
}); });
} }
if (this.#skipFileWrite)
return;
const streamType = this.#streamTypeMapping[type] || 'default'; const streamType = this.#streamTypeMapping[type] || 'default';
if (this.#writeStreams[streamType]) if (this.#writeStreams[streamType])
this.#writeStreams[streamType].write(`\n${type}${spacer} ${header}: ${subheader}${text}`); this.#writeStreams[streamType].write(`\n${type}${spacer} ${header}: ${subheader}${text}`);