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