mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-21 17:00:24 +00:00
the flag must be in all src and test files so that we get the benefit of running in the strict mode even in jstd the following script was used to modify all files: for file in `find src test -name "*.js"`; do echo -e "'use strict';\n" > temp.txt cat $file >> temp.txt mv temp.txt $file done
94 lines
2.3 KiB
JavaScript
94 lines
2.3 KiB
JavaScript
'use strict';
|
|
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc service
|
|
* @name angular.service.$log
|
|
* @requires $window
|
|
*
|
|
* @description
|
|
* Simple service for logging. Default implementation writes the message
|
|
* into the browser's console (if present).
|
|
*
|
|
* The main purpose of this service is to simplify debugging and troubleshooting.
|
|
*
|
|
* @example
|
|
<doc:example>
|
|
<doc:source>
|
|
<p>Reload this page with open console, enter text and hit the log button...</p>
|
|
Message:
|
|
<input type="text" name="message" value="Hello World!"/>
|
|
<button ng:click="$log.log(message)">log</button>
|
|
<button ng:click="$log.warn(message)">warn</button>
|
|
<button ng:click="$log.info(message)">info</button>
|
|
<button ng:click="$log.error(message)">error</button>
|
|
</doc:source>
|
|
<doc:scenario>
|
|
</doc:scenario>
|
|
</doc:example>
|
|
*/
|
|
var $logFactory; //reference to be used only in tests
|
|
angularServiceInject("$log", $logFactory = function($window){
|
|
return {
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc method
|
|
* @name angular.service.$log#log
|
|
* @methodOf angular.service.$log
|
|
*
|
|
* @description
|
|
* Write a log message
|
|
*/
|
|
log: consoleLog('log'),
|
|
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc method
|
|
* @name angular.service.$log#warn
|
|
* @methodOf angular.service.$log
|
|
*
|
|
* @description
|
|
* Write a warning message
|
|
*/
|
|
warn: consoleLog('warn'),
|
|
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc method
|
|
* @name angular.service.$log#info
|
|
* @methodOf angular.service.$log
|
|
*
|
|
* @description
|
|
* Write an information message
|
|
*/
|
|
info: consoleLog('info'),
|
|
|
|
/**
|
|
* @workInProgress
|
|
* @ngdoc method
|
|
* @name angular.service.$log#error
|
|
* @methodOf angular.service.$log
|
|
*
|
|
* @description
|
|
* Write an error message
|
|
*/
|
|
error: consoleLog('error')
|
|
};
|
|
|
|
function consoleLog(type) {
|
|
var console = $window.console || {};
|
|
var logFn = console[type] || console.log || noop;
|
|
if (logFn.apply) {
|
|
return function(){
|
|
var args = [];
|
|
forEach(arguments, function(arg){
|
|
args.push(formatError(arg));
|
|
});
|
|
return logFn.apply(console, args);
|
|
};
|
|
} else {
|
|
// we are IE, in which case there is nothing we can do
|
|
return logFn;
|
|
}
|
|
}
|
|
}, ['$window']);
|