/angular-env-logger

AngularJS module (angular-env-logger) with browser console statements restriction based on the application environment.

Primary LanguageJavaScriptMIT LicenseMIT

angular-env-logger is an angularjs module with logger restriction based on the application environment.

Author: M. Rahul Reddy (RahulReddy)

Usage

  1. Install via either npm or downloaded files:

    1. bower install angular-env-logger
    2. download angular-env-logger.zip
  2. Include dependencies in your HTML.

    1. When using bower:
    <script src="bower_components/angular-env-logger/dist/angular-env-logger.min.js"></script>
    1. when using downloaded files
    <script src="angular-env-logger.min.js"></script>
  3. Add env_logger to your application's module dependencies

    angular.module('app', ['env_logger']);
  4. 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
    
        });

Note

Use logger.log/warn/error instead of console.log/warn/error

Credits

Alexander Jangam (Alex)

License

MIT