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

@smjs/xmlogger

v1.0.2

Published

A logging system with detailed logging info and a simple interface with markup support

Downloads

3

Readme

XMLogger

A logging system with detailed logging info and a simple interface with markup support.

Features

  • [x] Detailed logging info e.g. date-time, environment, type, and formatted messages
  • [x] A simple interface which allows you to easily add new environments and format messages using a combination of markup and composite formatting
  • [x] Event callback and log history support to access the logs programmatically
  • [x] Customizable log components

Settings

XMLogger comes with a few settings that allow you to customize the logs to your liking. You can access the settings by calling XMLogger.SETTINGS.

Toggle padding

By default, XMLogger will add padding to the log type and environment to align the logs for readability. You can toggle this by calling XMLogger.SETTINGS.togglePadding.

Toggle date-time

By default, XMLogger will add the date-time to the logs. You can toggle this by calling XMLogger.SETTINGS.toggleDateTime.

Overwriting the template

Overwrites the default template of the logs. You can set the template by calling XMLogger.SETTINGS.setTemplate. The following tags are available:

  • <type>: The type of the log.
  • <type-tags>: The tags of the log type (Should be ended with a </r>).
  • <type-padding>: The additional padding of the log type.
  • <env>: The environment of the log.
  • <env-tags>: The tags of the log environment (Should be ended with a </r>).
  • <env-padding>: The additional padding of the log environment.
  • <date-time>: The date and time of the log.
  • <date>: The date of the log.
  • <time>: The time of the log.
  • <date-time-padding> An additional space which can be ignored if date-time is disabled.
  • <message>: The message of the log.
  • </r>: Resets the tags of the log.
  • All other tags are supported.

You can reset the template by calling XMLogger.SETTINGS.resetTemplate.

Overwriting log type tags

You can overwrite the default tags of a log type by calling XMLogger.SETTINGS.setLogTypeTags.

Registering an environment

You can register an environment by calling XMLogger.SETTINGS.registerEnv. These can be used as the first parameter of a log method.

Usage

Basics

The XMLogger comes with a lot of simple logging methods. These methods are:

  • log: Logs a message on stdout.
  • info: Logs an info message on stdout.
  • warn: Logs a warning message on stdout.
  • error: Logs an error message on stderr.
  • debug: Logs a debug message on stdout.
  • trace: Logs an error message with a trace on stderr.
  • traceInfo: Logs a message with a trace on stdout.
  • clear: Clears the console and follows up with a stdout message to indicate the clear.

Some of the more complex methods are:

  • dir: Logs a detailed representation of an object on stdout.
  • table: Logs a table on stdout.
  • time: Starts a timer with a given name.
  • timeEnd: Ends a timer with a given name and logs the time it took to complete on stdout.
  • assert: Asserts a given message and either logs a success response on stdout or a failure response on stderr.

Markup

XMLogger supports its own version of markup. The markup syntax is based on XML but with </r> as the closing tag. You can find all supported markup in the escape code list.

Example:

XMLogger.SETTINGS.registerEnv("test", "sfg-green", "italic");
XMLogger.log("test", "<bold><sfg-red>I'm a bold red log</r>");