Compare commits
6 Commits
eb136291c2
...
e9aa4ed2c0
Author | SHA1 | Date | |
---|---|---|---|
e9aa4ed2c0 | |||
aa1d257cd3 | |||
786f7db564 | |||
d68584572d | |||
3e55182657 | |||
22f5549bc7 |
8
index.ts
8
index.ts
@ -2,7 +2,8 @@ import MasterLogger from './src/MasterLogger.js';
|
|||||||
import LoggerClient from './src/LoggerClient.js';
|
import LoggerClient from './src/LoggerClient.js';
|
||||||
import Defaults, { LogLevel } from './src/Defaults.js';
|
import Defaults, { LogLevel } from './src/Defaults.js';
|
||||||
|
|
||||||
export { WriteOptions, LogFunction } from './src/Types.js';
|
export { WebhookClientOptions } from '@navy.gif/discord-webhook';
|
||||||
|
export { WriteOptions, LogFunction, Loggable } from './src/Types.js';
|
||||||
export { LoggerClientOptions, LoggerMasterOptions } from './src/Defaults.js';
|
export { LoggerClientOptions, LoggerMasterOptions } from './src/Defaults.js';
|
||||||
|
|
||||||
const addLogLevel = (name: string, level: number) =>
|
const addLogLevel = (name: string, level: number) =>
|
||||||
@ -16,9 +17,10 @@ const addLogLevel = (name: string, level: number) =>
|
|||||||
LogLevel[LogLevel[name] = level] = name;
|
LogLevel[LogLevel[name] = level] = name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export {
|
export {
|
||||||
MasterLogger,
|
MasterLogger,
|
||||||
LoggerClient,
|
LoggerClient,
|
||||||
Defaults, LogLevel, addLogLevel,
|
Defaults,
|
||||||
|
LogLevel,
|
||||||
|
addLogLevel,
|
||||||
};
|
};
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@navy.gif/logger",
|
"name": "@navy.gif/logger",
|
||||||
"version": "2.5.0",
|
"version": "2.5.3",
|
||||||
"description": "Logging thing",
|
"description": "Logging thing",
|
||||||
"author": "Navy.gif",
|
"author": "Navy.gif",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@ -29,7 +29,7 @@
|
|||||||
"typescript": "^5.0.4"
|
"typescript": "^5.0.4"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@navy.gif/discord-webhook": "^1.0.0",
|
"@navy.gif/discord-webhook": "^1.2.2",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"moment": "^2.29.4"
|
"moment": "^2.29.4"
|
||||||
},
|
},
|
||||||
|
@ -9,18 +9,18 @@ type TransportOptions = {
|
|||||||
} & WriteOptions
|
} & WriteOptions
|
||||||
|
|
||||||
const validKeys = [ 'labels' ];
|
const validKeys = [ 'labels' ];
|
||||||
const isTransportOpts = (obj: object): obj is TransportOptions =>
|
const isTransportOpts = (obj: unknown): obj is TransportOptions =>
|
||||||
{
|
{
|
||||||
|
if (!obj || typeof obj !== 'object')
|
||||||
|
return false;
|
||||||
const isWriteOption = isWriteOptions(obj);
|
const isWriteOption = isWriteOptions(obj);
|
||||||
const keys = Object.keys(obj);
|
const keys = Object.keys(obj);
|
||||||
return isWriteOption || keys.some(key => validKeys.includes(key));
|
return isWriteOption || keys.some(key => validKeys.includes(key));
|
||||||
};
|
};
|
||||||
|
|
||||||
class LoggerClient implements Logger
|
class LoggerClient implements Logger
|
||||||
{
|
{
|
||||||
|
|
||||||
static MaxChars = 0;
|
static MaxChars = 0;
|
||||||
|
|
||||||
[key: string]: LogFunction | unknown;
|
[key: string]: LogFunction | unknown;
|
||||||
|
|
||||||
#_guard: string;
|
#_guard: string;
|
||||||
|
@ -136,7 +136,7 @@ class MasterLogger implements Logger
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
close ()
|
close ()
|
||||||
{
|
{
|
||||||
clearInterval(this.#pruneInterval);
|
clearInterval(this.#pruneInterval);
|
||||||
|
|
||||||
@ -208,7 +208,7 @@ class MasterLogger implements Logger
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
write (type = 'info', ...args: [...entries: Loggable[], options: WriteOptions])
|
write (type = 'info', ...args: [...entries: Loggable[], options: WriteOptions | Loggable])
|
||||||
{
|
{
|
||||||
const last = args[args.length - 1];
|
const last = args[args.length - 1];
|
||||||
let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {};
|
let { subheader = '', shard, broadcast = false, labels = [] }: WriteOptions = {};
|
||||||
|
@ -10,8 +10,10 @@ export const makePlainError = (err: Error) =>
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validKeys = [ 'subheader', 'shard', 'broadcast', 'labels' ];
|
const validKeys = [ 'subheader', 'shard', 'broadcast', 'labels' ];
|
||||||
export const isWriteOptions = (obj: object, extended = false): obj is WriteOptions =>
|
export const isWriteOptions = (obj: unknown, extended = false): obj is WriteOptions =>
|
||||||
{
|
{
|
||||||
|
if (!obj || typeof obj !== 'object')
|
||||||
|
return false;
|
||||||
const keys = Object.keys(obj);
|
const keys = Object.keys(obj);
|
||||||
// Check for invalid keys, in some cases an arbitrary object might share keys
|
// Check for invalid keys, in some cases an arbitrary object might share keys
|
||||||
// while still allowing for an option to be extended
|
// while still allowing for an option to be extended
|
||||||
|
Loading…
Reference in New Issue
Block a user