-
Notifications
You must be signed in to change notification settings - Fork 1
Documentation #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
IamKritika
wants to merge
4
commits into
angular-libs:master
Choose a base branch
from
IamKritika:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,11 @@ | |
```javascript | ||
bower install ng-ui-logger | ||
<script src="bower_components/ui-logger/dist/scripts/ui-logger.js"></script> | ||
|
||
Add `ui.logger` to your list of dependencies. | ||
|
||
angular.module('test',['ui.logger']) | ||
|
||
``` | ||
#### CDN | ||
|
||
|
@@ -31,6 +36,130 @@ | |
* https://rawgit.com/angular-libs/ui-logger/master/dist/scripts/ui-logger.js | ||
* https://rawgit.com/angular-libs/ui-logger/master/dist/scripts/ui-logger.min.js | ||
|
||
#### Usage | ||
|
||
`ui.logger` module can be used to obtain the log data ( logger instance name,time,url,errorMessage,stackframes) for the exceptions occurring in your angular application.The module provides multiple options to easily accomplish front-end logging for different use cases.Given below are some basic examples to get one started with using `ui.logger` module - | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. first example can be more simple .. just log some information using $log |
||
|
||
**(1)** First of all, Include `ui.logger` as a dependency to your module. Further wrap the code that can generate exception in a `try block` and you can carry out the logging process in `catch block`. The module extends the functionality of `$log` service of AngularJs and helps you write the informative log data corresponding to the exception on console using `$log` service. Use `$log` methods like debug(),info(),warn(),log(),error() depending on the severity of error. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).run(['$log', function testRun($log){ | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
$log.debug(err); | ||
} | ||
}]); | ||
``` | ||
|
||
|
||
**(2)** `$log` service should be used only if basic logging with one global default instance of logger serves your purpose.You can create a new instance of logger using `getInstance()` method of `logger` service of `ui.logger`. If you wish to give the instance a particular name, pass the same as an argument to the `getInstance()` method. If nothing is passed as an argument , an instance with 'default' as its name is created.Once you get an instance of the logger , its logging level can be set by calling the instance's `setLevel()` method.You just need to pass the desirable logging level as an argument to the `setLevel()` method. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).run(['logger', function testRun(logger){ | ||
var logger_Instance=logger.getInstance('application_logger'); //application_logger will be set as name of the logger instance | ||
logger_Instance.setLevel('debug'); | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
logger_Instance.debug(err); | ||
} | ||
}]); | ||
``` | ||
|
||
|
||
**(3)** If a configuration needs to be done for all the logger instances, you can use provider of `logger` service i.e `loggerProvider`. One can set the logging level for all the instance using the `setLevel()` method of `loggerProvider`. Acceptable values of logger levels are 'debug','info','warn','log','error'. All the levels above your choosen logger level are automatically enabled. Say if you set 'info' as your debug level , it will automatically enable 'info','warn','log','warn' levels and disable 'debug' level. So if try to call debug() method with your instance, you will not get any results. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).config(['loggerProvider', function(loggerProvider){ | ||
loggerProvider.setLevel('info'); | ||
}]); | ||
angular.module('test',['ui.logger']).run(['logger', function testRun(logger){ | ||
var logger_Instance=logger.getInstance('application_logger'); | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
logger_Instance.warn(err); | ||
// "logger_Instance.debug(err);" using this statement will not give you any output. | ||
} | ||
}]); | ||
``` | ||
|
||
|
||
|
||
**(4)** You can use,store or manipulate generated log data by defining a callback function which does the manipulations for you.Pass this callback function as an argument to the `setInterceptor()` method of the `loggerProvider`. This function will then get called everytime an exception occurs with the generated 'log data'.You can use this callback function to push the log data to a server. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).config(['loggerProvider', function(loggerProvider){ | ||
loggerProvider.setLevel('info'); | ||
loggerProvider.setInterceptor(function(data){ | ||
console.log(data); | ||
}); | ||
}]); | ||
angular.module('test',['ui.logger']).run(['logger', function testRun(logger){ | ||
var logger_Instance=logger.getInstance(); | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
logger_Instance.info(err); | ||
} | ||
}]); | ||
``` | ||
|
||
|
||
**(5)** The logger instance by default writes the log data on the console and call the callback function(if specified). If you don't want to print the log data on the console , use `disableConsoleLogging()` method of `loggerProvider`. Pass 'true' as an argument to the method | ||
to disable the console logging.If console logging is disabled only the callback function will be called everytime log data is generated for an exception. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).config(['loggerProvider', function(loggerProvider){ | ||
loggerProvider.setLevel('info'); | ||
loggerProvider.setInterceptor(function(data){ | ||
console.log(data); | ||
}); | ||
loggerProvider.disableConsoleLogging(true); | ||
}]); | ||
angular.module('test',['ui.logger']).run(['logger', function testRun(logger){ | ||
var logger_Instance=logger.getInstance(); | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
logger_Instance.info(err); | ||
} | ||
}]); | ||
``` | ||
|
||
**(6)** You can have multiple instances of logger as well in a single angular application. Or even having a global instance for entire application and local instances for different services, controllers is also possible. | ||
|
||
```javascript | ||
angular.module('test',['ui.logger']).config(['loggerProvider', function(loggerProvider){ | ||
loggerProvider.setLevel('info'); | ||
loggerProvider.setInterceptor(function(data){ | ||
console.log(data); | ||
}); | ||
loggerProvider.disableConsoleLogging(true); | ||
}]); | ||
angular.module('test',['ui.logger']).run(['logger','$rootScope', function testRun(logger,$rootScope){ | ||
$rootScope.loggerInstance=logger.getInstance('application_logger'); | ||
try{ | ||
throw new TypeError('error ...!!!'); | ||
}catch(err){ | ||
$rootScope.loggerInstance.info(err); | ||
} | ||
}]); | ||
angular.module('test',['ui.logger']) .controller('TestCtrl', function ($scope,logger,$rootScope) { | ||
var loggerControllerInstance=logger.getInstance('controller_logger'); | ||
loggerControllerInstance.info(loggerControllerInstance=== $rootScope.loggerInstance); | ||
try{ | ||
throw new TypeError(' new error ...!!!'); | ||
}catch(err){ | ||
$rootScope.loggerInstance.info(err); | ||
} | ||
|
||
}); | ||
|
||
``` | ||
|
||
|
||
[](https://github.com/angular-libs/ui-logger) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add grunt-ngdocs to package.json