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

jquery-logger

v0.4.3

Published

A simple but powerful logging plugin for jQuery with namespaces.

Downloads

10

Readme

jQuery.Logger

A simple but powerful logging plugin for jQuery with namespaces.

Examples

Create a (global) logger and log something:
var logger = $.Logger();

/**
 * simply log something
 */
logger.debug("my first log");
// => [2015-03-16 14:38:55.817] DEBUG - global - my first log

/*
 * disable, log and enable again
 */
logger.disable();
logger.debug("another log");
// nothing happens
logger.enable();

/**
 * set the level
 */
logger.level("info");
logger.debug("foo bar");
// nothing happens
logger.info("but this time");
// => [2015-03-16 14:38:56.193] INFO - global - but this time


/**
 * show name and namespace
 */
logger.name();
// => "global"
logger.namespace();
// => "global";
Create a child logger:
var myLogger = $.Logger("foo");

/**
 * simply log something
 */
myLogger.info("foo's first log");
// => [2015-03-16 14:38:56.602] INFO - foo - foo's first log


/**
 * show parentage using the (global) logger defined above
 */
myLogger.parent() == logger;
// => true

// logger.child("foo") == myLogger;
// => true
Configuration
// configure $.Logger _before_ you create any logger instance
// (these are the default options)
$.Logger({
  // name of the global namespace
  global: "global",

  // delimitter that seperates namespaces
  delimitter: ".",

  // use appropriate console logging methods instead of the standard log method,
  useConsoleMethods: true,

  // show namespaces in logs
  showNamespace: true,

  // show timestamps in logs
  showTimestamp: true,

  // experimental
  // show file name and line number of the origin
  showOrigin: true,
  
  // experimental
  // cut query string from origin
  cutQuery: true
});

API

  • $.Logger([namespace|options])

    If options are passed, the logger options are extended and the $.Logger object is returned. If a namespace is passed, a new logger instance with that namespace is created and returned. When no argument is given, the global logger is returned. Logger parentage is built automatically. A namespace consists of a number of logger names seperated by a delimitter. Example: namespace "foo.bar" => logger "global" -> logger "foo" -> logger "bar". Note that the global namespace ("global" in this example) is always prepended.

  • namespace()

    Returns the namespace.

  • name()

    Returns the name.

  • parent()

    Returns the parent logger, or null when invoked on the global logger.

  • children()

    Return all child loggers mapped to their names.

  • child(name)

    Return a child logger given by name.

  • enabled()

    Returns the state of the logger.

  • enable()

    Enable the logger and all its child loggers.

  • disable()

    Disable this and all its child loggers.

  • level([level])

    When level is given, the log level is set to that value. Possible values: "all", "debug", "info", "warning", "error", "fatal". When no argument is passed, the current log level is returned.

  • levels()

    Returns all valid log levels mapped to their numerical representation.

  • options()

    Returns the current options.

  • log(level, ...)

    Log arguments with a given level.

  • all | debug | info | warning | error | fatal(...)

    Shorthands that wrap around log for specific levels.

  • originOffset([offset]), experimental

    The context that invoked a log (the origin) is determined by parsing the stack trace of a newly created error instance. The first few lines in that stack describe the internal invocation queue of this plugin. In the current implementation, the 5th line is the one that caused the actual log. However, in some cases (e.g. when logging a deprecation warning) it is useful to see the origin of an earlier invocation in the queue. This can be achieved by setting originOffset to a numerical value that is added to the stack line index (5th line -> 4) for the next log. After that, the offset is reset to 0 again.

    When offset is given, the origin offset is set to that value. When no argument is passed, the current origin offset is returned.

Development

License

MIT.

Authors

Marcel R. (riga)