Skip to content
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

[DDW-413] Update support request feature node logs handling #1092

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 cardano-sl-src.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"url": "https://github.com/input-output-hk/cardano-sl",
"rev": "515afc3fb6e8b9804a6c325defa95a778df8c8e8",
"sha256": "0f7djx171jvcp1wxnpy063xnqh28qhl701n9ldsy4bj89bj2iza2",
"rev": "d45e8dfbddde0d4a93a409680ddf9ef68e97e784",
"sha256": "1rpczahvpxv1rvc19g89jsyw8zb7k8n15bxb3h00h9v813szfq00",
"fetchSubmodules": false
}
8 changes: 8 additions & 0 deletions source/main/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ export const APP_NAME = 'Daedalus';
export const runtimeFolderPath = getRuntimeFolderPath(process.platform, process.env, APP_NAME);
export const appLogsFolderPath = launcherConfig.logsPrefix || path.join(runtimeFolderPath, 'Logs');
export const pubLogsFolderPath = path.join(appLogsFolderPath, 'pub');

export const ALLOWED_LOGS = [
'Daedalus.log',
];
export const ALLOWED_NODE_LOGS = new RegExp(/(node.json-)(\d{14}$)/);
export const ALLOWED_LAUNCHER_LOGS = new RegExp(/(launcher-)(\d{14}$)/);
export const MAX_NODE_LOGS_ALLOWED = 3;
export const MAX_LAUNCHER_LOGS_ALLOWED = 3;
58 changes: 29 additions & 29 deletions source/main/ipc-api/get-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@ import { ipcMain } from 'electron';
import { includes, sortBy } from 'lodash';
import fs from 'fs';
import path from 'path';
import { pubLogsFolderPath } from '../config';
import {
pubLogsFolderPath,
MAX_NODE_LOGS_ALLOWED,
ALLOWED_LOGS,
ALLOWED_NODE_LOGS,
ALLOWED_LAUNCHER_LOGS,
MAX_LAUNCHER_LOGS_ALLOWED,
} from '../config';
import { GET_LOGS } from '../../common/ipc-api';

const ALLOWED_LOGS = [
'Daedalus.log',
'launcher',
'node.pub',
'node.pub.0',
'node.pub.1',
'node.pub.2',
'node.pub.3',
'node.pub.4',
'node.pub.5',
'node.pub.6',
'node.pub.7',
'node.pub.8',
'node.pub.9',
'node.pub.10',
'node.pub.11',
'node.pub.12',
'node.pub.13',
'node.pub.14',
'node.pub.15',
'node.pub.16',
'node.pub.17',
'node.pub.18',
'node.pub.19',
];
const isFileAllowed = (fileName: string) => includes(ALLOWED_LOGS, fileName);
const isFileNodeLog = (fileName: string, nodeLogsIncluded: number) =>
ALLOWED_NODE_LOGS.test(fileName) && nodeLogsIncluded < MAX_NODE_LOGS_ALLOWED;
const isFileLauncherLog = (fileName: string, nodeLogsIncluded: number) =>
ALLOWED_LAUNCHER_LOGS.test(fileName) && nodeLogsIncluded < MAX_LAUNCHER_LOGS_ALLOWED;


export default () => {
ipcMain.on(GET_LOGS.REQUEST, (event) => {
Expand All @@ -39,14 +27,26 @@ export default () => {
// check if pub folder exists and create array of log file names
const logFiles = [];
if (fs.existsSync(pubLogsFolderPath)) {
const files = fs.readdirSync(pubLogsFolderPath);

const files = fs
.readdirSync(pubLogsFolderPath)
.sort()
.reverse();

let nodeLogsIncluded = 0;
let launcherLogsIncluded = 0;
for (let i = 0; i < files.length; i++) {
const currentFile = path.join(pubLogsFolderPath, files[i]);
if (fs.statSync(currentFile).isFile()) {
const fileName = path.basename(currentFile);
const isFileAllowed = includes(ALLOWED_LOGS, fileName);
if (isFileAllowed) {
if (isFileAllowed(fileName)) {
logFiles.push(fileName);
} else if (isFileNodeLog(fileName, nodeLogsIncluded)) {
logFiles.push(fileName);
nodeLogsIncluded++;
} else if (isFileLauncherLog(fileName, launcherLogsIncluded)) {
logFiles.push(fileName);
launcherLogsIncluded++;
}
}
}
Expand Down