use stderr for logging

This commit is contained in:
Nicolas Dextraze 2024-02-19 13:37:12 -05:00
parent b048b03cb9
commit 19ad44b066

View File

@ -17,29 +17,29 @@ const LogLevels = {
let logLevel = LogLevels.error; let logLevel = LogLevels.error;
function timestamp() { function timestamp() {
const d = new Date().toISOString(); const d = new Date().toISOString();
return [d.substr(5, 5), d.substr(11, 8)].join(' ') return [d.slice(5, 5), d.slice(11, 8)].join(' ')
} }
class Logger { class Logger {
debug(...args) { debug(...args) {
if (LogLevels.debug > logLevel) return; if (LogLevels.debug > logLevel) return;
const [format, ...rest] = args; const [format, ...rest] = args;
console.debug(timestamp(), "D", util.format(format, ...rest)); console.error(timestamp(), "D", util.format(format, ...rest));
} }
info(...args) { info(...args) {
if (LogLevels.info > logLevel) return; if (LogLevels.info > logLevel) return;
const [format, ...rest] = args; const [format, ...rest] = args;
console.debug(timestamp(), "I", util.format(format, ...rest)); console.error(timestamp(), "I", util.format(format, ...rest));
} }
warn(...args) { warn(...args) {
if (LogLevels.warn > logLevel) return; if (LogLevels.warn > logLevel) return;
const [format, ...rest] = args; const [format, ...rest] = args;
console.debug(timestamp(), "W", util.format(format, ...rest)); console.error(timestamp(), "W", util.format(format, ...rest));
} }
error(...args) { error(...args) {
if (LogLevels.error > logLevel) return; if (LogLevels.error > logLevel) return;
const [format, ...rest] = args; const [format, ...rest] = args;
console.debug(timestamp(), "E", util.format(format, ...rest)); console.error(timestamp(), "E", util.format(format, ...rest));
} }
} }
@ -139,7 +139,7 @@ class Logger {
/** @type TorStream */ /** @type TorStream */
let tor_stream; let tor_stream;
if (uri.hostname.endsWith('.onion')) { if (uri.hostname.endsWith('.onion')) {
const onion = uri.hostname.substr(0, uri.hostname.length - 6); const onion = uri.hostname.slice(0, uri.hostname.length - 6);
tor_stream = await circuit.create_onion_stream(onion, uri.port); tor_stream = await circuit.create_onion_stream(onion, uri.port);
} else { } else {
tor_stream = await circuit.create_stream(uri.hostname, uri.port); tor_stream = await circuit.create_stream(uri.hostname, uri.port);