Show / Hide Table of Contents
Close
Loading …
There was an error loading this resource. Please try again later.
 Improve this Doc  View Source

$log

  1. - $logProvider
  2. - service in module ng

Overview

Simple service for logging. Default implementation safely writes the message into the browser's console (if present).

The main purpose of this service is to simplify debugging and troubleshooting.

To reveal the location of the calls to $log in the JavaScript console, you can "blackbox" the AngularJS source in your browser:

Mozilla description of blackboxing. Chrome description of blackboxing.

Note: Not all browsers support blackboxing.

The default is to log debug messages. You can use ng.$logProvider#debugEnabled to change this.

Dependencies

Methods

  • log();

    Write a log message

  • info();

    Write an information message

  • warn();

    Write a warning message

  • error();

    Write an error message

  • debug();

    Write a debug message

Example

angular.module('logExample', [])
.controller('LogController', ['$scope', '$log', function($scope, $log) {
  $scope.$log = $log;
  $scope.message = 'Hello World!';
}]);