Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
ag-logger
Advanced tools
Readme
An AngularJS logger with configurable log levels. All logging messages are delegated to Angular's $log service.
We use bower for dependency management. Install ag-logger
into your project by running:
$ bower install ag-logger
After installing ag-logger
, load the script file in your application:
<script type="text/javascript" src="bower_components/ag-logger/release/ag-logger.js"></script>
Then, add the ag-logger
module as a dependency to your application:
var appModule = angular.module('app', ['ag-logger']);
There are five logging levels available:
ERROR > WARN > INFO > LOG > DEBUG
When a logger is set to a particular level, it will only log messages at that are logged at a level greater than or equal to the level it's configured at. For instance, if the logger is set to WARN
level, it will log ERROR
and WARN
messages. If the logger is set to ERROR
level, it will only log ERROR
messages.
Logging can be configured as a provider or a service (or a combination of both).
angular.module('app', ['ag-logger']).
config(function(agLoggerProvider) {
// sets the logger to ERROR level logging, during app configuration
agLoggerProvider.setLogLevel(agLoggerProvider.LOG_LEVELS.ERROR);
});
angular.module('app', ['ag-logger']).
controller('AppCtrl', AppCtrl);
function AppCtrl(agLogger) {
initLogging();
function initLogging() {
// sets the logger to WARNING level logging, within the application code
agLogger.setLogLevel(agLogger.LOG_LEVELS.WARN);
}
}
Messages can be logged via the agLogger service.
Note: By default, all logging levels are enabled.
angular.module('app', ['ag-logger']).
controller('AppCtrl', AppCtrl);
function AppCtrl(agLogger) {
testLogging();
function testLogging() {
// sets the logger to WARNING level logging, within the application code
logger.setLogLevel(logger.LOG_LEVELS.WARN);
logger.error('Error message'); // will be displayed in the console.
logger.warn('Warning message'); // will be displayed in the console.
logger.info('Info message'); // will not be displayed in the console.
logger.log('Log message'); // will not be displayed in the console.
logger.debug('Debug message'); // will not be displayed in the console.
}
}
Note: By default, all logging levels are enabled.
agLoggerProvider
property LOG_LEVELS - [string]
Returns a dictionary of all supported logging levels.
function configFn(agLoggerProvider) {
var LOG_LEVELS = agLoggerProvider.LOG_LEVELS;
console.log(LOG_LEVELS.OFF); // off
console.log(LOG_LEVELS.ERROR); // error
console.log(LOG_LEVELS.WARN); // warn
console.log(LOG_LEVELS.INFO); // info
console.log(LOG_LEVELS.LOG); // log
console.log(LOG_LEVELS.DEBUG); // debug
console.log(LOG_LEVELS.ALL); // all
}
Note: LOG_LEVELS.OFF
and LOG_LEVELS.ALL
don't have corresponding log functions, they're just filter levels.
void
setLogLevel(logLevelName)
Sets the log level.
function configFn(agLoggerProvider) {
// these two statements are functionally equivalent
agLoggerProvider.setLogLevel(agLoggerProvider.LOG_LEVELS.WARN);
agLoggerProvider.setLogLevel('warn');
}
string
getLogLevel()
Gets the current log level.
void
enableAll()
Enables the logging of all messages.
function configFn(agLoggerProvider) {
// these three statements are functionally equivalent
agLoggerProvider.setLogLevel(agLoggerProvider.LOG_LEVELS.ALL);
agLoggerProvider.setLogLevel('all');
agLoggerProvider.enableAll();
}
void
disableAll()
Disables the logging of all messages.
function configFn(agLoggerProvider) {
// these three statements are functionally equivalent
agLoggerProvider.setLogLevel(agLoggerProvider.LOG_LEVELS.OFF);
agLoggerProvider.setLogLevel('off');
agLoggerProvider.disableAll();
}
agLogger
property LOG_LEVELS - [string]
Returns a dictionary of all supported logging levels.
function AppCtrl(agLogger) {
var LOG_LEVELS = agLogger.LOG_LEVELS;
console.log(LOG_LEVELS.OFF); // off
console.log(LOG_LEVELS.ERROR); // error
console.log(LOG_LEVELS.WARN); // warn
console.log(LOG_LEVELS.INFO); // info
console.log(LOG_LEVELS.LOG); // log
console.log(LOG_LEVELS.DEBUG); // debug
console.log(LOG_LEVELS.ALL); // all
}
void
setLogLevel(logLevelName)
Sets the log level.
function AppCtrl(agLogger) {
// these two statements are functionally equivalent
agLogger.setLogLevel(agLogger.LOG_LEVELS.WARN);
agLogger.setLogLevel('warn');
}
string
getLogLevel()
Gets the current log level.
void
enableAll()
Enables the printing of all log levels.
function config(agLogger) {
// these three statements are functionally equivalent
agLogger.setLogLevel(agLogger.LOG_LEVELS.ALL);
agLogger.setLogLevel('all');
agLogger.enableAll();
}
void
disableAll()
Disables the printing of all log levels.
function config(agLogger) {
// these three statements are functionally equivalent
agLogger.setLogLevel(agLogger.LOG_LEVELS.OFF);
agLogger.setLogLevel('off');
agLogger.disableAll();
}
boolean
willLog(logLevel)
Returns a boolean representing whether the logger will log (print) messages at the provided level (depending on what the logger's current level is set at).
Messages will only be logged if they are logged at a level equal to or greater than the logger's configured level (see Usage).
void
error(message)
Logs the provided message at the error
level.
void
warn(message)
Logs the provided message at the warn
level.
void
info(message)
Logs the provided message at the info
level.
void
log(message)
Logs the provided message at the log
level.
void
debug(message)
Logs the provided message at the debug
level.
FAQs
An AngularJS logger with configurable log levels.
The npm package ag-logger receives a total of 5 weekly downloads. As such, ag-logger popularity was classified as not popular.
We found that ag-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.