diff --git a/src/aimedb/decoder.ts b/src/aimedb/decoder.ts index fbe821d..16af3af 100644 --- a/src/aimedb/decoder.ts +++ b/src/aimedb/decoder.ts @@ -121,7 +121,7 @@ export class Decoder extends Transform { const obj = reader(msg); - debug(`Decode ${JSON.stringify(obj)}`); + debug("Decode %j", obj); return callback(null, obj); } diff --git a/src/aimedb/encoder.ts b/src/aimedb/encoder.ts index 4436a44..3c5929c 100644 --- a/src/aimedb/encoder.ts +++ b/src/aimedb/encoder.ts @@ -30,7 +30,7 @@ export class Encoder extends Transform { } _transform(msg: AimeResponse, encoding, callback) { - debug(`Encode ${JSON.stringify(msg)}`); + debug("Encode %j", msg); let buf: Buffer; @@ -108,7 +108,9 @@ export class Encoder extends Transform { return callback(new Error("Unimplemented response type")); } - debug(`Send ${buf.toString("hex")}`); + if (debug.enabled) { + debug("Send %s", buf.toString("hex")); + } return callback(null, buf); } diff --git a/src/aimedb/frame.ts b/src/aimedb/frame.ts index 1037248..139efe0 100644 --- a/src/aimedb/frame.ts +++ b/src/aimedb/frame.ts @@ -36,7 +36,9 @@ export class Deframer extends Transform { const frame = this.state.slice(0, len); - debug(`Recv ${frame.toString("hex")}`); + if (debug.enabled) { + debug("Recv %s", frame.toString("hex")); + } this.state = this.state.slice(len); diff --git a/src/aimedb/handler.ts b/src/aimedb/handler.ts index c93fbcc..ed3e24e 100644 --- a/src/aimedb/handler.ts +++ b/src/aimedb/handler.ts @@ -53,7 +53,7 @@ async function lookup( req: Req.LookupRequest, now: Date ): Promise { - debug(`Mifare lookup v1: luid=${req.luid}`); + debug("Mifare lookup: luid=%s", req.luid); return { type: req.type, @@ -68,7 +68,7 @@ async function lookup2( req: Req.LookupRequest2, now: Date ): Promise { - debug(`Mifare lookup v2: luid=${req.luid}`); + debug("FeliCa lookup: luid=%s", req.luid); return { type: req.type, @@ -83,7 +83,7 @@ async function register( req: Req.RegisterRequest, now: Date ): Promise { - debug(`User register: luid=${req.luid}`); + debug("User register: luid=%s", req.luid); return { type: req.type, diff --git a/src/aimedb/index.ts b/src/aimedb/index.ts index 5538854..c1f26e5 100644 --- a/src/aimedb/index.ts +++ b/src/aimedb/index.ts @@ -28,7 +28,9 @@ export default function aimedb(db: DataSource) { output.write(res); } catch (e) { - debug(`Connection error:\n${e.toString()}\n`); + if (debug.enabled) { + debug("Connection error: %s", e.stack); + } break; } diff --git a/src/allnet.ts b/src/allnet.ts index bce3255..79b5926 100644 --- a/src/allnet.ts +++ b/src/allnet.ts @@ -59,8 +59,8 @@ app.use("/sys/servlet/PowerOn", async function(req, res, next) { return next(); }); -app.post("/sys/servlet/PowerOn", function(req, resp) { - debug(`Startup Request: ${JSON.stringify(req.body)}`); +app.post("/sys/servlet/PowerOn", function(req, res) { + debug("Startup request: %j", req.body); // Cut milliseconds out of ISO timestamp @@ -91,9 +91,9 @@ app.post("/sys/servlet/PowerOn", function(req, resp) { token: req.body.token, }; - debug(`Startup response: ${JSON.stringify(resParams)}`); + debug("Startup response: %j", resParams); - resp.send(resParams); + res.send(resParams); }); export default app; diff --git a/src/billing.ts b/src/billing.ts index 57460a1..c9cae75 100644 --- a/src/billing.ts +++ b/src/billing.ts @@ -62,7 +62,7 @@ app.use(async function(req, res, next) { }); app.post("/request/", function(req, res) { - debug(`Billing request: ${JSON.stringify(req.body)}`); + debug("Billing request: %j", req.body); const first = req.body[0]; @@ -135,7 +135,7 @@ app.post("/request/", function(req, res) { playhistory: "000000/0:000000/0:000000/0", }); - debug(`Billing response: ${JSON.stringify(resItems)}`); + debug("Billing response: %j", resItems); res.set("content-type", "text/plain"); res.send(resItems); diff --git a/src/checkdb.ts b/src/checkdb.ts index 0e0f3cf..d772748 100644 --- a/src/checkdb.ts +++ b/src/checkdb.ts @@ -42,7 +42,7 @@ async function initdb(txn: Transaction): Promise { debug("Initializing database"); for (const script of scripts) { - debug(`Executing ${script}`); + debug("Executing %s", script); const scriptPath = resolve(initPath, script); const scriptSql = readFileSync(scriptPath, "utf-8"); @@ -56,7 +56,7 @@ async function initdb(txn: Transaction): Promise { await txn.modify(metaInsert); - debug(`Initialized new database to schema version ${schemaver}`); + debug("Initialized new database to schema version %s", schemaver); } async function migratedb( @@ -72,7 +72,7 @@ async function migratedb( const captures = filename.match(migrateRx); if (captures === null) { - debug(`Warning: Unexpected file ${filename} in SQL migrations dir`); + debug("Warning: Unexpected file %s in SQL migrations dir", filename); continue; } @@ -83,7 +83,7 @@ async function migratedb( continue; } - debug(`Executing database upgrade: ${filename}`); + debug("Executing database upgrade: %s", filename); const scriptPath = resolve(migratePath, filename); const scriptSql = readFileSync(scriptPath, "utf-8"); @@ -126,7 +126,7 @@ export default async function checkdb(db: DataSource): Promise { const newver = await db.transaction(txn => migratedb(txn, schemaver)); if (newver !== undefined) { - debug(`Upgraded database to version ${newver}`); + debug("Upgraded database to version %s", newver); await db.vacuum(); diff --git a/src/chunithm/index.ts b/src/chunithm/index.ts index 5579f56..e233294 100644 --- a/src/chunithm/index.ts +++ b/src/chunithm/index.ts @@ -42,13 +42,13 @@ app.use(express.json()); // Trace requests and responses app.use(function(req, resp, next) { - debug(`\n--- Chunithm ${req.url} ---\n`); - debug(`Request: ${JSON.stringify(req.body)}\n`); + debug("\n--- Chunithm %s ---\n", req.url); + debug("Request: %j", req.body); const prevJson = resp.json; resp.json = function(obj) { - debug(`Response: ${JSON.stringify(obj)}`); + debug("Response: %j", obj); resp.json = prevJson; resp.json.apply(this, arguments); diff --git a/src/diva/index.ts b/src/diva/index.ts index b86f175..930073a 100644 --- a/src/diva/index.ts +++ b/src/diva/index.ts @@ -25,7 +25,7 @@ app.use(async function(req, res, next) { const send_ = res.send; res.send = function(kvps) { - debug(`Response: ${JSON.stringify(kvps)}\n`); + debug("Response: %j", kvps); const bits: string[] = []; @@ -68,7 +68,7 @@ app.use(async function(req, res, next) { req.body = body; debug("\n--- Diva ---\n"); - debug(`Request: ${JSON.stringify(req.body)}\n`); + debug("Request: %j", req.body); return next(); } else if (req.is("multipart/form-data")) { @@ -82,7 +82,7 @@ app.use(async function(req, res, next) { req.body = { ...files, ...fields }; debug("\n--- Diva (Multipart) ---\n"); - debug(`Request: ${JSON.stringify(req.body)}\n`); + debug("Request: %j", req.body); return next(); }); diff --git a/src/idz/decoder/index.ts b/src/idz/decoder/index.ts index 126cb63..ec8574f 100644 --- a/src/idz/decoder/index.ts +++ b/src/idz/decoder/index.ts @@ -184,8 +184,10 @@ export class Decoder extends Transform { const reqBuf = this.state.slice(0, 0x30 + msgLen); const payloadBuf = reqBuf.slice(0x30); - debug(`Raw: ${reqBuf.toString("hex")}`); - debug(`Header: ${JSON.stringify(header)}`); + if (debug.enabled) { + debug("Raw: %s", reqBuf.toString("hex")); + debug("Header: %j", header); + } const reader = readerFns.get(msgCode); @@ -197,7 +199,7 @@ export class Decoder extends Transform { const payload = reader(payloadBuf); - debug(`Payload: ${JSON.stringify(payload)}`); + debug("Payload: %j", payload); return callback(null, payload); } diff --git a/src/idz/encoder/index.ts b/src/idz/encoder/index.ts index e35af94..c890069 100644 --- a/src/idz/encoder/index.ts +++ b/src/idz/encoder/index.ts @@ -150,11 +150,13 @@ export class Encoder extends Transform { } _transform(res: Response, encoding, callback) { - debug(`Object: ${JSON.stringify(res)}`); + debug("Object: %j", res); const buf = encode(res); - debug(`Encoded: ${buf.toString("hex")}`); + if (debug.enabled) { + debug("Encoded: %s", buf.toString("hex")); + } if (buf.readInt16LE(0) === 0) { throw new Error("Missing message type code"); diff --git a/src/idz/index.ts b/src/idz/index.ts index 9439f93..7d3d5fd 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -18,7 +18,9 @@ export default function idz(db: DataSource) { output.write(await db.transaction(txn => dispatch(txn, req))); } } catch (e) { - debug(`Error:\n${e.toString()}`); + if (debug.enabled) { + debug("Error: %s", e.stack); + } } debug("Connection closed"); diff --git a/src/idz/ping.ts b/src/idz/ping.ts index 66d8172..df6f3dc 100644 --- a/src/idz/ping.ts +++ b/src/idz/ping.ts @@ -8,7 +8,7 @@ export default function createPing(port: number, host: string) { socket.bind(port, host); socket.on("message", (msg, rinfo) => { - debug(`Ping from ${rinfo.address}:${rinfo.port}`); + debug("Ping from %s:%s", rinfo.address, rinfo.port); socket.send(msg, rinfo.port, rinfo.address); }); } diff --git a/src/switchboard.ts b/src/switchboard.ts index 99c550c..e91abff 100644 --- a/src/switchboard.ts +++ b/src/switchboard.ts @@ -73,8 +73,8 @@ export function startupUri(model: string): string { // Diagnostic dump // -debug(`HOST_EXT: ${HOST_EXT} (Service host name sent to clients)`); -debug(`HOST_INT: ${HOST_INT} (Bind address)`); +debug("HOST_EXT: %s (Service host name sent to clients)", HOST_EXT); +debug("HOST_INT: %s (Bind address)", HOST_INT); if (cfgHostExt === undefined || cfgHostInt === undefined) { debug(