angular-env-logger is an angularjs module with logger restriction based on the application environment.
Author: M. Rahul Reddy (RahulReddy)
-
Install via either npm or downloaded files:
bower install angular-env-logger
- download angular-env-logger.zip
-
Include dependencies in your HTML.
- When using bower:
<script src="bower_components/angular-env-logger/dist/angular-env-logger.min.js"></script>
- when using downloaded files
<script src="angular-env-logger.min.js"></script>
-
Add
env_logger
to your application's module dependenciesangular.module('app', ['env_logger']);
-
Use the factory
logger
angular.module('app') .controller('appController', function($scope, logger){ logger.configEnv({ //initialize it once for your application local : "localhost", // key : window.location.hostname dev : "dev.yourHost", // key : window.location.hostname prod : "prod.yourHost" // key : window.location.hostname }) logger.enableLogger("local","dev"); //console statements are enabled for given keys. //In Host http://localhost:8080/your-path, this will be printed logger.log("to be seen in local"); //use logger.log/warn/error instead of console.log/warn/error //In Host http://dev.yourHost/your-path, this will be printed logger.log("to be seen in dev"); //use logger.log/warn/error instead of console.log/warn/error //In Host http://prod.yourHost/your-path, this will NOT be printed logger.log("to be seen in prod"); //use logger.log/warn/error instead of console.log/warn/error });
Use logger.log/warn/error instead of console.log/warn/error
Alexander Jangam (Alex)
MIT