mirror of
https://github.com/tribufu/node-gamedig
synced 2026-06-01 09:42:41 +00:00
Add punycode support (2.0.6)
This commit is contained in:
parent
5aaff8e1e0
commit
05619469b7
6 changed files with 141 additions and 64 deletions
40
lib/Logger.js
Normal file
40
lib/Logger.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
const HexUtil = require('./HexUtil');
|
||||
|
||||
class Logger {
|
||||
constructor() {
|
||||
this.debugEnabled = false;
|
||||
}
|
||||
|
||||
debug(...args) {
|
||||
if (!this.debugEnabled) return;
|
||||
this._print(...args);
|
||||
}
|
||||
|
||||
_print(...args) {
|
||||
try {
|
||||
const strings = this._convertArgsToStrings(...args);
|
||||
console.log(...strings);
|
||||
} catch(e) {
|
||||
console.log("Error while logging: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
_convertArgsToStrings(...args) {
|
||||
const out = [];
|
||||
for (const arg of args) {
|
||||
if (arg instanceof Error) {
|
||||
out.push(arg.stack);
|
||||
} else if (arg instanceof Buffer) {
|
||||
out.push("\n" + HexUtil.debugDump(arg) + "\n");
|
||||
} else if (typeof arg == 'function') {
|
||||
const result = arg.call(undefined, (...args) => out.push(...this._convertArgsToStrings(...args)));
|
||||
if (result !== undefined) out.push(...this._convertArgsToStrings(result));
|
||||
} else {
|
||||
out.push(arg);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Logger;
|
||||
Loading…
Add table
Add a link
Reference in a new issue