Compare commits

..

No commits in common. "3f8bf9793195abb877ae2a48db7098734fc541f7" and "04aa4fc98ad09ba48fbec085008339b503ef6696" have entirely different histories.

5 changed files with 32 additions and 39 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@navy.gif/logger",
"version": "2.2.2",
"version": "2.2.1",
"description": "Logging thing",
"author": "Navy.gif",
"license": "MIT",
@ -35,7 +35,6 @@
},
"scripts": {
"test": "node test/test.js",
"build": "tsc && tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js",
"release": "tsc && yarn publish"
"build": "tsc && tsc -p tsconfig.cjs.json && node ./scripts/declareTypes.js"
}
}

View File

@ -80,8 +80,10 @@ 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)
throw new Error(`Missing connection to master proces`);
// eslint-disable-next-line no-console
console.log(`${header} ${message}`);
else
process.send({ [this.#_guard]: true, header, message, ...opts });
@ -89,23 +91,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.');
}

View File

@ -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
}

View File

@ -10,12 +10,18 @@ import { inspect } from 'node:util';
// Own
import DiscordWebhook from '@navy.gif/discord-webhook';
import Defaults, { LogLevel } from './Defaults.js';
import { IPCMessage, LogFunction, Shard, WriteOptions } from './Types.js';
import { 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,
@ -29,8 +35,6 @@ type WriteStreams = {
class MasterLogger implements Logger {
[key: string]: LogFunction | unknown;
#_guard: string;
#_logLevel: LogLevel;
#_logLevelMapping: {[key: string]: number};
@ -142,10 +146,9 @@ class MasterLogger implements Logger {
if (!msg[this.#_guard])
return;
const { message, type, header, broadcast } = msg;
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 });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
this[type](message, { subheader: header, shard, broadcast });
});
}
@ -225,23 +228,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.');
}

View File

@ -10,15 +10,4 @@ type WriteOptions = {
broadcast?: boolean
}
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 };
export { WriteOptions, Shard };