Max length for log messages sent to not miss important information

pull/623/head
cruizba 2021-04-29 23:37:44 +02:00
parent b7da22180c
commit 68eac029c1
4 changed files with 24 additions and 16 deletions

View File

@ -175,7 +175,7 @@ export class Connection {
this.addStream(stream); this.addStream(stream);
}); });
logger.debug("Remote 'Connection' with 'connectionId' [" + this.connectionId + '] is now configured for receiving Streams with options: ', this.stream!.inboundStreamOpts); logger.info("Remote 'Connection' with 'connectionId' [" + this.connectionId + '] is now configured for receiving Streams with options: ', this.stream!.inboundStreamOpts);
} }
/** /**

View File

@ -74,9 +74,9 @@ export abstract class EventDispatcher {
onAux(type: string, message: string, handler: (event: Event) => void): EventDispatcher { onAux(type: string, message: string, handler: (event: Event) => void): EventDispatcher {
const arrowHandler = event => { const arrowHandler = event => {
if (event) { if (event) {
logger.debug(message, event); logger.info(message, event);
} else { } else {
logger.debug(message); logger.info(message);
} }
handler(event); handler(event);
}; };
@ -91,9 +91,9 @@ export abstract class EventDispatcher {
onceAux(type: string, message: string, handler: (event: Event) => void): EventDispatcher { onceAux(type: string, message: string, handler: (event: Event) => void): EventDispatcher {
const arrowHandler = event => { const arrowHandler = event => {
if (event) { if (event) {
logger.debug(message, event); logger.info(message, event);
} else { } else {
logger.debug(message); logger.info(message);
} }
handler(event); handler(event);
// Remove handler from map after first and only execution // Remove handler from map after first and only execution

View File

@ -306,7 +306,7 @@ export class StreamManager extends EventDispatcher {
canplayListenerAdded: false canplayListenerAdded: false
}); });
logger.debug('New video element associated to ', this); logger.info('New video element associated to ', this);
return returnNumber; return returnNumber;
} }

View File

@ -10,6 +10,7 @@ export class OpenViduLogger {
private JSNLOG_URL: string = "/openvidu/elk/openvidu-browser-logs"; private JSNLOG_URL: string = "/openvidu/elk/openvidu-browser-logs";
private MAX_JSNLOG_BATCH_LOG_MESSAGES: number = 100; private MAX_JSNLOG_BATCH_LOG_MESSAGES: number = 100;
private MAX_MSECONDS_BATCH_MESSAGES: number = 5000; private MAX_MSECONDS_BATCH_MESSAGES: number = 5000;
private MAX_LENGTH_STRING_JSON: number = 1000;
private logger: Console = window.console; private logger: Console = window.console;
private LOG_FNS = [this.logger.log, this.logger.debug, this.logger.info, this.logger.warn, this.logger.error]; private LOG_FNS = [this.logger.log, this.logger.debug, this.logger.info, this.logger.warn, this.logger.error];
@ -27,7 +28,7 @@ export class OpenViduLogger {
private constructor() {} private constructor() {}
static configureJSNLog(openVidu: OpenVidu, token: string) { static configureJSNLog(openVidu: OpenVidu, token: string) {
// If instance is created is OpenVidu Pro // If instance is created and it is OpenVidu Pro
if (this.instance && openVidu.webrtcStatsInterval > -1 if (this.instance && openVidu.webrtcStatsInterval > -1
// If logs are enabled // If logs are enabled
&& openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug && openVidu.sendBrowserLogs === OpenViduLoggerConfiguration.debug
@ -86,7 +87,13 @@ export class OpenViduLogger {
return value; return value;
}; };
}; };
return JSON.stringify(obj, getCircularReplacer());
// Cut long messages
const stringifyJson = JSON.stringify(obj, getCircularReplacer());
if (stringifyJson.length > this.instance.MAX_LENGTH_STRING_JSON) {
return `${stringifyJson.substring(0, this.instance.MAX_LENGTH_STRING_JSON)}...`;
}
return stringifyJson;
}; };
// Initialize JL to send logs // Initialize JL to send logs
@ -120,6 +127,15 @@ export class OpenViduLogger {
return OpenViduLogger.instance; return OpenViduLogger.instance;
} }
private isDebugLogEnabled() {
return this.isJSNLogSetup;
}
private canConfigureJSNLog(openVidu: OpenVidu, logger: OpenViduLogger): boolean {
return openVidu.session.sessionId != logger.loggingSessionId &&
openVidu.finalUserId != logger.loggingFinalUserId
}
log(...args: any[]){ log(...args: any[]){
if (!this.isProdMode) { if (!this.isProdMode) {
this.LOG_FNS[0].apply(this.logger, arguments); this.LOG_FNS[0].apply(this.logger, arguments);
@ -170,12 +186,4 @@ export class OpenViduLogger {
this.isProdMode = true; this.isProdMode = true;
} }
private isDebugLogEnabled() {
return this.isJSNLogSetup;
}
private canConfigureJSNLog(openVidu: OpenVidu, logger: OpenViduLogger): boolean {
return openVidu.session.sessionId != logger.loggingSessionId || openVidu.finalUserId != logger.loggingFinalUserId
}
} }