mirror of
https://gitlab.com/futo-org/fcast.git
synced 2025-08-21 23:02:49 +00:00
Receivers: Added unified logger module
This commit is contained in:
parent
7f9d7939bc
commit
b24b3f0c55
17 changed files with 351 additions and 117 deletions
|
@ -4,14 +4,15 @@ import { DiscoveryService } from 'common/DiscoveryService';
|
|||
import { TcpListenerService } from 'common/TcpListenerService';
|
||||
import { WebSocketListenerService } from 'common/WebSocketListenerService';
|
||||
import { NetworkService } from 'common/NetworkService';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
import { Updater } from './Updater';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
import * as log4js from "log4js";
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
import { ToastIcon } from 'common/components/Toast';
|
||||
const cp = require('child_process');
|
||||
let logger = null;
|
||||
|
||||
export class Main {
|
||||
static shouldOpenMainWindow = true;
|
||||
|
@ -23,7 +24,6 @@ export class Main {
|
|||
static webSocketListenerService: WebSocketListenerService;
|
||||
static discoveryService: DiscoveryService;
|
||||
static tray: Tray;
|
||||
static logger: log4js.Logger;
|
||||
|
||||
private static toggleMainWindow() {
|
||||
if (Main.mainWindow) {
|
||||
|
@ -68,7 +68,7 @@ export class Main {
|
|||
});
|
||||
}
|
||||
|
||||
Main.logger.error('Failed to check for updates:', err);
|
||||
logger.error('Failed to check for updates:', err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,8 +180,8 @@ export class Main {
|
|||
l.emitter.on("resume", () => Main.playerWindow?.webContents?.send("resume"));
|
||||
|
||||
l.emitter.on("stop", () => {
|
||||
Main.playerWindow?.close();
|
||||
Main.playerWindow = null;
|
||||
Main.playerWindow?.close();
|
||||
Main.playerWindow = null;
|
||||
});
|
||||
|
||||
l.emitter.on("seek", (message) => Main.playerWindow?.webContents?.send("seek", message));
|
||||
|
@ -242,7 +242,7 @@ export class Main {
|
|||
defaultId: 0
|
||||
});
|
||||
|
||||
Main.logger.error('Failed to download update:', err);
|
||||
logger.error('Failed to download update:', err);
|
||||
Main.mainWindow?.webContents?.send("download-failed");
|
||||
}
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ export class Main {
|
|||
Main.mainWindow.on('closed', () => {
|
||||
Main.mainWindow = null;
|
||||
|
||||
if (!networkWorker.isDestoryed()) {
|
||||
if (!networkWorker.isDestroyed()) {
|
||||
networkWorker.close();
|
||||
}
|
||||
});
|
||||
|
@ -366,27 +366,28 @@ export class Main {
|
|||
})
|
||||
.options({
|
||||
'no-main-window': { type: 'boolean', default: false, desc: "Start minimized to tray" },
|
||||
'fullscreen': { type: 'boolean', default: false, desc: "Start application in fullscreen" }
|
||||
'fullscreen': { type: 'boolean', default: false, desc: "Start application in fullscreen" },
|
||||
'log': { chocies: ['ALL', 'TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL', 'MARK', 'OFF'], alias: 'loglevel', default: 'INFO', desc: "Defines the verbosity level of the logger" },
|
||||
})
|
||||
.parseSync();
|
||||
|
||||
const isUpdating = Updater.isUpdating();
|
||||
const fileLogType = isUpdating ? 'fileSync' : 'file';
|
||||
log4js.configure({
|
||||
Logger.initialize({
|
||||
appenders: {
|
||||
out: { type: 'stdout' },
|
||||
log: { type: fileLogType, filename: path.join(app.getPath('logs'), 'fcast-receiver.log'), flags: 'a', maxLogSize: '5M' },
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ['out', 'log'], level: 'info' },
|
||||
default: { appenders: ['out', 'log'], level: argv.log },
|
||||
},
|
||||
});
|
||||
Main.logger = log4js.getLogger();
|
||||
Main.logger.info(`Starting application: ${app.name} | ${app.getAppPath()}`);
|
||||
Main.logger.info(`Version: ${app.getVersion()}`);
|
||||
Main.logger.info(`Commit: ${Updater.getCommit()}`);
|
||||
Main.logger.info(`Release channel: ${Updater.releaseChannel} - ${Updater.getChannelVersion()}`);
|
||||
Main.logger.info(`OS: ${process.platform} ${process.arch}`);
|
||||
logger = new Logger('Main', LoggerType.BACKEND);
|
||||
logger.info(`Starting application: ${app.name} | ${app.getAppPath()}`);
|
||||
logger.info(`Version: ${app.getVersion()}`);
|
||||
logger.info(`Commit: ${Updater.getCommit()}`);
|
||||
logger.info(`Release channel: ${Updater.releaseChannel} - ${Updater.getChannelVersion()}`);
|
||||
logger.info(`OS: ${process.platform} ${process.arch}`);
|
||||
|
||||
if (isUpdating) {
|
||||
await Updater.processUpdate();
|
||||
|
@ -415,7 +416,7 @@ export class Main {
|
|||
Main.application.on('window-all-closed', () => { });
|
||||
}
|
||||
catch (err) {
|
||||
Main.logger.error(`Error starting application: ${err}`);
|
||||
logger.error(`Error starting application: ${err}`);
|
||||
app.exit();
|
||||
}
|
||||
}
|
||||
|
@ -435,15 +436,15 @@ export function getComputerName() {
|
|||
hostname = os.hostname();
|
||||
}
|
||||
catch (err) {
|
||||
Main.logger.warn('Error fetching hostname, trying different method...');
|
||||
Main.logger.warn(err);
|
||||
logger.warn('Error fetching hostname, trying different method...');
|
||||
logger.warn(err);
|
||||
|
||||
try {
|
||||
hostname = cp.execSync("hostnamectl hostname").toString().trim();
|
||||
}
|
||||
catch (err2) {
|
||||
Main.logger.warn('Error fetching hostname again, using generic name...');
|
||||
Main.logger.warn(err2);
|
||||
logger.warn('Error fetching hostname again, using generic name...');
|
||||
logger.warn(err2);
|
||||
|
||||
hostname = 'linux device';
|
||||
}
|
||||
|
@ -458,7 +459,7 @@ export function getComputerName() {
|
|||
}
|
||||
|
||||
export async function errorHandler(err: NodeJS.ErrnoException) {
|
||||
Main.logger.error("Application error:", err);
|
||||
logger.error("Application error:", err);
|
||||
Main.mainWindow?.webContents?.send("toast", { message: err, icon: ToastIcon.ERROR });
|
||||
|
||||
const restartPrompt = await dialog.showMessageBox({
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import storage from 'electron-json-storage';
|
||||
import { app } from 'electron';
|
||||
import * as log4js from "log4js";
|
||||
const logger = log4js.getLogger();
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
const logger = new Logger('Store', LoggerType.BACKEND);
|
||||
|
||||
export class Store {
|
||||
private static storeVersion = 1;
|
||||
|
|
|
@ -2,13 +2,14 @@ import * as fs from 'fs';
|
|||
import * as https from 'https';
|
||||
import * as path from 'path';
|
||||
import * as crypto from 'crypto';
|
||||
import * as log4js from "log4js";
|
||||
import { app } from 'electron';
|
||||
import { Store } from './Store';
|
||||
import sudo from 'sudo-prompt';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
|
||||
const cp = require('child_process');
|
||||
const extract = require('extract-zip');
|
||||
const logger = log4js.getLogger();
|
||||
const logger = new Logger('Updater', LoggerType.BACKEND);
|
||||
|
||||
enum UpdateState {
|
||||
Copy = 'copy',
|
||||
|
@ -193,7 +194,7 @@ export class Updater {
|
|||
// Also does not work very well on Mac...
|
||||
private static relaunch(binPath: string) {
|
||||
logger.info(`Relaunching app binary: ${binPath}`);
|
||||
log4js.shutdown();
|
||||
logger.shutdown();
|
||||
|
||||
let proc;
|
||||
if (process.platform === 'win32') {
|
||||
|
@ -394,7 +395,8 @@ export class Updater {
|
|||
|
||||
logger.info('Extraction complete.');
|
||||
const updateInfo: UpdateInfo = {
|
||||
updateState: UpdateState.Copy,
|
||||
// updateState: UpdateState.Copy,
|
||||
updateState: UpdateState.Cleanup,
|
||||
installPath: Updater.installPath,
|
||||
tempPath: path.dirname(destination),
|
||||
currentVersion: Updater.releasesJson.currentVersion,
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import { ipcRenderer } from 'electron';
|
||||
import si from 'modules/systeminformation';
|
||||
import { Logger, LoggerType } from 'common/Logger';
|
||||
const logger = new Logger('NetworkWorker', LoggerType.FRONTEND);
|
||||
|
||||
const networkStateChangeListenerTimeout = 2500;
|
||||
let networkStateChangeListenerInterfaces = [];
|
||||
|
@ -10,11 +12,11 @@ setInterval(networkStateChangeListener, networkStateChangeListenerTimeout);
|
|||
function networkStateChangeListener(forceUpdate: boolean) {
|
||||
new Promise<void>((resolve) => {
|
||||
si.networkInterfaces((data) => {
|
||||
// console.log(data);
|
||||
// logger.info(data);
|
||||
const queriedInterfaces = Array.isArray(data) ? data : [data];
|
||||
|
||||
si.wifiConnections((data) => {
|
||||
// console.log(data);
|
||||
// logger.info(data);
|
||||
const wifiConnections = Array.isArray(data) ? data : [data];
|
||||
|
||||
const interfaces = [];
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import 'common/main/Renderer';
|
||||
|
||||
const logger = window.targetAPI.logger;
|
||||
export function onQRCodeRendered() {}
|
||||
|
||||
const updateView = document.getElementById("update-view");
|
||||
|
@ -14,7 +15,7 @@ const progressBarProgress = document.getElementById("progress-bar-progress");
|
|||
let updaterProgressUIUpdateTimer = null;
|
||||
|
||||
window.electronAPI.onUpdateAvailable(() => {
|
||||
console.log(`Received UpdateAvailable event`);
|
||||
logger.info(`Received UpdateAvailable event`);
|
||||
updateViewTitle.textContent = 'FCast update available';
|
||||
|
||||
updateText.textContent = 'Do you wish to update now?';
|
||||
|
@ -26,7 +27,7 @@ window.electronAPI.onUpdateAvailable(() => {
|
|||
});
|
||||
|
||||
window.electronAPI.onDownloadComplete(() => {
|
||||
console.log(`Received DownloadComplete event`);
|
||||
logger.info(`Received DownloadComplete event`);
|
||||
window.clearTimeout(updaterProgressUIUpdateTimer);
|
||||
updateViewTitle.textContent = 'FCast update ready';
|
||||
|
||||
|
@ -39,7 +40,7 @@ window.electronAPI.onDownloadComplete(() => {
|
|||
});
|
||||
|
||||
window.electronAPI.onDownloadFailed(() => {
|
||||
console.log(`Received DownloadFailed event`);
|
||||
logger.info(`Received DownloadFailed event`);
|
||||
window.clearTimeout(updaterProgressUIUpdateTimer);
|
||||
updateView.setAttribute("style", "display: none");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue