feat: logging errors on log file

This commit is contained in:
Fabio Di Stasio 2023-11-27 13:36:56 +01:00
parent c3d96cb35b
commit 315d9d84c2
7 changed files with 80 additions and 75 deletions

17
package-lock.json generated
View File

@ -19,7 +19,7 @@
"@vueuse/core": "~10.4.1",
"ace-builds": "~1.24.1",
"better-sqlite3": "~9.1.1",
"electron-log": "~4.4.1",
"electron-log": "~5.0.1",
"electron-store": "~8.1.0",
"electron-updater": "~4.6.5",
"electron-window-state": "~5.0.3",
@ -6859,9 +6859,12 @@
}
},
"node_modules/electron-log": {
"version": "4.4.8",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.4.8.tgz",
"integrity": "sha512-QQ4GvrXO+HkgqqEOYbi+DHL7hj5JM+nHi/j+qrN9zeeXVKy8ZABgbu4CnG+BBqDZ2+tbeq9tUC4DZfIWFU5AZA=="
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.0.1.tgz",
"integrity": "sha512-x4wnwHg00h/onWQgjmvcdLV7Mrd9TZjxNs8LmXVpqvANDf4FsSs5wLlzOykWLcaFzR3+5hdVEQ8ctmrUxgHlPA==",
"engines": {
"node": ">= 14"
}
},
"node_modules/electron-publish": {
"version": "24.5.0",
@ -22406,9 +22409,9 @@
}
},
"electron-log": {
"version": "4.4.8",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-4.4.8.tgz",
"integrity": "sha512-QQ4GvrXO+HkgqqEOYbi+DHL7hj5JM+nHi/j+qrN9zeeXVKy8ZABgbu4CnG+BBqDZ2+tbeq9tUC4DZfIWFU5AZA=="
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/electron-log/-/electron-log-5.0.1.tgz",
"integrity": "sha512-x4wnwHg00h/onWQgjmvcdLV7Mrd9TZjxNs8LmXVpqvANDf4FsSs5wLlzOykWLcaFzR3+5hdVEQ8ctmrUxgHlPA=="
},
"electron-publish": {
"version": "24.5.0",

View File

@ -127,7 +127,7 @@
"@vueuse/core": "~10.4.1",
"ace-builds": "~1.24.1",
"better-sqlite3": "~9.1.1",
"electron-log": "~4.4.1",
"electron-log": "~5.0.1",
"electron-store": "~8.1.0",
"electron-updater": "~4.6.5",
"electron-window-state": "~5.0.3",

View File

@ -8,7 +8,7 @@ import * as path from 'path';
import { validateSender } from '../libs/misc/validateSender';
const isDevelopment = process.env.NODE_ENV !== 'production';
const isFlatpak = process.platform === 'linux' && Boolean(process.env.FLATPAK_ID?.includes('fabiodistasio') || process.env.FLATPAK_ID?.includes('AntaresSQL'));
const isFlatpak = process.platform === 'linux' && process.env.FLATPAK_ID;
export default (connections: {[key: string]: antares.Client}) => {
let exporter: ChildProcessWithoutNullStreams = null;

View File

@ -1,4 +1,5 @@
import { ipcMain } from 'electron';
import * as log from 'electron-log/main';
import * as Store from 'electron-store';
import { autoUpdater } from 'electron-updater';
@ -59,7 +60,7 @@ export default () => {
mainWindow.reply('update-downloaded');
});
// autoUpdater.logger = require('electron-log');
// autoUpdater.logger.transports.console.format = '{h}:{i}:{s} {text}';
// autoUpdater.logger.transports.file.level = 'info';
log.transports.file.level = 'info';
// log.transports.console.format = '{h}:{i}:{s} {text}';
autoUpdater.logger = log;
};

View File

@ -1,5 +1,6 @@
import * as remoteMain from '@electron/remote/main';
import { app, BrowserWindow, ipcMain, nativeImage, safeStorage } from 'electron';
import * as log from 'electron-log/main';
import * as Store from 'electron-store';
import * as windowStateKeeper from 'electron-window-state';
import * as path from 'path';
@ -8,6 +9,7 @@ import ipcHandlers from './ipc-handlers';
import { OsMenu, ShortcutRegister } from './libs/ShortcutRegister';
Store.initRenderer();
log.errorHandler.startCatching();
const settingsStore = new Store({ name: 'settings' });
const appTheme = settingsStore.get('application_theme');
const isDevelopment = process.env.NODE_ENV !== 'production';

View File

@ -1,4 +1,5 @@
import * as antares from 'common/interfaces/antares';
import * as log from 'electron-log/main';
import * as fs from 'fs';
import { MySQLClient } from '../libs/clients/MySQLClient';
@ -8,64 +9,74 @@ import MysqlExporter from '../libs/exporters/sql/MysqlExporter';
import PostgreSQLExporter from '../libs/exporters/sql/PostgreSQLExporter';
let exporter: antares.Exporter;
log.transports.file.fileName = 'workers.log';
log.errorHandler.startCatching();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.on('message', async ({ type, client, tables, options }: any) => {
if (type === 'init') {
const connection = await ClientsFactory.getClient({
client: client.name,
params: client.config,
poolSize: 5
}) as MySQLClient | PostgreSQLClient;
await connection.connect();
try {
const connection = await ClientsFactory.getClient({
client: client.name,
params: client.config,
poolSize: 5
}) as MySQLClient | PostgreSQLClient;
await connection.connect();
switch (client.name) {
case 'mysql':
case 'maria':
exporter = new MysqlExporter(connection as MySQLClient, tables, options);
break;
case 'pg':
exporter = new PostgreSQLExporter(connection as PostgreSQLClient, tables, options);
break;
default:
switch (client.name) {
case 'mysql':
case 'maria':
exporter = new MysqlExporter(connection as MySQLClient, tables, options);
break;
case 'pg':
exporter = new PostgreSQLExporter(connection as PostgreSQLClient, tables, options);
break;
default:
process.send({
type: 'error',
payload: `"${client.name}" exporter not aviable`
});
return;
}
exporter.once('error', err => {
log.error(err.toString());
process.send({
type: 'error',
payload: `"${client.name}" exporter not aviable`
payload: err.toString()
});
return;
}
});
exporter.once('error', err => {
console.error(err);
exporter.once('end', () => {
process.send({
type: 'end',
payload: { cancelled: exporter.isCancelled }
});
connection.destroy();
});
exporter.once('cancel', () => {
fs.unlinkSync(exporter.outputFile);
process.send({ type: 'cancel' });
});
exporter.on('progress', state => {
process.send({
type: 'export-progress',
payload: state
});
});
exporter.run();
}
catch (err) {
log.error(err.toString());
process.send({
type: 'error',
payload: err.toString()
});
});
exporter.once('end', () => {
process.send({
type: 'end',
payload: { cancelled: exporter.isCancelled }
});
connection.destroy();
});
exporter.once('cancel', () => {
fs.unlinkSync(exporter.outputFile);
process.send({ type: 'cancel' });
});
exporter.on('progress', state => {
process.send({
type: 'export-progress',
payload: state
});
});
exporter.run();
}
}
else if (type === 'cancel')
exporter.cancel();
});
process.on('beforeExit', console.log);

View File

@ -1,6 +1,7 @@
import SSHConfig from '@fabio286/ssh2-promise/lib/sshConfig';
import * as antares from 'common/interfaces/antares';
import { ImportOptions } from 'common/interfaces/importer';
import * as log from 'electron-log/main';
import * as mysql from 'mysql2';
import * as pg from 'pg';
@ -11,6 +12,9 @@ import MySQLImporter from '../libs/importers/sql/MySQLlImporter';
import PostgreSQLImporter from '../libs/importers/sql/PostgreSQLImporter';
let importer: antares.Importer;
log.transports.file.fileName = 'workers.log';
log.errorHandler.startCatching();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
process.on('message', async ({ type, dbConfig, options }: {
type: string;
@ -49,7 +53,7 @@ process.on('message', async ({ type, dbConfig, options }: {
}
importer.once('error', err => {
console.error(err);
log.error(err.toString());
process.send({
type: 'error',
payload: err.toString()
@ -84,7 +88,7 @@ process.on('message', async ({ type, dbConfig, options }: {
importer.run();
}
catch (err) {
console.error(err);
log.error(err.toString());
process.send({
type: 'error',
payload: err.toString()
@ -94,19 +98,3 @@ process.on('message', async ({ type, dbConfig, options }: {
else if (type === 'cancel')
importer.cancel();
});
process.on('uncaughtException', (err) => {
console.error(err);
process.send({
type: 'error',
payload: err.toString()
});
});
process.on('unhandledRejection', (err) => {
console.error(err);
process.send({
type: 'error',
payload: err.toString()
});
});