From 2c104976db8539584cbc4204ccc237c074806781 Mon Sep 17 00:00:00 2001 From: Akos Kitta Date: Fri, 16 Jun 2023 16:58:57 +0200 Subject: [PATCH] fix: include all log `args` in the log message - In the bundled application, the customized logger that writes the log files bogusly includes only the first message fragment in the log message. This PR ensures all message fragments are included in the final message before it is printed to the console/terminal and persisted to the rotating log files. - Includes messages with `debug` severity in the log. - Disables the ANSI coloring in the CLI daemon log by adding the `NO_COLOR=true` environment variable to the spawned CLI daemon process. - Trims trailing line ending of the daemon log. Signed-off-by: Akos Kitta --- .../src/node/arduino-daemon-impl.ts | 8 ++++++-- electron/build/patch/backend/main.js | 13 ++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/arduino-ide-extension/src/node/arduino-daemon-impl.ts b/arduino-ide-extension/src/node/arduino-daemon-impl.ts index 0e48f3c60..0d0e4e529 100644 --- a/arduino-ide-extension/src/node/arduino-daemon-impl.ts +++ b/arduino-ide-extension/src/node/arduino-daemon-impl.ts @@ -9,6 +9,7 @@ import { DisposableCollection, } from '@theia/core/lib/common/disposable'; import { Event, Emitter } from '@theia/core/lib/common/event'; +import { deepClone } from '@theia/core/lib/common/objects'; import { environment } from '@theia/application-package/lib/environment'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; @@ -171,7 +172,10 @@ export class ArduinoDaemonImpl const args = await this.getSpawnArgs(); const cliPath = this.getExecPath(); const ready = new Deferred<{ daemon: ChildProcess; port: string }>(); - const options = { shell: true }; + const options = { + shell: true, + env: { ...deepClone(process.env), NO_COLOR: String(true) }, + }; const daemon = spawn(`"${cliPath}"`, args, options); // If the process exists right after the daemon gRPC server has started (due to an invalid port, unknown address, TCP port in use, etc.) @@ -258,7 +262,7 @@ export class ArduinoDaemonImpl } protected onData(message: string): void { - this.logger.info(message); + this.logger.info(message.trim()); } // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/electron/build/patch/backend/main.js b/electron/build/patch/backend/main.js index cb138d3c4..6f41b4ed3 100644 --- a/electron/build/patch/backend/main.js +++ b/electron/build/patch/backend/main.js @@ -6,6 +6,7 @@ // From the specs: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html // "If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used." const os = require('os'); +const util = require('util'); if (os.platform() === 'linux' && !process.env['XDG_CONFIG_HOME']) { const { join } = require('path'); const home = process.env['HOME']; @@ -18,12 +19,14 @@ setup({ appName: 'Arduino IDE', maxSize: 10 * 1024 * 1024 }); -for (const name of ['log', 'trace', 'info', 'warn', 'error']) { +for (const name of ['log', 'trace', 'debug', 'info', 'warn', 'error']) { const original = console[name]; - console[name] = (data => { - original(data); - log(data); - }).bind(console); + console[name] = function () { + const messages = Object.values(arguments); + const message = util.format(...messages) + original(message) + log(message); + } } const { BackendApplicationConfigProvider } = require('@theia/core/lib/node/backend-application-config-provider');