Use debug package for logging

This commit is contained in:
Tau
2019-11-06 17:28:30 -05:00
parent db260d5f2f
commit 9697b4b06e
21 changed files with 110 additions and 60 deletions
+6 -3
View File
@@ -1,3 +1,4 @@
import logger from "debug";
import { Transform } from "stream";
import { _team } from "./_team";
@@ -33,6 +34,8 @@ import { updateTeamLeader } from "./updateTeamLeader";
import { updateTeamMember } from "./updateTeamMember";
import { Response } from "../response";
const debug = logger("app:idz:encoder");
function encode(res: Response): Buffer {
switch (res.type) {
case "check_team_name_res":
@@ -147,14 +150,14 @@ export class Encoder extends Transform {
}
_transform(res: Response, encoding, callback) {
console.log("Idz: Res: Object:", res);
debug(`Object: ${JSON.stringify(res)}`);
const buf = encode(res);
console.log("Idz: Res: Encoded:", buf.toString("hex"));
debug(`Encoded: ${buf.toString("hex")}`);
if (buf.readInt16LE(0) === 0) {
throw new Error("MESSAGE TYPE CODE YOU FUCKING IDIOT");
throw new Error("Missing message type code");
}
return callback(null, buf);