Skip to content

Commit

Permalink
feat: add logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
paweldomas committed Nov 23, 2016
1 parent b58f1cd commit 76c8984
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 8 deletions.
36 changes: 35 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global $, config, getRoomName */
/* global $, config, getRoomName, loggingConfig, JitsiMeetJS */
/* application specific logic */
const logger = require("jitsi-meet-logger").getLogger(__filename);

Expand All @@ -19,6 +19,8 @@ import 'aui-experimental-css';

window.toastr = require("toastr");

const Logger = require("jitsi-meet-logger");

import URLProcessor from "./modules/config/URLProcessor";
import RoomnameGenerator from './modules/util/RoomnameGenerator';

Expand All @@ -32,6 +34,7 @@ import UIEvents from './service/UI/UIEvents';
import getTokenData from "./modules/tokendata/TokenData";
import translation from "./modules/translation/translation";


/**
* Tries to push history state with the following parameters:
* 'VideoChat', `Room: ${roomName}`, URL. If fail, prints the error and returns
Expand Down Expand Up @@ -79,6 +82,36 @@ function buildRoomName () {
return roomName;
}

/**
* Adjusts the logging levels.
* @private
*/
function configureLoggingLevels () {
// NOTE The library Logger is separated from the app loggers, so the levels
// have to be set in two places

// Set default logging level
const defaultLogLevel
= loggingConfig.defaultLogLevel || JitsiMeetJS.logLevels.TRACE;
Logger.setLogLevel(defaultLogLevel);
JitsiMeetJS.setLogLevel(defaultLogLevel);

// NOTE console was used on purpose here to go around the logging
// and always print the default logging level to the console
console.info("Default logging level set to: " + defaultLogLevel);

// Set log level for each logger
if (loggingConfig) {
Object.keys(loggingConfig).forEach(function(loggerName) {
if ('defaultLogLevel' !== loggerName) {
const level = loggingConfig[loggerName];
Logger.setLogLevelById(level, loggerName);
JitsiMeetJS.setLogLevelById(level, loggerName);
}
});
}
}

const APP = {
// Used by do_external_connect.js if we receive the attach data after
// connect was already executed. status property can be "initialized",
Expand Down Expand Up @@ -107,6 +140,7 @@ const APP = {
connection: null,
API,
init () {
configureLoggingLevels();
this.keyboardshortcut =
require("./modules/keyboardshortcut/keyboardshortcut");
this.configFetch = require("./modules/config/HttpConfigFetch");
Expand Down
2 changes: 0 additions & 2 deletions conference.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,6 @@ export default {
*/
init(options) {
this.roomName = options.roomName;
JitsiMeetJS.setLogLevel(JitsiMeetJS.logLevels.TRACE);

// attaches global error handler, if there is already one, respect it
if(JitsiMeetJS.getGlobalOnErrorHandler){
var oldOnErrorHandler = window.onerror;
Expand Down
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"utils.js",
"do_external_connect.js",
"interface_config.js",
"logging_config.js",
"lib-jitsi-meet.min.js",
"app.bundle.min.js",
"all.css"
Expand Down Expand Up @@ -43,6 +44,7 @@
<!--#include virtual="connection_optimization/connection_optimization.html" -->
<script src="connection_optimization/do_external_connect.js?v=1"></script>
<script><!--#include virtual="/interface_config.js" --></script>
<script><!--#include virtual="/logging_config.js" --></script>
<script src="libs/lib-jitsi-meet.min.js?v=139"></script>
<script src="libs/app.bundle.min.js?v=139"></script>
<!--#include virtual="title.html" -->
Expand Down
8 changes: 8 additions & 0 deletions logging_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Logging configuration
var loggingConfig = { // eslint-disable-line no-unused-vars
//default log level for the app and lib-jitsi-meet
//defaultLogLevel: 'trace',
// Examples:
//'modules/version/ComponentsVersions.js': 'info',
//'modules/xmpp/ChatRoom.js': 'log'
};
11 changes: 8 additions & 3 deletions modules/config/URLProcessor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global config, interfaceConfig, getConfigParamsFromUrl */
/* global config, interfaceConfig, loggingConfig, getConfigParamsFromUrl */
const logger = require("jitsi-meet-logger").getLogger(__filename);

var configUtils = require('./Util');
Expand Down Expand Up @@ -27,7 +27,8 @@ var URLProcessor = {
// }
var configJSON = {
config: {},
interfaceConfig: {}
interfaceConfig: {},
loggingConfig: {}
};
for (var key in params) {
if (typeof key !== "string") {
Expand All @@ -47,14 +48,18 @@ var URLProcessor = {
} else if (key.indexOf("interfaceConfig.") === 0) {
confObj = configJSON.interfaceConfig;
confKey = key.substr("interfaceConfig.".length);
} else if (key.indexOf("loggingConfig.") === 0) {
confObj = configJSON.loggingConfig;
confKey = key.substr("loggingConfig.".length);
}

if (!confObj)
continue;

confObj[confKey] = params[key];
}
configUtils.overrideConfigJSON(config, interfaceConfig, configJSON);
configUtils.overrideConfigJSON(
config, interfaceConfig, loggingConfig, configJSON);
}
};

Expand Down
12 changes: 10 additions & 2 deletions modules/config/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@ var ConfigUtil = {
* @param config the config object for which we'll be overriding properties
* @param interfaceConfig the interfaceConfig object for which we'll be
* overriding properties.
* @param loggingConfig the logging config object for which we'll be
* overriding properties.
* @param newConfig object containing configuration properties. Destination
* object is selected based on root property name:
* {
* config: {
* // config.js properties to be
* },
* interfaceConfig: {
* // interfaceConfig.js properties here
* // interface_config.js properties here
* },
* loggingConfig: {
* // logging_config.js properties here
* }
* }
*/
overrideConfigJSON: function (config, interfaceConfig, newConfig) {
overrideConfigJSON: function (config,
interfaceConfig, loggingConfig, newConfig) {
var configRoot, key, value, confObj;
for (configRoot in newConfig) {
confObj = null;
if (configRoot == "config") {
confObj = config;
} else if (configRoot == "interfaceConfig") {
confObj = interfaceConfig;
} else if (configRoot == "loggingConfig") {
confObj = loggingConfig;
} else {
continue;
}
Expand Down

0 comments on commit 76c8984

Please sign in to comment.