-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit 'ef714aee69ff6042a252a4c1eb93e29326615b24' into maintena…
…nce/crm-enterprise-1.11
- Loading branch information
Showing
3 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Oro/Bundle/UIBundle/Resources/public/js/tools/logger.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var tools = require('oroui/js/tools'); | ||
var _ = require('underscore'); | ||
var console = window.console; | ||
|
||
return { | ||
/** | ||
* Shows warning, only in DEV mode | ||
* | ||
* ```javascript | ||
* logger.warn('Value `{{value}}` is not valid', {value: 5}); | ||
* ``` | ||
* | ||
* @param {String} message - message to warn | ||
* @param {Object} variables - variables to replace in message text | ||
*/ | ||
warn: function(message, variables) { | ||
var tpl = _.template(message, { | ||
interpolate: /\{\{([\s\S]+?)}}/g | ||
}); | ||
if (tools.debug) { | ||
if (console && console.error) { | ||
// error method is used as it prints stack trace | ||
console.error('Warning: ' + tpl(variables || {})); | ||
} else { | ||
var error = new Error('Warning: ' + tpl(variables || {})); | ||
setTimeout(function() { | ||
throw error; | ||
}, 0); | ||
} | ||
} | ||
}, | ||
|
||
/** | ||
* Throws exception with message | ||
* | ||
* ```javascript | ||
* logger.error('Value `{{value}}` is not valid', {value: 5}); | ||
* ``` | ||
* | ||
* @param {String} message - message for exception to throw | ||
* @param {Object} variables - variables to replace | ||
*/ | ||
error: function(message, variables) { | ||
var tpl = _.template(message, { | ||
interpolate: /{{([\s\S]+?)}}/g | ||
}); | ||
throw new Error(tpl(variables || {})); | ||
} | ||
}; | ||
}); |