//log.js
(function() {
/*global adventurejs A*/
"use strict";
var p = adventurejs.Game.prototype;
/**
* Custom logging function.
* @method adventurejs.Game#log
* @memberOf adventurejs.Game
* @param {String|Number} method 0=log, 1=warn, 2=error
* @param {String|Number} level 0=critical, 1=high, 2=medium, 3=low
* @param {*} msg Message for console.
*/
p.log = function Game_log( method, level, msg, keyword )
{
// no logging below 0
if( 0 > this.game.settings.log_level )
{
return;
}
if( "string" !== typeof keyword ) keyword = "";
// exclude keywords that haven't been included
if( method==="log" && true !== this.game.settings.log_keywords[ keyword.toLowerCase() ] )
{
return;
}
// don't log above current level
var levels = [ "critical", "high", "medium", "low" ];
if( "string" === typeof level )
{
level = levels.indexOf( level );
}
if( level > this.game.settings.log_level )
{
return;
}
var methods = [ "log", "warn", "error" ];
if( "undefined" === typeof method
|| null === method )
{
method = "log";
}
if( "number" === typeof method )
{
method = methods[ method ];
}
if( Array.isArray( msg ) )
{
msg = msg.join(" ");
}
var warnOrErr = "";
var style = 'background: #36e400; font-weight:bold; color: #2b2b2b;padding:1px;margin-right:3px;';
if(method === "warn") {
warnOrErr = "warning";
style='background: #e5d254; font-weight:bold; color: #493c35;margin-right:3px;';
}
else if(method === "error") {
warnOrErr = "error";
style='background: #ef866d; font-weight:bold; color: #4a3532;margin-right:3px;';
}
if( "undefined" !== typeof console[ method ] )
{
console[ method ](
"%c ajs " + "%c " + msg,
style,
''
);
if( level <= this.game.settings.log_trace_level )
{
console.groupCollapsed("Trace...");
console.trace();
console.groupEnd();
}
}
return;
}
}());