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

trace-log

v1.1.1

Published

Provides logging with filename/method name helpers

Downloads

9

Readme

trace-log

Terrible name, but hey, it's hard to come up with a good name for a logging library. My motivation for writing this was to create a logging class that would wrap my calls to stdout or stderr and provide a context to the log message. e.g. rather than;

// File testFile.js
var logger = require('debug')('MyLibrary');

var testFunction = function(){
	logger('doing some stuff');
};

Which would generated the following debug output;

MyLibrary doing some stuff +0ms

I wanted the logging framework to provide more context to the log output, so you could work out which file or function a log entry was coming from. I wanted a log output more like this;

MyLibrary testFile.js>testFunction() [DEBUG]: doing some stuff +0ms

Getting Started

The code is available from github. You can clone it from there or you can install it with npm if using it as a dependency of something you're building.

Prerequisities

You will need to have nodejs and npm installed to use this library.

Installing

If cloning the repository manually you will need to run npm install in the trace-log repository directory, this will download and install all the dependent libraries in the node_modules directory.

If installing as a dependency of something you're building run the following command in your project's route directory; that in which your package.json exists.

npm install --save trace-log

Running the tests

There are some mocha tests included. To run these; npm run test

This library also uses the 'debug' library and no logging will be made unless the environment variable DEBUG is set so that output will be made. For the purpose of running the tests you can enable all debug; export DEBUG=*

Usage

To use in your code;

// File testFile.js
#require the library
var Logger = require('trace-log');

#Set the libary name and global log level
Logger.setGlobalDefaults("people-modeller", "TRACE");

#Create a logger
var logger = new Logger('Person.js');
logger.trace("Loading module");
var Person = function(name){
	var personLogger = logger.getSubModuleLogger('Person');
	personLogger.trace("name is %s", name);
};

module.export = Person;

Log Levels

The log level specified will limit the logging output to those log message made at that log level or more important. Valid log levels, ordered by importance, most important first;

  • FATAL
  • ERROR
  • WARN
  • INFO
  • DEBUG
  • TRACE

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Thanks to sunny days.