Skip to content

Commit

Permalink
New logging system
Browse files Browse the repository at this point in the history
  • Loading branch information
frncesc committed Jul 20, 2016
1 parent 5ac8307 commit ee54b8b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"grunt-contrib-clean": "~1.0.0",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jshint": "~1.0.0",
"grunt-contrib-uglify": "~1.0.1",
"grunt-contrib-uglify": "~2.0.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-express": "^1.4.1",
"grunt-extract-sourcemap": "^0.1.17",
Expand Down
39 changes: 35 additions & 4 deletions src/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,44 @@ define([
* @abstract
*/
var Utils = {
/**
* List of valid verbosity levels
* @const {string[]} */
LOG_LEVELS: ['none', 'error', 'warn', 'info', 'debug', 'trace', 'all'],
/**
* Labels printed on logs for each message type
* @const {string[]}
*/
LOG_PRINT_LABELS: [' ', 'ERROR', 'WARN ', 'INFO ', 'DEBUG', 'TRACE', 'ALL '],
/**
* Current verbosity level. Default is 2 (only errror and warning messages are printed)
* @type {number} */
LOG_LEVEL: 2, // warn
/**
* Options of the logging system
* @type {object} */
LOG_OPTIONS: {
prefix: 'JClic',
timestamp: true,
popupOnErrors: false,
chainTo: null,
pipeTo: null
},
/**
* Establishes the current verbosity level of the logging system
* @param {string} level - One of the valid strings in {@link Utils.LOG_LEVELS}
*/
setLogLevel: function (level) {
var log = Utils.LOG_LEVELS.indexOf(level);
if (log >= 0)
Utils.LOG_LEVEL = log;
},
/**
* Reports a new message to the logging system
* @param {string} type - The type of message. Mus be `error`, `warn`, `info`, `debug` or `trace`.
* @param {string} msg - The main message to be logged. Additional parameters can be added, like
* in `console.log` (see: [https://developer.mozilla.org/en-US/docs/Web/API/Console/log])
*/
log: function (type, msg) {
var level = Utils.LOG_LEVELS.indexOf(type);

Expand All @@ -67,9 +90,17 @@ define([
for (var p = 2; p < arguments.length; p++)
args.push(arguments[p]);
console[level === 1 ? 'error' : level === 2 ? 'warn' : 'log'].apply(console, args);
} else {
level === 1 ? console.error(mainMsg) : level === 2 ? console.warn(mainMsg) : console.log(mainMsg);
}
} else
switch (level) {
case 1:
console.error(mainMsg);
break;
case 2:
console.warn(mainMsg);
break;
default:
console.log(mainMsg);
}

// Call chained logger, if anny
if (Utils.LOG_OPTIONS.chainTo)
Expand Down Expand Up @@ -666,4 +697,4 @@ define([
};

return Utils;
});
});
10 changes: 8 additions & 2 deletions src/skins/Skin.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,14 @@ define([
this.$dlgBottomPanel)));

this.$infoHead = $('<div/>', {class: 'infoHead'})
.append($('<div/>', {class: 'headTitle'})
.append($(this.appLogo).css({width: '1.5em', height: '1.5em', 'vertical-align': 'bottom'}))
.append($('<div/>', {class: 'headTitle unselectableText'})
.append($(this.appLogo).css({width: '1.5em', height: '1.5em', 'vertical-align': 'bottom'})
.dblclick(function () {
// Double click on JClic logo is a hidden method to increase verbosity on Javascript console
Utils.setLogLevel('all');
Utils.log('trace', 'Log level set to "trace"');
$(this).off('dblclick');
}))
.append($('<span/>').html('JClic.js')))
.append($('<p/>').css({'margin-top': 0, 'margin-left': '3.5em'})
.append($('<a/>', {href: 'http://clic.xtec.cat/repo/index.html?page=info'}).html('http://clic.xtec.cat'))
Expand Down
4 changes: 2 additions & 2 deletions test/jclic-demo/debug.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<body style="margin: 0">
<div class ="JClic"
data-project="demo.jclic"
data-options='{"fade":"400","logLevel":"trace"}'
data-options='{"fade":"400"}'
data-options-report-with-user='{"reporter":"TCPReporter","path":"localhost:9000","user":"test01","lap":"15"}'
data-options-reporter='{"reporter":"TCPReporter","path":"localhost:9000"}'
data-backOptions='{"skin":"@orange.xml","lang":"es","counters":"false","width":"900","height":"600","fade":"400","fontSubstitutions":{"arial":"Roboto Slab"}}'>
data-backOptions='{"logLevel":"trace","skin":"@orange.xml","lang":"es","counters":"false","width":"900","height":"600","fade":"400","fontSubstitutions":{"arial":"Roboto Slab"}}'>
</div>
</body>
</html>

0 comments on commit ee54b8b

Please sign in to comment.