Compare commits
2 Commits
04aa4fc98a
...
3f8bf97931
Author | SHA1 | Date | |
---|---|---|---|
3f8bf97931 | |||
cfdd4cda44 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@navy.gif/logger",
|
||||
"version": "2.2.1",
|
||||
"version": "2.2.2",
|
||||
"description": "Logging thing",
|
||||
"author": "Navy.gif",
|
||||
"license": "MIT",
|
||||
@ -35,6 +35,7 @@
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node test/test.js",
|
||||
"build": "tsc && tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js"
|
||||
"build": "tsc && tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js",
|
||||
"release": "tsc && yarn publish"
|
||||
}
|
||||
}
|
||||
|
@ -80,10 +80,8 @@ class LoggerClient implements Logger {
|
||||
const spacer = ' '.repeat(LoggerClient.MaxChars - this.#_name.length);
|
||||
const header = `${`[${this.#_name.substring(0, LoggerClient.MaxChars)}]${spacer}`} `;
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
if (!process.send || !process.connected)
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`${header} ${message}`);
|
||||
throw new Error(`Missing connection to master proces`);
|
||||
else
|
||||
process.send({ [this.#_guard]: true, header, message, ...opts });
|
||||
|
||||
@ -91,23 +89,23 @@ class LoggerClient implements Logger {
|
||||
|
||||
// These methods are dynamically implemented by the constructor
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
error (_str: string, _opts: WriteOptions): void {
|
||||
error (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
warn (_str: string, _opts: WriteOptions): void {
|
||||
warn (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
status (_str: string, _opts: WriteOptions): void {
|
||||
status (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
info (_str: string, _opts: WriteOptions): void {
|
||||
info (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
debug (_str: string, _opts: WriteOptions): void {
|
||||
debug (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { WriteOptions } from "./Types";
|
||||
|
||||
export interface Logger {
|
||||
error(str: string, opts: WriteOptions): void
|
||||
warn(str: string, opts: WriteOptions): void
|
||||
status(str: string, opts: WriteOptions): void
|
||||
info(str: string, opts: WriteOptions): void
|
||||
debug(str: string, opts: WriteOptions): void
|
||||
error(str: string, opts?: WriteOptions): void
|
||||
warn(str: string, opts?: WriteOptions): void
|
||||
status(str: string, opts?: WriteOptions): void
|
||||
info(str: string, opts?: WriteOptions): void
|
||||
debug(str: string, opts?: WriteOptions): void
|
||||
}
|
@ -10,18 +10,12 @@ import { inspect } from 'node:util';
|
||||
// Own
|
||||
import DiscordWebhook from '@navy.gif/discord-webhook';
|
||||
import Defaults, { LogLevel } from './Defaults.js';
|
||||
import { Shard, WriteOptions } from './Types.js';
|
||||
import { IPCMessage, LogFunction, Shard, WriteOptions } from './Types.js';
|
||||
import { addLogLevel } from '../index.js';
|
||||
import { Logger } from './LoggerInterface.js';
|
||||
|
||||
const DAY = 1000 * 60 * 60 * 24;
|
||||
|
||||
type IPCMessage = {
|
||||
[key: string]: string | object
|
||||
_guard: string
|
||||
type: string
|
||||
}
|
||||
|
||||
type FuncsType = {
|
||||
[key: string]: {
|
||||
func: (...strings: string[]) => string,
|
||||
@ -35,6 +29,8 @@ type WriteStreams = {
|
||||
|
||||
class MasterLogger implements Logger {
|
||||
|
||||
[key: string]: LogFunction | unknown;
|
||||
|
||||
#_guard: string;
|
||||
#_logLevel: LogLevel;
|
||||
#_logLevelMapping: {[key: string]: number};
|
||||
@ -146,9 +142,10 @@ class MasterLogger implements Logger {
|
||||
if (!msg[this.#_guard])
|
||||
return;
|
||||
const { message, type, header, broadcast } = msg;
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
this[type](message, { subheader: header, shard, broadcast });
|
||||
const func = this[type] as LogFunction;
|
||||
if (!func)
|
||||
throw new Error(`Attempted use of invalid logging function of type: ${type}, ensure client and master have the same type definitions.`);
|
||||
func(message, { subheader: header, shard, broadcast });
|
||||
});
|
||||
}
|
||||
|
||||
@ -228,23 +225,23 @@ class MasterLogger implements Logger {
|
||||
|
||||
// These methods are dynamically implemented by the constructor
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
error (_str: string, _opts: WriteOptions): void {
|
||||
error (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
warn (_str: string, _opts: WriteOptions): void {
|
||||
warn (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
status (_str: string, _opts: WriteOptions): void {
|
||||
status (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
info (_str: string, _opts: WriteOptions): void {
|
||||
info (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
debug (_str: string, _opts: WriteOptions): void {
|
||||
debug (_str: string, _opts?: WriteOptions): void {
|
||||
throw new Error('Method not implemented.');
|
||||
}
|
||||
|
||||
|
13
src/Types.ts
13
src/Types.ts
@ -10,4 +10,15 @@ type WriteOptions = {
|
||||
broadcast?: boolean
|
||||
}
|
||||
|
||||
export { WriteOptions, Shard };
|
||||
type IPCMessage = {
|
||||
[key: string]: string | boolean
|
||||
_guard: string
|
||||
type: string,
|
||||
message: string,
|
||||
header: string,
|
||||
broadcast: boolean
|
||||
}
|
||||
|
||||
type LogFunction = (str: string, opts: WriteOptions) => void
|
||||
|
||||
export { WriteOptions, Shard, IPCMessage, LogFunction };
|
Loading…
Reference in New Issue
Block a user