Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:lwhiteley/AngularLogExtender
Browse files Browse the repository at this point in the history
* 'develop' of github.com:lwhiteley/AngularLogExtender:
  update submodule
  snapshot release
  release 0.0.4
  Release v0.0.4
  Update Documentation
  Update Documentation
  Update Documentation
  Update Documentation
  Update Documentation
  Remove constant reference
  Shorten module name to log.ex.uo
  Replace plain text with constant references
  Update documentation to give a more accurate description of the module
  Update Documentation
  Update Documentation to showcase added configurations
  Update Documentation to showcase constants
  Update Documentation and add logMethod constant for external use
  • Loading branch information
ferronrsmith committed Jan 11, 2014
2 parents 1a714bb + 80718b1 commit 7bc6f5c
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 38 deletions.
24 changes: 23 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@

0.0.3-sha.f6846fb / 2014-01-07
0.0.3-sha.665adf9 / 2014-01-10
==================

* Update Documentation
* Update Documentation
* Update Documentation
* Update Documentation
* Update Documentation
* Remove constant reference
* Shorten module name to log.ex.uo
* Replace plain text with constant references
* Update documentation to give a more accurate description of the module
* Update Documentation
* Update Documentation to showcase added configurations
* Update Documentation to showcase constants
* Update Documentation and add logMethod constant for external use
* updated config for lcov
* more context
* new dist
* remove readme dup
* fixed readme issue
* updated documentation
* update submodule
* update submodule
* generated changelog generated distributed version
* added the functionality for supporting toggling of methods
* remove allowedMethods
* remove allowMethods override
Expand Down
68 changes: 42 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,73 +3,81 @@ AngularLogExtender

This is an extension of the Angular $log functionality. It uses the native $decorator to push the $log pass its capabilities and provide new functionality such as configuring the $log for different environments such as production and development.

###Notes

The prefered file to use is the log-ex-unobtrusive.js file. With this file you can just include the module to your AngularJs Application and it does all the work. Methods native to the log extender are not publicly available in your AngularJs Application so this extension can be used as a standalone plugin.

To view the blog this module was extended from and inspired by, go to
http://solutionoptimist.com/2013/10/07/enhance-angularjs-logging-using-decorators/

[![Build Status](https://travis-ci.org/ferronrsmith/AngularLogExtender.png?branch=master)](https://travis-ci.org/ferronrsmith/AngularLogExtender)
[![Coverage Status](https://coveralls.io/repos/ferronrsmith/AngularLogExtender/badge.png)](https://coveralls.io/r/ferronrsmith/AngularLogExtender)

###Notes

The prefered file to use is the log-ex-unobtrusive.js file. You can include the module to your AngularJs Application and it does all the work immediately. Methods native to the log extender are not publicly available in your AngularJs Application so this extension can be used as a standalone plugin. Advanced configurations can be done to make the $log service fit your personal development style.

Feel Free to make your own contributions to this module so we can make it better :)

###Configurations

1. Set $log Instance Class Name
2. Enable/Disable Logging Globally
3. Enable/Disable Logging at a Component Level
4. Customize the Log Prefix
5. Enable/Disable Specific $log methods throughout the app

##How to Use

######Step 1. Add Module Dependency
```javascript
var app = angular.module('myAngularApp', ['log.extension.uo']);
var app = angular.module('myAngularApp', ['log.ex.uo']);
```

######Step 2. Enable Debugging Globally to see logs

Add the logExProvider dependency to your AngularJS app to configure logging. Pass true to the logExProvider.enableLogging(boolean) function as a parameter to enable logging. This is set to false by default to disable logging in a production environment. The Best practice is to keep this flag set to false in the master version of the code base, given that some version control system is being used. See eg. below.
Add the logExProvider dependency to your AngularJS app to configure logging. Pass true to the `logExProvider.enableLogging(boolean)` function as a parameter to enable logging. This is set to false by default to disable logging in a production environment. The Best practice is to keep this flag set to false in the master version of the code base, given that some version control system is being used. See eg. below.

```javascript
app.config([ 'logExProvider', function(logExProvider) {
app.config(['logExProvider', function(logExProvider) {
logExProvider.enableLogging(true);
}]);
```
######Step 3. Print Log from any component (Controller, Directive etc..)

```javascript
app.controller('CoreController', ['$scope','$log', function($scope, $log) {
$log.log("Simple Log Extender Example");
}]);
```
######Step 4. Load the web page and look in the Developer Console
Sample Output
```
Dec-08-2013-12:50:52PM >> CONFIG: LOGGING ENABLED GLOBALLY
Dec-08-2013-12:50:52PM >> Simple Log Extender Example
```
##Advanced Configurations

######Step 3. Restrict Logging to specific methods
######1. Restrict Logging to specific methods

Add the logExProvider dependency to your AngularJS app to configure logging. Pass an array with the methods that should be enabled to the `restrictLogMethods` method. `$warn, $debug, $error` messages won't be displayed in the console

```javascript
app.config([ 'logExProvider', function(logExProvider) {
app.config(['logExProvider', function(logExProvider) {
logExProvider.restrictLogMethods(['log', 'info']);
}]);
```

######Step 4. Override Log Prefix - Log Prefix Formatter
######2. Override Log Prefix - Log Prefix Formatter

Add the logExProvider dependency to your AngularJS app to configure logging. Pass a custom function that accepts a `className` param to the `overrideLogPrefix` method

```javascript
app.controller('CoreController', ['$scope','$log', function($scope, $log) {
app.config(['logExProvider', function(logExProvider) {
logExProvider.overrideLogPrefix(function (className) {
var $injector = angular.injector([ 'ng' ]);
var $filter = $injector.get( '$filter' );
var formatMessage = "";
var separator = " >> ";
var format = "MMMM-dd-yyyy-h:mm:ssa";
var now = $filter('date')(new Date(), format);
return "" + now + (className === null ? "" : "::" + className) + separator;
});
}]);
```

######Step 5. Load the web page and look in the Developer Console
Sample Output
```
Dec-08-2013-12:50:52PM >> CONFIG: LOGGING ENABLED GLOBALLY
Dec-08-2013-12:50:52PM >> Simple Log Extender Example
```

##Advanced Use Cases
###Use Case 1: Set Component Class Name
This example can be used to know which component (controller, directive etc.) $log instances are being pushed from to the console. The new instance must be re-assigned to the $log object to take effect. This Advanced use case is always recommended to get more information from your application logs.
Expand Down Expand Up @@ -144,6 +152,18 @@ app.controller('CoreController', ['$scope','$log', function($scope, $log) {
Dec-08-2013-1:20:56PM >> [OVERRIDE] LOGGING ENABLED - $log enabled for this instance
Dec-08-2013-1:20:56PM >> Advanced Log Extender Example: Use Case 3: Eg 2
```

###Use Case 4: Configure only specific methods to print to the console
This scenario is helpful when you want to only allow specific types of log messages to be sent to the console in a
particular environment. For eg. Say we want to only allow error logs to be seen in production, then the following configuration will
produce this result.
#####Eg 1.
```javascript
app.config(['logExProvider', function(logExProvider) {
logExProvider.enableLogging(true);
logExProvider.restrictLogMethods(['error']);
}]);
```
####NB.
These examples only show the use of $log.log(), however, the other $log methods were left in tact and can be used as well.

Expand All @@ -158,9 +178,5 @@ These are:

1. More configurations are being considered such as disabling timestamp to offer more customizations for a developers needs
2. remove the need to reassign $log instance
3. Log function level overriding


[![Build Status](https://travis-ci.org/ferronrsmith/AngularLogExtender.png?branch=master)](https://travis-ci.org/ferronrsmith/AngularLogExtender)

[![Coverage Status](https://coveralls.io/repos/ferronrsmith/AngularLogExtender/badge.png)](https://coveralls.io/r/ferronrsmith/AngularLogExtender)
18 changes: 14 additions & 4 deletions dist/log-ex-unobtrusive.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Log Unobtrusive Extension v0.0.3-sha.2d1589e
* Log Unobtrusive Extension v0.0.4-sha.d4c9720
*
* Used within AngularJS to enhance functionality within the AngularJS $log service.
*
Expand All @@ -15,7 +15,7 @@
* - Has global and feature level activation/disabling for $log
* - Created and tested with AngularJS v.1.2.3
*/
angular.module("log.extension.uo", []).provider('logEx', ['$provide',
angular.module("log.ex.uo", []).provider('logEx', ['$provide',
function($provide) {

// Creates an injector function that can be used for retrieving services as well as for dependency injection
Expand All @@ -26,8 +26,17 @@ angular.module("log.extension.uo", []).provider('logEx', ['$provide',

var enableGlobally = false;

// methods as object [constant]
var lm = {
log: 'log',
info: 'info',
warn: 'warn',
error: 'error',
debug: 'debug'
};
// default log methods available
var defaultLogMethods = ['log', 'info', 'warn', 'debug', 'error', 'getInstance'];
var defaultLogMethods = [lm.log, lm.info, lm.warn, lm.debug, lm.error, 'getInstance'];

/**
* publicly allowed methods for the extended $log object.
* this give the developer the option of using special features
Expand Down Expand Up @@ -350,7 +359,7 @@ angular.module("log.extension.uo", []).provider('logEx', ['$provide',
this.$get = function() {
return {
name: 'Log Unobtrusive Extension',
version: '0.0.3-sha.2d1589e',
version: '0.0.4-sha.d4c9720',
enableLogging: enableLogging,
restrictLogMethods: restrictLogMethods,
overrideLogPrefix: overrideLogPrefix
Expand All @@ -372,5 +381,6 @@ angular.module("log.extension.uo", []).provider('logEx', ['$provide',
* Configure which log functions can be exposed at runtime
*/
this.restrictLogMethods = restrictLogMethods;

}
]);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"type": "MIT",
"url": "https://github.com/lwhiteley/AngularLogExtender/blob/master/LICENSE"
},
"version": "0.0.3-snapshot",
"version": "0.0.4-snapshot",
"engine": "node >= 0.10.0",
"devDependencies": {
"karma": "~0.10.8",
Expand Down
2 changes: 1 addition & 1 deletion sample_app
Submodule sample_app updated 1 files
+1 −1 app/js/app.js
11 changes: 10 additions & 1 deletion src/declarations.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@

var enableGlobally = false;

// methods as object [constant]
var lm = {
log: 'log',
info: 'info',
warn: 'warn',
error: 'error',
debug: 'debug'
};
// default log methods available
var defaultLogMethods = ['log', 'info', 'warn', 'debug', 'error', 'getInstance'];
var defaultLogMethods = [lm.log, lm.info, lm.warn, lm.debug, lm.error, 'getInstance'];

/**
* publicly allowed methods for the extended $log object.
* this give the developer the option of using special features
Expand Down
2 changes: 1 addition & 1 deletion src/module.prefix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
angular.module("log.extension.uo", [ ]).provider('logEx', ['$provide', function ($provide) {
angular.module("log.ex.uo", [ ]).provider('logEx', ['$provide', function ($provide) {
7 changes: 4 additions & 3 deletions src/providerFunc/provider.suffix
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
return {
name: '%APP_NAME%',
version: '%VERSION%',
enableLogging:enableLogging,
restrictLogMethods:restrictLogMethods,
overrideLogPrefix:overrideLogPrefix
enableLogging: enableLogging,
restrictLogMethods: restrictLogMethods,
overrideLogPrefix: overrideLogPrefix
};
};

Expand All @@ -27,4 +27,5 @@
* Configure which log functions can be exposed at runtime
*/
this.restrictLogMethods = restrictLogMethods;

}]);

0 comments on commit 7bc6f5c

Please sign in to comment.