Skip to content

Commit

Permalink
fix: include all log args in the log message
Browse files Browse the repository at this point in the history
 - 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 <[email protected]>
  • Loading branch information
Akos Kitta committed Jun 23, 2023
1 parent d79bc0d commit 2c10497
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions arduino-ide-extension/src/node/arduino-daemon-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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.)
Expand Down Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions electron/build/patch/backend/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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');
Expand Down

0 comments on commit 2c10497

Please sign in to comment.