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

slf4js

v1.1.0

Published

A simple logging facade for Node

Downloads

11

Readme

A Simple Facade for CommonJS loggers.

slf4js wraps specific logger implementations with a standard logger interface. The job of performing the logging is delegated to the specific logging implementations, slf4js mostly provides the interface and throttles the logger implementations to behave more like loggers in the Java world. In this way, you can swap out loggers easily, which you can't do if you sprinkle code for a specific logger implementation throughout your code.

However, slf4js avoids such log4j-concepts like appenders and layouts in configurations. To configure log messages, simply create a JSON object containing the format for the log messages, and the log levels for whatever you want to log. Log levels can be assigned to anything--files, "classes," functions, "packages." To use a custom logger, assign the path to logger file to the optional "logger" property. If you omit the logger property, the default ConsoleLogger will be used, sending messages to the browser console.

An example configuration file:

 {
    "logger": "logging/AlertLogger",
    "pattern": "%d{yyyy/MM/dd HH:mm:ss.SSS} [%M] %p%-5l - %m%n",
    "firstModule": "INFO",                     
    "MyGreatClass": "LOG"                      
 }
  • "firstModule" is a function being logged from INFO up.
  • "MyGreatClass" is a "class" being logged from LOG up.

Configuration properties:

  • pattern: The format for log messages
  • logger: [optional] A String path to the Logger implementation class to use for logger.
  • All other properties are key-value pairs mapping a string (which can be the name of a function, the "name" of a class, or any string that was used when the logger instance was created) to a log level. Hence, given the properties example above, slf4js.getLogger("MyGreatClass") would create a Logger with a log level of LOG, because "MyGreatClass" maps to LOG.

Pattern Symbols

The pattern symbols are the same ones used by log4j, and for the most part they have the same functions, but there are a few differences, and only the symbols below are supported:

% The CSS style for the log message. This departs from log4j and follows the Console API.

%d{date format} The date of the event. Optionally the date format follows within braces: e.g., %d{yyyy/MM/dd HH:mm:ss,SSS}. If the format is omitted, the format defaults to yyyy/MM/dd HH:mm:ss.

| Pattern | Description | | -------- | -------------- | %F | The web page where the log request was issued. | | %l | The function that generated the event | | %L | | | %m | The log message | | %M | Class, function, file, package that issued the message. The name will be the one passed to slf4js.getLogger() when the logger was created. | | %n | The platform-specific newline character | | %p | The log level of the event | | %% | The percent sign | | %-[0-9]+ | Moves the next part of the message to the right by the specified number of spaces: e.g., %p%-5l, writes the log level, followed by 5 spaces followed by the location. |