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

contrace

v0.8.0

Published

Log to console showing line number, file and method from where the log originated. Also nicely highlight code for functions, objects, arrays etc. using an ide like feel.

Downloads

92

Readme

Contrace

Console Trace is a console package that prints out beautiful IDE-like code and nicely formatted logging. In addition it tells you info about where each log occurred and in which file.

It's often difficult to come up with the source of a log and remember removing or silencing logs. Contrace simplifies this by printing out the source line and file from where the log occurred. This is also useful when debugging and making sense of modules you didn't write yourself. You can insert memorable log messages that help you to see how the code is executing, from where and when.

I initially wrote this for use with Sails but it can be used with any package.

Installation

npm install contrace

Usage

This is an extract of the basic example file in the examples:

const chalk = require('chalk'); // not required to use lib, just use it for custom formats as below example

const contrace = require('contrace')({
  showLogType: true,
  showTimestamp: true,
});

// contrace.debug(contrace);

contrace.log('Log method is the simplest method for logging out, mainly used to output just about anything you want.');
contrace.info('Info is there to announce certain information like events and notifications \u2139');
const obj = {
  foo: 'zvinonzi',
  bar: {
    wadii: 'hapana',
  },

  fn: function quoteGhonyeti () {
    // ... do stuff in here
    let ghonyetiQuote = 'Magi wanga wagarisa uri side-chick!';
    return ghonyetiQuote;
  },

  thinga: 76234,
  mabob: '\u{1f604}',

  murayini: [
    {
      a: 'ehe',
      b: 'baz',
      c: 'caz',
    },
    2042,
    [
      x => console.log(x),
      "Life is knowing God",
    ],
    "five",
    'seven',
  ],
};
// add a circular reference to the object to show support for circular structures
obj.recursive = obj;

contrace.debug(chalk`Debug is there for trying to figure out variable contents etc. You use it temporarily to track certain values etc. Here a circular reference is introduced to show that it can handle circular structures. It tries to make sure everything still looks like js and is readable, take a look at this debug of {bold obj}:`, obj);

contrace.warn('Warning is for generally giving warning about something that you think can cause issues');
contrace.error('Error prints out errors WITH a stack trace');
contrace.fatal('Fatal prints out fatal errors WITHOUT a stack trace');

contrace.log(chalk`All these can output {cyan colored text} {green that you can format} {keyword('hotpink') using Chalk}`);
contrace.error('Any of the methods format your code the same (take note of "const", it\'s not in the source): ', fibonacci = n => n <= 1 ? 1:fibonacci(n - 1) + fibonacci(n - 2) );

After you require the package into your module, you use it like console. The above example outputs:

Example 01

Sweet!

Use with SailsJS or other similar packages/frameworks

Contrace was developed for use with SailsJS but you can use it with any app as detailed above. For use with Sails there is a hook for it; sails-hook-contrace

or you can do the following yourself in your SailsJS app's config/log.js file:

module.exports.log = {
  custom: require('contrace')({
    stackIndex: 2, // bump the stack trace index so it prints the correct filename
    methods: [ 'silly', 'verbose', 'info', 'debug', 'warn', 'error' ],
    showTimestamp: true,
    // ... other Contrace options
  }),
  inspect: false,
}

Sails will use Contrace as the default log. The above code is what the Contrace hook does for you.

Options

You pass in options as a dictionary to the initialization function ie:

const contra = require('contrace')({ /* options */ });

  • showFile {boolean}: show the file path where the log occured. Default: true
  • showMethod {boolean}: show the method where the log occured. Default: false
  • showTimestamp {boolean}: show timestamp when the log occured. Default: false
  • divider {boolean}: use divs to divide log entries. Default: false
  • stackIndex {number}: set the stack index used to extract file info from the stack. [wip] more options documentations

Author

Emmanuel Mahuni

Attributions

Tracer A powerful and customizable logging library for node.js.

Chroma-fi cli syntax highlighting: any function - any object - 176 languages

Github

https://github.com/emahuni

License

Emmanuel Mahuni (c) 2018 MIT