npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

angular-simple-logger

v0.1.7

Published

Basic logger with level logging which can also be independent.

Downloads

35,926

Readme

angular-simple-logger (nemLogging.nemSimpleLogger)

Join the chat at https://gitter.im/nmccready/angular-simple-logger Dependencies  Dependencies  Build Status

Purpose:

To have simplified log levels where a supporting angular module's log levels are independent of the application.

Dependencies: (What can make what was simple/complicated (kinda))

How to decide which file from /dist to include in your project:

  • If using bower, include dist/angular-simple-logger.js. This is a drop-in replacement for browser.js. It is prepacked (all dependencies included). Do NOT use with Browserify or Webpack since it will break any commonJS compiler.

  • If using npm with Browserify or Webpack, include dist/index.js (CommonJS version). Do NOT use with bower.

  • *.light.js - any, will/should work with Browser, Brower and npm (with some love, but why?)

Why is it this way? Well visonmedia debug is complicated. See here . I am open to a better way so please work with me, not against me.

Bottom line: Here is what I recommend. If your using bower with a project that depends on this; bundle your vendor files seperatley via gulp, and main bowerfiles. Browserify, and Webpack can work with both bower and npm at the same time so it is up to you to make your whole app play nice (ie you can ignore stuff and not call require).

Also you can override which version (say point to*.light.js) for webpack and or browserify to use/target against.

If your lucky and all of your projects are in npm then you can eliminate bower and not worry about this.

In the end there are plenty of workarounds using the tools explained above.

Basic use:

angular.module('someApp', ['nemLogging'])
//note this can be any type of injectable angular dependency (factory, service.. etc)
.controller("someController", function ($scope, nemSimpleLogger) {
  nemSimpleLogger.doLog = true; //default is true
  nemSimpleLogger.currentLevel = nemSimpleLogger.LEVELS.debug;//defaults to error only
});  

Create a Custom Independent Loggers

(maybe 3 for one lib)

angular.module('someApp', ['nemLogging'])
//note this can be any type of injectable angular dependency (factory, service.. etc)
.service("apiLogger", function ($scope, nemSimpleLogger) {
  var logger = nemSimpleLogger.spawn();
  logger.currentLevel = logger.LEVELS.warn;
  return logger;
})
.service("businessLogicLogger", function ($scope, nemSimpleLogger) {
  var logger = nemSimpleLogger.spawn();
  logger.currentLevel = logger.LEVELS.error;
  return logger;
})
.service("terseLogger", function ($scope, nemSimpleLogger) {
  var logger = nemSimpleLogger.spawn();
  logger.currentLevel = logger.LEVELS.info;
  return logger;
});

Use your new creations!

angular.module('someApp', ['nemLogging'])
//note this can be any type of injectable angular dependency (factory, service.. etc)
.service("booksApi", function (apiLogger, $http) {
  //do something with your books
  $http.get("/ap/books").then(function(data){
    apiLogger.debug("books have come yay!");
  });
})
.controller("businessCtrl", function ($scope, businessLogicLogger, book) {
  businessLogicLogger.debug("new book");
  var b = new book();
  $scope.books = [b];
})
.controller("appCtrl", function ($rootScope, terseLogger) {
  $rootScope.$on "error", function(){
    terseLogger.error("something happened");
  }
});

Override all of $log (optional decorator)

Optionally (default is off) decorate $log to utilize log levels globally within the app.

Note this logger's currentLevel is debug! Where the order is debug, info, warn, error, log.

angular.module('someApp', ['nemLogging']))
.config(function($provide, nemSimpleLoggerProvider) {
  return $provide.decorator.apply(null, nemSimpleLoggerProvider.decorator);
})
.config(function($provide, nemSimpleLoggerProvider) {
  var logger = $provide.decorator.apply(null, nemSimpleLoggerProvider.decorator);
  //override level at config
  logger.currentLevel = logger.LEVELS.error;
  return logger;
})
.run(function($log){
  //at run time
  //override the default log level globally
  $log.currentLevel = $log.LEVELS.error;
});

Optional Debug Levels via debug

If you choose to use the full version of this library and no the light.

You can add finer grain debug levels via the visionmedia/debug API.

To use:

angular.module('someApp', ['nemLogging']))
//as a provider
.config(function(nemDebugProvider) {
  var debug = nemDebugProvider.debug;
  debug.enable("worker:*");
})
.service('LoggerLevelA', function(nemSimpleLogger) {
  //will have debug, info, warn, error, and log at disposal as before, but now debug is using the visionmedia/debug fn
  return nemSimpleLogger.spawn("worker:a");
})
.service('LoggerLevelB', function(nemSimpleLogger) {
  return nemSimpleLogger.spawn("worker:b");
})
//heck maybe you don't want all of the logger interface only want debug.. then
.service('JustDebugC',function(nemDebug) {
  return nemDebug("worker:c");
})
.run(function(nemDebug){
  //enable another debug level
  nemDebug.enable("coolStuff:*");
});

API

Underneath it all it is still calling $log so calling the logger for logging itself is the same.

  • LEVELS: available are debug, info, warn, error, log

  • doLog (boolean) - deaults to true. If set to false all logging for that logger instance is disabled.

  • currentLevel (number) - defaults to error: 4 corresponds to the current log level provided by LEVELS.

  • spawn - create a independent logger accepts a logger or a string (see visionmedia debug notes above). Defaults to $log