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 <a.kitta@arduino.cc>
This commit is contained in:
Akos Kitta 2023-06-16 16:58:57 +02:00 committed by Akos Kitta
parent 95fdc593ed
commit 94d2962985
2 changed files with 14 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import {
DisposableCollection, DisposableCollection,
} from '@theia/core/lib/common/disposable'; } from '@theia/core/lib/common/disposable';
import { Event, Emitter } from '@theia/core/lib/common/event'; 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 { environment } from '@theia/application-package/lib/environment';
import { EnvVariablesServer } from '@theia/core/lib/common/env-variables'; import { EnvVariablesServer } from '@theia/core/lib/common/env-variables';
import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application'; import { BackendApplicationContribution } from '@theia/core/lib/node/backend-application';
@ -171,7 +172,10 @@ export class ArduinoDaemonImpl
const args = await this.getSpawnArgs(); const args = await this.getSpawnArgs();
const cliPath = this.getExecPath(); const cliPath = this.getExecPath();
const ready = new Deferred<{ daemon: ChildProcess; port: string }>(); 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); 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.) // 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 { protected onData(message: string): void {
this.logger.info(message); this.logger.info(message.trim());
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any

View File

@ -6,6 +6,7 @@
// From the specs: https://specifications.freedesktop.org/basedir-spec/latest/ar01s03.html // 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." // "If $XDG_CONFIG_HOME is either not set or empty, a default equal to $HOME/.config should be used."
const os = require('os'); const os = require('os');
const util = require('util');
if (os.platform() === 'linux' && !process.env['XDG_CONFIG_HOME']) { if (os.platform() === 'linux' && !process.env['XDG_CONFIG_HOME']) {
const { join } = require('path'); const { join } = require('path');
const home = process.env['HOME']; const home = process.env['HOME'];
@ -18,12 +19,14 @@ setup({
appName: 'Arduino IDE', appName: 'Arduino IDE',
maxSize: 10 * 1024 * 1024 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]; const original = console[name];
console[name] = (data => { console[name] = function () {
original(data); const messages = Object.values(arguments);
log(data); const message = util.format(...messages)
}).bind(console); original(message)
log(message);
}
} }
const { BackendApplicationConfigProvider } = require('@theia/core/lib/node/backend-application-config-provider'); const { BackendApplicationConfigProvider } = require('@theia/core/lib/node/backend-application-config-provider');