-
-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: forward backend logging to electron (#2236)
Signed-off-by: Akos Kitta <[email protected]>
- Loading branch information
Showing
5 changed files
with
106 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,17 @@ | ||
// @ts-check | ||
'use strict'; | ||
|
||
// Patch for on Linux when `XDG_CONFIG_HOME` is not available, `node-log-rotate` creates the folder with `undefined` name. | ||
// See https://github.com/lemon-sour/node-log-rotate/issues/23 and https://github.com/arduino/arduino-ide/issues/394. | ||
// If the IDE2 is running on Linux, and the `XDG_CONFIG_HOME` variable is not available, set it to avoid the `undefined` folder. | ||
// 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." | ||
function enableFileLogger() { | ||
const os = require('os'); | ||
// `true` if the this (backend main) process has been forked. | ||
if (process.send) { | ||
const util = require('util'); | ||
if (os.platform() === 'linux' && !process.env['XDG_CONFIG_HOME']) { | ||
const { join } = require('path'); | ||
const home = process.env['HOME']; | ||
const xdgConfigHome = home | ||
? join(home, '.config') | ||
: join(os.homedir(), '.config'); | ||
process.env['XDG_CONFIG_HOME'] = xdgConfigHome; | ||
} | ||
const { setup, log } = require('node-log-rotate'); | ||
|
||
setup({ | ||
appName: 'Arduino IDE', | ||
maxSize: 10 * 1024 * 1024, | ||
}); | ||
for (const name of ['log', 'trace', 'debug', 'info', 'warn', 'error']) { | ||
const original = console[name]; | ||
console[name] = function () { | ||
// eslint-disable-next-line prefer-rest-params | ||
const messages = Object.values(arguments); | ||
const message = util.format(...messages); | ||
original(message); | ||
log(message); | ||
const args = Object.values(arguments); | ||
const message = util.format(...args); | ||
process.send?.({ severity: name, message }); // send the log message to the parent process (electron main) | ||
}; | ||
} | ||
} | ||
|
||
if (process.env.IDE2_FILE_LOGGER === 'true') { | ||
enableFileLogger(); | ||
} | ||
|
||
require('./src-gen/backend/main'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters