mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-25 00:49:10 +00:00
refactor: improve console visibility
This commit is contained in:
committed by
Carlos Valente
parent
b99cf5f255
commit
715600a514
+13
-9
@@ -20,6 +20,7 @@ import {
|
|||||||
clearUploadfolder,
|
clearUploadfolder,
|
||||||
} from './setup/index.js';
|
} from './setup/index.js';
|
||||||
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
import { ONTIME_VERSION } from './ONTIME_VERSION.js';
|
||||||
|
import { consoleGreen } from './utils/console.js';
|
||||||
|
|
||||||
// Import Routers
|
// Import Routers
|
||||||
import { appRouter } from './api-data/index.js';
|
import { appRouter } from './api-data/index.js';
|
||||||
@@ -44,6 +45,7 @@ import { populateDemo } from './setup/loadDemo.js';
|
|||||||
import { getState } from './stores/runtimeState.js';
|
import { getState } from './stores/runtimeState.js';
|
||||||
import { initRundown } from './services/rundown-service/RundownService.js';
|
import { initRundown } from './services/rundown-service/RundownService.js';
|
||||||
import { generateCrashReport } from './utils/generateCrashReport.js';
|
import { generateCrashReport } from './utils/generateCrashReport.js';
|
||||||
|
import { getNetworkInterfaces } from './utils/networkInterfaces.js';
|
||||||
|
|
||||||
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
console.log(`Starting Ontime version ${ONTIME_VERSION}`);
|
||||||
|
|
||||||
@@ -158,11 +160,8 @@ export const startServer = async () => {
|
|||||||
|
|
||||||
const { serverPort } = DataProvider.getSettings();
|
const { serverPort } = DataProvider.getSettings();
|
||||||
|
|
||||||
const returnMessage = `Ontime is listening on port ${serverPort}`;
|
|
||||||
|
|
||||||
expressServer = http.createServer(app);
|
expressServer = http.createServer(app);
|
||||||
socket.init(expressServer);
|
socket.init(expressServer);
|
||||||
logger.info(LogOrigin.Server, returnMessage);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Module initialises the services and provides initial payload for the store
|
* Module initialises the services and provides initial payload for the store
|
||||||
@@ -200,7 +199,15 @@ export const startServer = async () => {
|
|||||||
// eventStore set is a dependency of the services that publish to it
|
// eventStore set is a dependency of the services that publish to it
|
||||||
messageService.init(eventStore.set.bind(eventStore));
|
messageService.init(eventStore.set.bind(eventStore));
|
||||||
|
|
||||||
expressServer.listen(serverPort, '0.0.0.0');
|
expressServer.listen(serverPort, '0.0.0.0', () => {
|
||||||
|
const nif = getNetworkInterfaces();
|
||||||
|
for (const key of Object.keys(nif)) {
|
||||||
|
consoleGreen(`Ontime running on: http://${nif[key].address}:${serverPort}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const returnMessage = `Ontime is listening on port ${serverPort}`;
|
||||||
|
logger.info(LogOrigin.Server, returnMessage);
|
||||||
|
|
||||||
return { message: returnMessage, serverPort };
|
return { message: returnMessage, serverPort };
|
||||||
};
|
};
|
||||||
@@ -251,7 +258,6 @@ export const shutdown = async (exitCode = 0) => {
|
|||||||
await restoreService.clear();
|
await restoreService.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Clear token
|
|
||||||
expressServer?.close();
|
expressServer?.close();
|
||||||
runtimeService.shutdown();
|
runtimeService.shutdown();
|
||||||
integrationService.shutdown();
|
integrationService.shutdown();
|
||||||
@@ -263,16 +269,14 @@ export const shutdown = async (exitCode = 0) => {
|
|||||||
process.on('exit', (code) => console.log(`Ontime shutdown with code: ${code}`));
|
process.on('exit', (code) => console.log(`Ontime shutdown with code: ${code}`));
|
||||||
|
|
||||||
process.on('unhandledRejection', async (error) => {
|
process.on('unhandledRejection', async (error) => {
|
||||||
console.error('Error: unhandled rejection', error);
|
|
||||||
generateCrashReport(error);
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Error: unhandled rejection ${error}`);
|
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('uncaughtException', async (error) => {
|
process.on('uncaughtException', async (error) => {
|
||||||
console.error('Error: uncaught exception', error);
|
|
||||||
generateCrashReport(error);
|
generateCrashReport(error);
|
||||||
logger.error(LogOrigin.Server, `Error: uncaught exception ${error}`);
|
logger.error(LogOrigin.Server, `Uncaught exception | ${error}`);
|
||||||
await shutdown(1);
|
await shutdown(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { generateId, millisToString } from 'ontime-utils';
|
|||||||
import { clock } from '../services/Clock.js';
|
import { clock } from '../services/Clock.js';
|
||||||
import { isProduction } from '../setup/index.js';
|
import { isProduction } from '../setup/index.js';
|
||||||
import { socket } from '../adapters/WebsocketAdapter.js';
|
import { socket } from '../adapters/WebsocketAdapter.js';
|
||||||
|
import { consoleRed } from '../utils/console.js';
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
private queue: Log[];
|
private queue: Log[];
|
||||||
@@ -34,8 +35,13 @@ class Logger {
|
|||||||
* @param log
|
* @param log
|
||||||
*/
|
*/
|
||||||
private _push(log: Log) {
|
private _push(log: Log) {
|
||||||
if (!isProduction) {
|
if (!isProduction || log.level === LogLevel.Error) {
|
||||||
console.log(`[${log.level}] \t ${log.origin} \t ${log.text}`);
|
if (log.level === LogLevel.Error) {
|
||||||
|
consoleRed(`[${log.level}] \t ${log.origin} \t ${log.text}`);
|
||||||
|
} else {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(`[${log.level}] \t ${log.origin} \t ${log.text}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -96,7 +102,6 @@ class Logger {
|
|||||||
* Shutdown logger
|
* Shutdown logger
|
||||||
*/
|
*/
|
||||||
shutdown() {
|
shutdown() {
|
||||||
console.log('Shutting down logger');
|
|
||||||
this.queue = [];
|
this.queue = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
/* eslint-disable no-console */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to log messages in green
|
||||||
|
*/
|
||||||
|
export function consoleGreen(message: string) {
|
||||||
|
console.log(`\x1b[32m${message}\x1b[0m`);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility function to log messages in red
|
||||||
|
*/
|
||||||
|
export function consoleRed(message: string) {
|
||||||
|
console.error(`\x1b[31m${message}\x1b[0m`);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user