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

simply-log

v0.2.6

Published

An attempt at a extremely simple logger, which is easy to extend with code and not silly config.

Downloads

8

Readme

SimplyLog


SimplyLog is a project meant to bring more flexible and controllable logging into javascript. The primary goals are extensibility, simplicity, and compatibility. omething that allows developers to quickly turn logging on and off as they are debugging a site, and even control the amount of logging that gets output. In addition to allowing a developer or a team to attach more information to the debugging. And for teams allowing a standard logging style to be setup for their projects.

And lastly the syntax and API is intended to be as clear and easy to use as possible.

Usage

Creating a new logger

// Create a new console logger named example logger
//   A console logger is a logger with the console appender already
//   attached to it
var log = SimplyLog.consoleLogger('exampleLogger');

// Change the logging level from its default to TRACE level
log.setLevel(SimplyLog.TRACE);

// Send a message to the appender (which currently is a console appender)
log.trace('hello there', '!');
// The above line will result in the output exampleLogger:trace -> hello there!

// Changes this log to only output error messages
log.setLevel(SimplyLog.ERROR);

// This line won't actually output anything because the log level is set above it
log.debug('hello user');

Usage in Node

// Add the logger
var logger = require('simply-log');

var myLog = logger.consoleLogger('myLog');
myLog.setLevel(logger.TRACE);

Another Notes

SimplyLog keeps track of all loggers you create within it, this means you can reuse loggers in different parts of your app as long as SimplyLog is at the root. For instance var logger = require('simply-log')

logger.getLogger('stuffLogger').setLevel(logger.TRACE);

var doStuff = function() {
	// Do some stuff
	logger.consoleLogger('stuffLogger').trace('Hello World')
}

var adjustLogging = function(level) {
	// Adjust the logger used in the 'doStuff' function
	logger.getLogger('stuffLogger').setLevel(level);
}

// Will print hello world
doStuff();

adjustLogging(logger.INFO)
// Will not print hello world
doStuff();

API Crash Course

Logging a message

Messages are sent to the log appenders by calling the appropriate console log level method. The method to call is always the level you want to send in all lower case. As of now the current levels are error, info, warn, debug, trace. Any number of arguments can be passed to these methods For instance the following is legal

SimplyLog.error('Lorem', 'ipsom', $(window));

Logging levels

SimplyLog currently supports the following logging levels in order of highest level to lowest level, setting the level a level down will also send all log levels above it to the appender.

  • SimplyLog.OFF Highest level, will disable all output
  • SimplyLog.ERROR Intended for error level logging
  • SimplyLog.INFO General information level
  • SimplyLog.WARN Display api level warnings
  • SimplyLog.DEBUG Display debug level messages
  • SimplyLog.TRACE Trace level, most verbose level of logging

Default level

You can setup SimplyLog to automatically set the logging level for all logs built by it by calling SimplyLog.setDefaultLevel(SimplyLog.{level});

Appenders

Appenders are a way of allowing the log system to be extended, anything you can code can be called as an appender. Any number of appenders can be added to a logger to allow Tutorial and more complex appenders to come, to get started now take a look at the defaultConsoleAppender in src/js/SimplyLog.js.