Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package maintenance #227

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
package-lock.json
16 changes: 16 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Timur Shemsedinov <timur.shemsedinov@gmail.com>
Mykola Bilochub <nbelochub@gmail.com>
Julia Gerasymenko <gerasymenko.j.ke@gmail.com>
Dmytro Nechai <nechaido@gmail.com>
Denys Otrishko <shishugi@gmail.com>
Timur Sevimli <svmlitimur+github@gmail.com>
Dmitry Semigradsky <semigradskyd@gmail.com>
Eugene Lepeico <jnlepico@gmail.com>
Serhii Moskovko <cakedispensers@gmail.com>
Georg Oldenburger <georgoldenb@gmail.com>
Bob_chemist <bob_chemist@mail.ru>
Aleksandr Kukharenko <Sandrk27@gmail.com>
Ivan Tymoshenko <ivan@tymoshenko.me>
Oleksandr Khodos <ax.khodos@gmail.com>
Nikita Machehin <nicitamac@gmail.com>
Roman Popov <1@rom4.ru>
2 changes: 1 addition & 1 deletion metalog.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EventEmitter = require('node:events');
import { EventEmitter } from 'node:events';

interface LoggerOptions {
path: string;
Expand Down
59 changes: 31 additions & 28 deletions metalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,105 +78,108 @@ const getNextReopen = () => {
};

class Console {
#write;
#groupIndent = 0;
#counts = new Map();
#times = new Map();
#readline = readline;

constructor(write) {
this._write = write;
this._groupIndent = 0;
this._counts = new Map();
this._times = new Map();
this.#write = write;
}

assert(assertion, ...args) {
try {
console.assert(assertion, ...args);
} catch (err) {
this._write('error', this._groupIndent, err.stack);
this.#write('error', this.#groupIndent, err.stack);
}
}

clear() {
readline.cursorTo(process.stdout, 0, 0);
readline.clearScreenDown(process.stdout);
this.#readline.cursorTo(process.stdout, 0, 0);
this.#readline.clearScreenDown(process.stdout);
}

count(label = 'default') {
let cnt = this._counts.get(label) || 0;
let cnt = this.#counts.get(label) || 0;
cnt++;
this._counts.set(label, cnt);
this._write('debug', this._groupIndent, `${label}: ${cnt}`);
this.#counts.set(label, cnt);
this.#write('debug', this.#groupIndent, `${label}: ${cnt}`);
}

countReset(label = 'default') {
this._counts.delete(label);
this.#counts.delete(label);
}

debug(...args) {
this._write('debug', this._groupIndent, ...args);
this.#write('debug', this.#groupIndent, ...args);
}

dir(...args) {
this._write('debug', this._groupIndent, ...args);
this.#write('debug', this.#groupIndent, ...args);
}

trace(...args) {
const msg = util.format(...args);
const err = new Error(msg);
this._write('debug', this._groupIndent, `Trace${err.stack}`);
this.#write('debug', this.#groupIndent, `Trace${err.stack}`);
}

info(...args) {
this._write('info', this._groupIndent, ...args);
this.#write('info', this.#groupIndent, ...args);
}

log(...args) {
this._write('log', this._groupIndent, ...args);
this.#write('log', this.#groupIndent, ...args);
}

warn(...args) {
this._write('warn', this._groupIndent, ...args);
this.#write('warn', this.#groupIndent, ...args);
}

error(...args) {
this._write('error', this._groupIndent, ...args);
this.#write('error', this.#groupIndent, ...args);
}

group(...args) {
if (args.length !== 0) this.log(...args);
this._groupIndent += INDENT;
this.#groupIndent += INDENT;
}

groupCollapsed(...args) {
this.group(...args);
}

groupEnd() {
if (this._groupIndent.length === 0) return;
this._groupIndent -= INDENT;
if (this.#groupIndent.length === 0) return;
this.#groupIndent -= INDENT;
}

table(tabularData) {
this._write('log', 0, JSON.stringify(tabularData));
this.#write('log', 0, JSON.stringify(tabularData));
}

time(label = 'default') {
this._times.set(label, process.hrtime());
this.#times.set(label, process.hrtime());
}

timeEnd(label = 'default') {
const startTime = this._times.get(label);
const startTime = this.#times.get(label);
const totalTime = process.hrtime(startTime);
const totalTimeMs = totalTime[0] * 1e3 + totalTime[1] / 1e6;
this.timeLog(label, `${label}: ${totalTimeMs}ms`);
this._times.delete(label);
this.#times.delete(label);
}

timeLog(label, ...args) {
const startTime = this._times.get(label);
const startTime = this.#times.get(label);
if (startTime === undefined) {
const msg = `Warning: No such label '${label}'`;
this._write('warn', this._groupIndent, msg);
this.#write('warn', this.#groupIndent, msg);
return;
}
this._write('debug', this._groupIndent, ...args);
this.#write('debug', this.#groupIndent, ...args);
}
}

Expand Down
Loading