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

cat-log4angular

v1.2.0

Published

[![Build Status](https://travis-ci.org/Catalysts/cat-log4angular.svg)](https://travis-ci.org/Catalysts/cat-log4angular)

Downloads

16

Readme

Build Status

cat-log4angular

A simple configurable logger enhancing angulars $log service. It provides support for multiple log levels ('debug', 'info', 'warn', 'error') as well as named (hierarchical) loggers (eg. cc.catalysts.LogService). The set log level will propagate to all child loggers if they don't explicitly define their own level. In additional an 'appender' concept is implemented which allows for arbitrary implementations of how the log message is processed. Two implementations of such appenders are included within cat-log4angular:

  • a simple console appender
  • a http appender (interval based log post requests to a configurable url)

Note: By default no appender is registered, this means that calling any log method will result in a NOOP by default.

Usage

First you need to get the necessary js file, the easiest way to do so is by using bower and just installing 'cat-log4angular'. (bower-repo) Afterwards just add the the js file to your html page and make your angular app/module depend on cat.service.log. Next you have to setup all appenders you want to use. After that you are good to go. Just call $log.Logger('someLoggerName') to retrieve a named logger instance, and log via the appropriate functions.

Examples

Some code snippets as short reference of the main features. For a more complete usage example please have a look at the examples directory.

Setting the ROOT log level during the configuration phase

angular.module('myApp', ['cat.service.log'])
    .config(function(catLogServiceProvider, ROOT_LOGGER_NAME) {
        // Changing the log level of the root logger from the default 'info' to 'warn'
        catLogServiceProvider.configure(ROOT_LOGGER_NAME, 'warn');
    });

Setting the ROOT log level during the run phase

angular.module('myApp', ['cat.service.log'])
    .run(function($log) {
        // Note that $log was decorated and now references to the root logger
        $log.setLevel('error');
    });

Registering the console appender

angular.module('myApp', ['cat.service.log'])
    .config(function(catLogServiceProvider, CONSOLE_APPENDER) {
        // Register the console appender
        catLogServiceProvider.appender(CONSOLE_APPENDER);
    });

Using the catHttpLogAppender

angular.module('myApp', ['cat.service.log'])
    .config(function (catHttpLogAppenderProvider) {
        catHttpLogAppenderProvider
            // set the post url
            .postUrl('/logs/upload')
            // set the appender to post all logs to the configured url every 3 seconds
            .interval(3);
    })
    .run(function (catLogService, catHttpLogAppender) {
        // register the catHttpLogAppender
        catLogService.appender(catHttpLogAppender);
    });

Writing a custom appender

angular.module('myApp', ['cat.service.log'])
    .run(function ($rootScope, catLogService) {
        catLogServiceProvider.appender({
            report : function(level, group, message) {
                // trigger a 'log' event for every logged message
                $rootScope.$broadcast('log', {level: level, group: group, message: message, timestamp: new Date()});
            }
        });
    });

License

Published under 'The MIT License (MIT)' For details see LICENSE