-
-
Notifications
You must be signed in to change notification settings - Fork 446
fix: forward backend logging to electron #2236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.