aboutsummaryrefslogtreecommitdiffstats
path: root/src/service/log.js
diff options
context:
space:
mode:
authorIgor Minar2011-02-15 01:12:45 -0500
committerIgor Minar2011-02-15 11:01:53 -0500
commit1777110958f76ee4be5760e36c96702223385918 (patch)
tree5aa03b246507e66877e5eac69e58e004e244d7a5 /src/service/log.js
parentd2089a16335276eecb8d81eb17332c2dff2cf1a2 (diff)
downloadangular.js-1777110958f76ee4be5760e36c96702223385918.tar.bz2
split up services into individual files
- split up services into files under src/service - split up specs into files under test/service - rewrite all specs so that they don't depend on one global forEach - get rid of obsolete code and tests in ng:switch - rename mock $log spec from "$log" to "$log mock"
Diffstat (limited to 'src/service/log.js')
-rw-r--r--src/service/log.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/src/service/log.js b/src/service/log.js
new file mode 100644
index 00000000..e1e3f2e6
--- /dev/null
+++ b/src/service/log.js
@@ -0,0 +1,92 @@
+/**
+ * @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'], true);