mirror of
https://github.com/djhackersdev/minime.git
synced 2026-04-25 08:06:45 -05:00
Flip-flop on debug logging code style
This commit is contained in:
parent
3aee0f611c
commit
650e05310d
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ async function lookup(
|
|||
req: Req.LookupRequest,
|
||||
now: Date
|
||||
): Promise<Res.LookupResponse> {
|
||||
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<Res.LookupResponse2> {
|
||||
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<Res.RegisterResponse> {
|
||||
debug(`User register: luid=${req.luid}`);
|
||||
debug("User register: luid=%s", req.luid);
|
||||
|
||||
return {
|
||||
type: req.type,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ async function initdb(txn: Transaction): Promise<void> {
|
|||
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<void> {
|
|||
|
||||
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<void> {
|
|||
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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user