| 599 | } |
| 600 | |
| 601 | onLogged(path, line, data) { |
| 602 | this.log += data; |
| 603 | if (!this.logPath && path) { |
| 604 | this.logPath = path; |
| 605 | this.logLine = line; |
| 606 | this.knownPaths.add(path); |
| 607 | } |
| 608 | if (this.log.endsWith("\n")) { |
| 609 | if (this.log.startsWith("|:") && this.log.endsWith(":|\n")) { |
| 610 | const payload = this.log.slice(2, this.log.length - 3); |
| 611 | if (payload.startsWith("@filename ")) { |
| 612 | const parts = payload.split(" "); |
| 613 | if (parts[1]) |
| 614 | this.binaryName = parts[1]; |
| 615 | } |
| 616 | else if (payload.startsWith("@close")) { |
| 617 | if (this.binaryOutput) { |
| 618 | fs.closeSync(this.binaryOutput); |
| 619 | this.print(`#xsbug-log capture: ${this.binaryPath}`); |
| 620 | } |
| 621 | delete this.binaryOutput; |
| 622 | delete this.binaryName; |
| 623 | delete this.binaryPath; |
| 624 | } |
| 625 | else if (payload.startsWith("@")) { |
| 626 | // ignore unknown directives |
| 627 | } |
| 628 | else if (payload) { |
| 629 | if (!this.binaryOutput) { |
| 630 | this.binaryPath = process.env.MODDABLE + "/build/tmp/" + (this.binaryName ? this.binaryName : "log.bin"); |
| 631 | this.binaryOutput = fs.openSync(this.binaryPath, "w+"); |
| 632 | } |
| 633 | fs.writeSync(this.binaryOutput, Buffer.from(payload, "base64"), 0); |
| 634 | } |
| 635 | } |
| 636 | else if (this.log.startsWith("# Break: ")) { |
| 637 | // Suppress — onBroken will display this with full context |
| 638 | } |
| 639 | else if (this.log.startsWith("# Exception: ")) { |
| 640 | if (this.exceptionsMode !== 'silent') { |
| 641 | // Show exception with file/line like xsbug does |
| 642 | const msg = this.log.slice(0, this.log.length - 1); |
| 643 | this.print(msg, this.logPath, this.logLine, 'log'); |
| 644 | } |
| 645 | } |
| 646 | else { |
| 647 | this.print(this.log.slice(0, this.log.length - 1), this.logPath, this.logLine, 'log'); |
| 648 | } |
| 649 | this.log = ""; |
| 650 | this.logPath = null; |
| 651 | this.logLine = null; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | onInstrumentValues(values) { |
| 656 | super.onInstrumentValues(values); |