[mirotalk] - #298 add json logs format, update dep

This commit is contained in:
Miroslav Pejic
2025-07-13 18:35:38 +02:00
parent ccc719680c
commit fe2a51c1fc
7 changed files with 99 additions and 102 deletions
+3 -1
View File
@@ -19,6 +19,8 @@ TZ=UTC
LOGS_DEBUG=true # true or false
LOGS_COLORS=true # true or false
LOGS_JSON=false # true or false
LOGS_JSON_PRETTY=false # true or false
# Cors
# Origin: Allow specified origin es '["https://example.com", "https://subdomain.example.com", "http://localhost:3000"]' or
@@ -190,4 +192,4 @@ EMAIL_SEND_TO=p2p.mirotalk@gmail.com
STATS_ENABLED=true # true or false
STATS_SCR=https://stats.mirotalk.com/script.js
STATS_ID=c7615aa7-ceec-464a-baba-54cb605d7261
STATS_ID=b3dc4db6-e6bd-468f-ab4d-58e93b23c6a8
+69 -74
View File
@@ -1,18 +1,15 @@
'use strict';
const util = require('util');
const colors = require('colors');
const LOGS_DEBUG = process.env.LOGS_DEBUG ? process.env.LOGS_DEBUG === 'true' : true;
const LOGS_COLORS = process.env.LOGS_COLORS ? process.env.LOGS_COLORS === 'true' : true;
const LOGS_JSON = process.env.LOGS_JSON ? process.env.LOGS_JSON === 'true' : false;
const LOGS_JSON_PRETTY = process.env.LOGS_JSON_PRETTY ? process.env.LOGS_JSON_PRETTY === 'true' : false;
console.log('Logs', {
colors: LOGS_COLORS,
debug: LOGS_DEBUG,
});
LOGS_COLORS ? colors.enable() : colors.disable();
if (LOGS_COLORS) colors.enable();
else colors.disable();
const options = {
depth: null,
@@ -20,104 +17,102 @@ const options = {
};
module.exports = class Logs {
constructor(appName = 'miroTalkP2P') {
this.appName = colors.yellow(appName);
this.appName = appName;
this.debugOn = LOGS_DEBUG;
this.timeStart = Date.now();
this.timeEnd = null;
this.timeElapsedMs = null;
this.tzOptions = {
timeZone: process.env.TZ || 'UTC', // Fallback to UTC if TZ environment variable is not set
hour12: false, // Set hour12 to false for 24-hour format
timeZone: process.env.TZ || 'UTC',
hour12: false,
};
}
/**
* Console debug logs
* @param {string} msg message
* @param {object} op optional params
* @returns
*/
jsonLog(level, appName, msg, op, extra = {}) {
const logObj = {
timestamp: new Date().toISOString(),
level,
app: appName,
message: msg,
...extra,
};
if (op && typeof op === 'object' && Object.keys(op).length > 0) {
logObj.data = op;
}
// Output pretty JSON if LOGS_JSON_PRETTY is set, else compact one line JSON
LOGS_JSON_PRETTY ? console.log(JSON.stringify(logObj, null, 2)) : console.log(JSON.stringify(logObj));
}
debug(msg, op = '') {
if (this.debugOn) {
this.timeEnd = Date.now();
this.timeElapsedMs = this.getFormatTime(Math.floor(this.timeEnd - this.timeStart));
if (!this.debugOn) return;
this.timeEnd = Date.now();
this.timeElapsedMs = this.getFormatTime(Math.floor(this.timeEnd - this.timeStart));
if (LOGS_JSON) {
this.jsonLog('debug', this.appName, msg, op, { elapsed: this.timeElapsedMs });
} else {
console.debug(
'[' + this.getDateTime() + '] [' + this.appName + '] ' + msg,
'[' + this.getDateTime() + '] [' + colors.yellow(this.appName) + '] ' + msg,
util.inspect(op, options),
this.timeElapsedMs
colors.magenta(this.timeElapsedMs)
);
}
this.timeStart = Date.now();
}
log(msg, op = '') {
if (LOGS_JSON) {
jsonLog('log', this.appName, msg, op);
} else {
console.log(
'[' + this.getDateTime() + '] [' + colors.yellow(this.appName) + '] ' + msg,
util.inspect(op, options)
);
this.timeStart = Date.now();
}
}
/**
* Console logs
* @param {string} msg message
* @param {object} op optional params
* @returns
*/
log(msg, op = '') {
console.log('[' + this.getDateTime() + '] [' + this.appName + '] ' + msg, util.inspect(op, options));
}
/**
* Console info logs
* @param {string} msg message
* @param {object} op optional params
* @returns
*/
info(msg, op = '') {
console.info(
'[' + this.getDateTime() + '] [' + this.appName + '] ' + colors.green(msg),
util.inspect(op, options)
);
if (LOGS_JSON) {
this.jsonLog('info', this.appName, msg, op);
} else {
console.info(
'[' + this.getDateTime() + '] [' + colors.yellow(this.appName) + '] ' + colors.green(msg),
util.inspect(op, options)
);
}
}
/**
* Console warning logs
* @param {string} msg message
* @param {object} op optional params
* @returns
*/
warn(msg, op = '') {
console.warn(
'[' + this.getDateTime() + '] [' + this.appName + '] ' + colors.yellow(msg),
util.inspect(op, options)
);
if (LOGS_JSON) {
this.jsonLog('warn', this.appName, msg, op);
} else {
console.warn(
'[' + this.getDateTime() + '] [' + colors.yellow(this.appName) + '] ' + colors.yellow(msg),
util.inspect(op, options)
);
}
}
/**
* Console error logs
* @param {string} msg message
* @param {object} op optional params
* @returns
*/
error(msg, op = '') {
console.error(
'[' + this.getDateTime() + '] [' + this.appName + '] ' + colors.red(msg),
util.inspect(op, options)
);
if (LOGS_JSON) {
this.jsonLog('error', this.appName, msg, op);
} else {
console.error(
'[' + this.getDateTime() + '] [' + colors.yellow(this.appName) + '] ' + colors.red(msg),
util.inspect(op, options)
);
}
}
/**
* Get date time
* @returns {string} date to Local String
*/
getDateTime() {
const currentTime = new Date().toLocaleString('en-US', this.tzOptions);
const milliseconds = String(new Date().getMilliseconds()).padStart(3, '0');
return colors.cyan(`${currentTime}:${milliseconds}`);
}
/**
* Get format time
* @param {integer} ms
* @returns formatted time
*/
getFormatTime(ms) {
let time = Math.floor(ms);
let type = 'ms';
if (ms >= 1000) {
time = Math.floor((ms / 1000) % 60);
type = 's';
@@ -126,10 +121,10 @@ module.exports = class Logs {
time = Math.floor((ms / 1000 / 60) % 60);
type = 'm';
}
if (ms >= (3, 6e6)) {
if (ms >= 3.6e6) {
time = Math.floor((ms / 1000 / 60 / 60) % 24);
type = 'h';
}
return colors.magenta('+' + time + type);
return '+' + time + type;
}
};
+1 -1
View File
@@ -45,7 +45,7 @@ dependencies: {
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.30
* @version 1.5.31
*
*/
+21 -21
View File
@@ -1,17 +1,17 @@
{
"name": "mirotalk",
"version": "1.5.30",
"version": "1.5.31",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mirotalk",
"version": "1.5.30",
"version": "1.5.31",
"license": "AGPL-3.0",
"dependencies": {
"@mattermost/client": "10.8.0",
"@ngrok/ngrok": "1.5.1",
"@sentry/node": "^9.37.0",
"@sentry/node": "^9.38.0",
"axios": "^1.10.0",
"chokidar": "^4.0.3",
"colors": "^1.4.0",
@@ -1037,18 +1037,18 @@
"license": "Apache-2.0"
},
"node_modules/@sentry/core": {
"version": "9.37.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-9.37.0.tgz",
"integrity": "sha512-RyIsIIcIzEngvvNRr+0oAHJpeAgT5sP12qQXAY6DpeBfFJc9tRTdvxaTURNTkfh+WWO35eIqr4XEB4Hp7Q81IA==",
"version": "9.38.0",
"resolved": "https://registry.npmjs.org/@sentry/core/-/core-9.38.0.tgz",
"integrity": "sha512-dUwSv1VXDfsrcY69a/cgZNDsFal6iYOf0C4T+/ylpmgYp5SVe3vQK+2FLXUMuvgnOf+kHO6IeW0RhnhSyUflmA==",
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/@sentry/node": {
"version": "9.37.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-9.37.0.tgz",
"integrity": "sha512-wj0y6Yo4u3qa/qzTW6Xwvf9G6njxSkPxJ91Bpb/iqhf8JGWJnigXkyq9R2qnelXazCX44TYqqC+zHpaBiX9pLg==",
"version": "9.38.0",
"resolved": "https://registry.npmjs.org/@sentry/node/-/node-9.38.0.tgz",
"integrity": "sha512-OhfRTge6hncSehrTBHpnz5R66OWRd8WMKn6ZoS0nwBmTfREjPkNRfOADIUqEElfyuaNj+gWsqTM1/E915pnZew==",
"license": "MIT",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
@@ -1081,9 +1081,9 @@
"@opentelemetry/sdk-trace-base": "^1.30.1",
"@opentelemetry/semantic-conventions": "^1.34.0",
"@prisma/instrumentation": "6.11.1",
"@sentry/core": "9.37.0",
"@sentry/node-core": "9.37.0",
"@sentry/opentelemetry": "9.37.0",
"@sentry/core": "9.38.0",
"@sentry/node-core": "9.38.0",
"@sentry/opentelemetry": "9.38.0",
"import-in-the-middle": "^1.14.2",
"minimatch": "^9.0.0"
},
@@ -1101,13 +1101,13 @@
}
},
"node_modules/@sentry/node/node_modules/@sentry/node-core": {
"version": "9.37.0",
"resolved": "https://registry.npmjs.org/@sentry/node-core/-/node-core-9.37.0.tgz",
"integrity": "sha512-j/DM2jb2egZQyTJx76QtOh4qskL9kduIPMy9OXC+6m6nY+rVbRhIgs9aDjn3GE+DdUU79OMIoy10g8basGjM5Q==",
"version": "9.38.0",
"resolved": "https://registry.npmjs.org/@sentry/node-core/-/node-core-9.38.0.tgz",
"integrity": "sha512-G0JmsntsvALoqS9iLTi4Jn1DcQB7gw9PY1Fmkdcdcf7i4EJEdRDX0tiD9ssDrcjgzzFPnm0PCrSAkIfTtd3Zyg==",
"license": "MIT",
"dependencies": {
"@sentry/core": "9.37.0",
"@sentry/opentelemetry": "9.37.0",
"@sentry/core": "9.38.0",
"@sentry/opentelemetry": "9.38.0",
"import-in-the-middle": "^1.14.2"
},
"engines": {
@@ -1124,12 +1124,12 @@
}
},
"node_modules/@sentry/node/node_modules/@sentry/opentelemetry": {
"version": "9.37.0",
"resolved": "https://registry.npmjs.org/@sentry/opentelemetry/-/opentelemetry-9.37.0.tgz",
"integrity": "sha512-vJfy7TyYIvKYzzqFlVDZNHm3gzPmr14eyyXYmCVkpWKsqZWdJChg5zfGJTXujLKwMsTFVOt08RMw2DF1s9r5jA==",
"version": "9.38.0",
"resolved": "https://registry.npmjs.org/@sentry/opentelemetry/-/opentelemetry-9.38.0.tgz",
"integrity": "sha512-Oa0kk4EiBMwCvHS5ZI50M/SMNfGM9ztsmedFEfpS+mZz8y9C5Artd0ukGK4OAYcSBggNVQkhmmhWbwpNnRNQiw==",
"license": "MIT",
"dependencies": {
"@sentry/core": "9.37.0"
"@sentry/core": "9.38.0"
},
"engines": {
"node": ">=18"
+2 -2
View File
@@ -1,6 +1,6 @@
{
"name": "mirotalk",
"version": "1.5.30",
"version": "1.5.31",
"description": "A free WebRTC browser-based video call",
"main": "server.js",
"scripts": {
@@ -43,7 +43,7 @@
"dependencies": {
"@mattermost/client": "10.8.0",
"@ngrok/ngrok": "1.5.1",
"@sentry/node": "^9.37.0",
"@sentry/node": "^9.38.0",
"axios": "^1.10.0",
"chokidar": "^4.0.3",
"colors": "^1.4.0",
+1 -1
View File
@@ -73,7 +73,7 @@ let brand = {
},
about: {
imageUrl: '../images/mirotalk-logo.gif',
title: 'WebRTC P2P v1.5.30',
title: 'WebRTC P2P v1.5.31',
html: `
<button
id="support-button"
+2 -2
View File
@@ -15,7 +15,7 @@
* @license For commercial use or closed source, contact us at license.mirotalk@gmail.com or purchase directly from CodeCanyon
* @license CodeCanyon: https://codecanyon.net/item/mirotalk-p2p-webrtc-realtime-video-conferences/38376661
* @author Miroslav Pejic - miroslav.pejic.85@gmail.com
* @version 1.5.30
* @version 1.5.31
*
*/
@@ -11240,7 +11240,7 @@ function showAbout() {
Swal.fire({
background: swBg,
position: 'center',
title: brand.about?.title && brand.about.title.trim() !== '' ? brand.about.title : 'WebRTC P2P v1.5.30',
title: brand.about?.title && brand.about.title.trim() !== '' ? brand.about.title : 'WebRTC P2P v1.5.31',
imageUrl: brand.about?.imageUrl && brand.about.imageUrl.trim() !== '' ? brand.about.imageUrl : images.about,
customClass: { image: 'img-about' },
html: `