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

unified_debug

v1.1.0

Published

Unified Trace Debugging for Native Code and JavaScript

Downloads

5

Readme

Unified Debug

Unified Debug is an internal run-time debugging package for C and JavaScript. In the spirit of Fred Fish's dbug package, which is widely used in the MySQL server, this package manages "printf()-style" trace debugging of source code.

It allows a JavaScript user to set a debug output level, enabling trace messages at that level and above from both native code and JavaScript source files. Additionally, the user can also enable all messages from individual source files.

By default, messages are written to stderr. They can be redirected to any Node WritableStream, with some limitations. The current implementation does not allow redirection when messages originate from C code running in a UV worker thread.

Package Contents

  • unified_debug.js: Node.JS module which declares, documents, and implements the Unified Debug API for JavaScript.
  • example-c/unified_debug.h: header file declaring the C and C++ APIs. The API is based on preprocessor macros. If the symbol UNIFIED_DEBUG is not defined at compile-time, a stub API is substituted so that debugging is disabled entirely.
  • example-c/unified_debug.cpp: source file which implements both the C API and the C-to-JavaScript bridge.

The JavaScript API

  /* Turn debug output on 
  */
  function on();
  
  /* Turn debug output off 
  */
  function off();
  
  /* Functions for setting the output level for debug messages
  */
  function level_urgent();
  function level_notice();
  function level_info();
  function level_debug();
  function level_detail();
  
  /* Set a per-file debugging level.  
     This can be used to enable messages from particular source files.
     To enable all messages from a file, use level=5 (DETAIL).
  */
  function set_file_level(filename, level);
  

  /* Obtain a Logger for JavaScript source file.
     filename is used as a hash key, so no two files may register the same
     filename. 
     Returns a Logger.
  */
  function getLogger();

Example of the Logger API

To write messages, use getLogger() to obtain a Logger, then use the Logger to write messages.

   var unified_debug = require("unified_debug"),
       udebug = unified_debug.getLogger("ThisFile.js");

   udebug.log("a debug message");  // same as log_debug()

   udebug.log_urgent("urgent message");
   udebug.log_notice("notice message");
   udebug.log_info("info message");
   udebug.log_debug("debug message");
   udebug.log_detail("detail message");

   udebug.URGENT;      // numeric constant values for log levels
   udebug.NOTICE;
   udebug.INFO;
   udebug.DEBUG;
   udebug.DETAIL;

   udebug.is_urgent();  // returns true if current output level is >= URGENT
   udebug.is_notice();  // returns true if current output level is >= NOTICE
   udebug.is_info();    // returns true if current output level is >= INFO
   udebug.is_debug();   // returns true if current output level is >= DEBUG
   udebug.is_detail();  // returns true if current output level is == DETAIL

   udebug.set_file_level(x);  // Set our own per-file output level to x

Using Unified Debug with C/C++

  • Copy unified_debug.h and unified_debug.cpp from example-c into your own project and build system.
  • #DEFINE UNIFIED_DEBUG 1 to enable debugging at compile time.

The C and C++ APIs

In these macros message expands to any printf()-style set of arguments. The maximum allowed size for a debug message is defined in unified_debug.h; messages longer than the maximum size will be truncated.

DEBUG_PRINT(message);          // print message at DEBUG level
DEBUG_PRINT_DETAIL(message);   // print message at DETAIL level
DEBUG_PRINT_INFO(message);     // print message at INFO level
DEBUG_TRACE();                 // print filename and line number
DEBUG_ENTER();                 // print "Entering" message for function
DEBUG_LEAVE();                 // print "Leaving" message for function

// C++ only: create a stack-allocated marker that will print an "Entering"
// message from its constructor and a "Leaving" message from its destructor,
// with both messages written at debug level udeb_level
DEBUG_MARKER(udeb_level);