Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Error.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -832,8 +832,8 @@ export class ErrorBoundary extends React.Component {
// Add window.onerror and window.onunhandledrejection handlers
componentDidMount () {
const errorHandler = async (_error) => {
error("ErrorBoundary caught an error:", _error);
const stateUpdate = await buildExceptionState(_error, {});
error("ErrorBoundary caught an error:", stateUpdate.frontendException ?? stateUpdate.backendException);
this.setState(stateUpdate);
return true;
};
Expand All @@ -851,8 +851,8 @@ export class ErrorBoundary extends React.Component {
const { context } = arg || {};

return async (_error) => {
error("ErrorBoundary caught an error:", _error, context);
const stateUpdate = await buildExceptionState(_error, { context });
error("ErrorBoundary caught an error:", stateUpdate.frontendException ?? stateUpdate.backendException);
this.setState(stateUpdate);
};
};
Expand Down
16 changes: 14 additions & 2 deletions src/helpers/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,32 @@

import cockpit from "cockpit";

// So JSON.stringify(error) includes message, name, and stack instead of "{}"
if (typeof Error.prototype.toJSON !== "function") {
// eslint-disable-next-line no-extend-native
Error.prototype.toJSON = function toJSON () {
return { message: this.message, name: this.name, stack: this.stack };
};
}

const LOG_FILE = "/tmp/anaconda-webui.log";

class Logger {
constructor () {
this.logger = cockpit.file(LOG_FILE);
}

_stringifyArgs (args) {
return JSON.stringify(args);
}

_write_to_journal (level, args) {
cockpit.spawn(["logger", "-t", "anaconda-webui", "-p", level, args.join(" ")]);
return cockpit.spawn(["logger", "-t", "anaconda-webui", "-p", level, this._stringifyArgs(args)]);
}

_write (level, args) {
const timestamp = new Date().toISOString();
const message = `${timestamp} [${level}] ${args.join(" ")}\n`;
const message = `${timestamp} [${level}] ${this._stringifyArgs(args)}\n`;
Comment thread
KKoukiou marked this conversation as resolved.

this.logger.modify(oldContent => oldContent + message);
}
Expand Down
Loading