Compare commits
No commits in common. "6b8692e63a8e8716d4e8985443828840de6a88bf" and "40f6bc572e06ecfafefd045a27fb4254f094aae1" have entirely different histories.
6b8692e63a
...
40f6bc572e
@ -46,19 +46,16 @@ class LoggerClient implements Logger
|
|||||||
|
|
||||||
const { customTypes = [] } = opts;
|
const { customTypes = [] } = opts;
|
||||||
this.#types = [ ...customTypes, ...Defaults.Types ];
|
this.#types = [ ...customTypes, ...Defaults.Types ];
|
||||||
this.#_logLevelMapping = { ...Defaults.ClientOptions.logLevelMapping, ...opts.logLevelMapping };
|
for (const type of this.#types)
|
||||||
this.#_guard = opts.guard || Defaults.ClientOptions.guard as string;
|
|
||||||
this.#_logLevel = opts.logLevel ?? Defaults.ClientOptions.logLevel as number;
|
|
||||||
|
|
||||||
for (const type of this.#types)
|
|
||||||
{
|
{
|
||||||
if (typeof this.#_logLevelMapping[type] === 'undefined')
|
|
||||||
throw new Error(`Missing logLevelMapping for type ${type}`);
|
|
||||||
Object.defineProperty(this, type, {
|
Object.defineProperty(this, type, {
|
||||||
value: (msg: string, o: WriteOptions) => this.#transport(msg, { ...o, type })
|
value: (msg: string, o: WriteOptions) => this.#transport(msg, { ...o, type })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.#_guard = opts.guard || Defaults.ClientOptions.guard as string;
|
||||||
|
this.#_logLevel = opts.logLevel ?? Defaults.ClientOptions.logLevel as number;
|
||||||
|
this.#_logLevelMapping = { ...Defaults.ClientOptions.logLevelMapping, ...opts.logLevelMapping };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,7 @@ class MasterLogger implements Logger
|
|||||||
|
|
||||||
constructor (config = Defaults.MasterOptions)
|
constructor (config = Defaults.MasterOptions)
|
||||||
{
|
{
|
||||||
|
|
||||||
const {
|
const {
|
||||||
directory, customTypes = [], customStreams = [], customTypeMapping,
|
directory, customTypes = [], customStreams = [], customTypeMapping,
|
||||||
customColours, guard, fileRotationFreq, logLevel, logLevelMapping,
|
customColours, guard, fileRotationFreq, logLevel, logLevelMapping,
|
||||||
@ -81,8 +82,6 @@ class MasterLogger implements Logger
|
|||||||
this.#types = [ ...customTypes, ...Defaults.Types ];
|
this.#types = [ ...customTypes, ...Defaults.Types ];
|
||||||
for (const type of this.#types)
|
for (const type of this.#types)
|
||||||
{
|
{
|
||||||
if (typeof this.#_logLevelMapping[type] === 'undefined')
|
|
||||||
throw new Error(`Missing logLevelMapping for type ${type}`);
|
|
||||||
Object.defineProperty(this, type, {
|
Object.defineProperty(this, type, {
|
||||||
value: (msg: string, opts: WriteOptions) => this.write(type, msg, opts)
|
value: (msg: string, opts: WriteOptions) => this.write(type, msg, opts)
|
||||||
});
|
});
|
||||||
@ -207,6 +206,8 @@ class MasterLogger implements Logger
|
|||||||
|
|
||||||
write (type = 'info', text: string | object | Error, { subheader = '', shard, broadcast = false }: WriteOptions = {})
|
write (type = 'info', text: string | object | Error, { subheader = '', shard, broadcast = false }: WriteOptions = {})
|
||||||
{
|
{
|
||||||
|
|
||||||
|
type = type.toLowerCase();
|
||||||
let colour = this.#colourFuncs[type];
|
let colour = this.#colourFuncs[type];
|
||||||
if (!colour)
|
if (!colour)
|
||||||
colour = this.#colourFuncs.info;
|
colour = this.#colourFuncs.info;
|
||||||
@ -221,14 +222,9 @@ class MasterLogger implements Logger
|
|||||||
const maxChars = Math.max(...this.#types.map(t => t.length));
|
const maxChars = Math.max(...this.#types.map(t => t.length));
|
||||||
const spacer = ' '.repeat(maxChars - type.length);
|
const spacer = ' '.repeat(maxChars - type.length);
|
||||||
|
|
||||||
if (this.#_logLevelMapping[type] >= this.#_logLevel)
|
if (this.#_logLevelMapping[type] >= this.#_logLevel)
|
||||||
{
|
console.log(`${colour.func(type)}${spacer} ${colour.func(header)}: ${chalk.bold(subheader)}${text}`); // eslint-disable-line no-console
|
||||||
const out = `${colour.func(type)}${spacer} ${colour.func(header)}: ${chalk.bold(subheader)}${text}`;
|
|
||||||
if (type === 'error')
|
|
||||||
console.error(out); // eslint-disable-line no-console
|
|
||||||
else
|
|
||||||
console.log(out); // eslint-disable-line no-console
|
|
||||||
}
|
|
||||||
if ((broadcast || this.#_broadcastLevel <= this.#_logLevelMapping[type]) && this.#webhook)
|
if ((broadcast || this.#_broadcastLevel <= this.#_logLevelMapping[type]) && this.#webhook)
|
||||||
{
|
{
|
||||||
const description = (subheader.length ? `**${subheader}**\n` : '') + `\`\`\`${text}\`\`\``;
|
const description = (subheader.length ? `**${subheader}**\n` : '') + `\`\`\`${text}\`\`\``;
|
||||||
|
Loading…
Reference in New Issue
Block a user