Giter Site home page Giter Site logo

debug-js / debug Goto Github PK

View Code? Open in Web Editor NEW
11.0K 11.0K 901.0 410 KB

A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers

License: MIT License

JavaScript 100.00%
browser debug debugging javascript logging node node-js

debug's People

Contributors

accaliadeelementia avatar anaisbetts avatar arcanis avatar dmarcelino avatar dougwilson avatar escwald avatar gscottolson avatar mblarsen avatar miaulightouch avatar mooyoul avatar msasad avatar musikov avatar mylesborins avatar nopnop avatar ossdev07 avatar outsideris avatar panuhorsmalahti avatar piamancini avatar profiprog avatar qix- avatar sdaitzman avatar slaskis avatar thebigredgeek avatar timoxley avatar tj avatar tootallnate avatar vkarpov15 avatar vpulim avatar yamikuronue avatar zhuangya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

debug's Issues

use console.group

console.group.

i have many debugs for almost every component in my app, it will be awesome if every debug type would be a group.

let me know what you think, so i can PR.

Lazy string arguments

I was going to open an issue to support lazy string arguments.

The idea is things like debug(JSON.stringify(largeobject)) are executed (due to call-by-value) even if the logger is disabled. I ended up writing a small library to support lazy string arguments http://github.com/jb55/lazy-string for anyone else who is interested.

Consider a v1.0.0 release

So there's been a lot of cleanup, refactoring, and changes lately. We went from like 30+ issues on Friday to just 2 now. So I'm pretty happy with that. On top of that we now have:

  • Common logic shared between Node.js and web browsers, with just the different parts abstracted out.
  • %o formatting consistently in web browsers and node (maps to util.inspect())
  • %j formatting consistently in web browsers and node (web browsers don't JSONify %j by default, but node does)
  • Web inspector and Firebug client-side colors!!!
  • Global scope "diff" timestamping. It's easier to disable noisy scopes via command line if you want to get more granular, than not being able to at all.

Probably some other goodies that I'm forgetting, but I figure this is good enough for a v1.0.0 release due to the breaking changes.

@visionmedia Thoughts?

No Git repository published in npm

While you're publishing packages to npm, can you please push a repository URL too? Most package publishers provide a canonical Git URL where updates may be retrieved, which helps people and software tools discover the Git repository. If you're using the package.json file in the repository, you could add:

"repository" :
  { "type" : "git"
  , "url" : "git://github.com/visionmedia/debug.git"
  }

Then pushing these changes to npm would be awesome.

publish newer version to NPM

the NPM version is out of date + needs a npm publish, would be nice to have the JSONP security fix on the NPM published version

ANSI escape codes bug

It is possible that I am just looking at this wrong but I'm 90% sure this code is wrong.

fmt = '  \u001b[9' + c + 'm' + name + ' '
  + '\u001b[3' + c + 'm\u001b[90m'
  + fmt + '\u001b[3' + c + 'm'
  + ' +' + humanize(ms) + '\u001b[0m';

What this is doing is making the output pretty colours.

c holds the number corresponding to a colour (https://en.wikipedia.org/wiki/ANSI_escape_code#Colors)

Since the 9c codes aren't actually standard (I haven't come across something which doesn't implement them though) it is understandable to include the equivalent 3c code before the 9c one as if the 'Intense' colour spec hasn't been implemented then it will display the 'non-intense' version instead. This is what I think the above code is meant to be doing but it isn't since the 3c escape code is in the wrong place (if a system didn't implement the intense spec then the message would be colored and the name would not be which is the opposite of what it should be).

Another improvement would be to use hexadecimal e.g. \u001b[36m -> \x1b[36m as it is smaller.

This is my suggestion:

fmt = '  \x1b[3' + c + 'm\x1b[9' + c + 'm' + name + ' '
  + '\x1b[30m\x1b[90m'
  + fmt + '\x1b[3' + c + 'm'
  + ' +' + humanize(ms) + '\x1b[0m';

I wanted to get some feedback before submitting a pull request.

Excessive RegExp in split

(process.env.DEBUG || '')
  .split(/[\s,]+/)

Usually use like DEBUG=worker,http node app.js, so I really can not understand the '\s' there.

Microseconds in debug information

Sometimes (for example while develop middleware for connect/express) I want to see microseconds in debug.
Maybe you can check that microtime module is installed and print microseconds?

Manually handle/redirect output

It could be nice to be able to handle output manually instead of it going to stderr all the time. Example:

var debug = require('debug');

// Manually handle debug output. After this there are no output to stderr.
debug.handleOutput(function(message) {
  console.log(message.name, message.time, message.text);
});

Print error stack when handed an error

Feature request: When calling debug with an err as the first and only parameter, print a stack trace from it.

I would be happy to provide PR if you think this is a good idea.

Parse process.env when debug is called rather than when it is required.

Currently the environment variable is parsed when debug is required, this means that if the module wants to dynamically change the environment (for example in the presence of a --debug argument) then the require has to be done after this logic instead of at the top of the file, as is convention.

I think it would be better to parse the environment variable when debug() is first called as then modules which would like the extra flexibility can do the following and it will work with the modified env.

var debug = require('debug');

// environment changing logic

debug = debug('module');

Update all the README screenshots

They're all outdated, even the Web Inspector Colors one that I just added (since the node debug contents are white now instead of grey).

true "global" debug.log or remove it entirely

There are some potential "wtf" issues with not being able to capture a non-deduped debug's .log statements because the exported objects will differ if npm can't dedupe.

Possible we need some kind of guaranteed global for this. That was one benefit of the previous implementation, we could have configured it to use console.log/console.error via an env var String.

Related to debug.log changes in #108

Excessive ^$ regexp.

the debug module by default creates the ^$ regexp which is unnecessary, harmful, and makes things run slower.
Test case:

var mod = require('..');
var debug = mod('tes');
debug('x1');
var debug2 = mod('');
debug2('x2');

(process.env.DEBUG || '')
  .split(/[\s,]+/)
  .forEach(function(name){
    name = name.replace('*', '.*?');
    console.log('^' + name + '$');
  });

Output:

wicked@wicked-desktop:~/debug$ node example/test2.js 
   x2 +0ms
^$

Consider there's no DEBUG env in the call.

Tags?

For example, on a running server only one entity has an issue.
Let's say in a game one only quest has some bug.
And we have a code something like this:

var debug = require('debug')('quests');
for (var i in quests) {
  // check if the quest completed
  if (...) {
    debug("quest " + i + "is completed");
  }
}

This would capture all quests.

I could create require('debug')('quest_' + i); for each quest...

But what I would really like is to be able add some tags to debug calls to be able to dynamically filter debug messages by them.

debug({quest: i, uid: uid, }, "quest " + i + "is completed");

and then filter them by either uid or quest somehow.

Any ideas how to do this?

Support "-" prefix in DEBUG environment variable

It would be really useful if you could prefix a module name with a "-" to indicate that debug should be disabled for that module.

For example, this would turn debugging on for everything except for somemodule:

DEBUG="* -somemodule"

Can this be used in conjunction with clusters?

Great tool!

Is it possible to use this in conjunction with node.js clusters? In my implementation it shows these log messages in an infinite loop: Failed to open socket on port 5858, waiting 1000 ms before retrying.

I could just disable clusters in development mode, but wanted to check if there is a way to use them in conjunction with the debug module.

Please include a license

Hi there. It would be awesome from a distribution packaging point of view if you could include the full text of the MIT/X11 license in your software, usually in a file called LICENSE.

Thanks!

Logging objects in browser results in [object Object]

Better support for logging arbitrary objects can be added when in browser.

Doing this

var debug = debug('app:main');
debug('person object', { name: 'foo', likes: ['bar'] });

Shows this in console

app:main person object [object Object] +1ms

I'm not sure how should errors be handled when doing multiple though. Something like this

debug(new Error('first error'), 'some text', new Error('second error'));

The first error prints the stack or message if available. Should every error print the stack or message?

feature: DEBUG=?

context

When debugging apps that have several dependent modules using debug() the DEBUG=* output quickly becomes cluttered. Imagine an app that uses my modules, all using debug() which then depend on other modules using debug(). When someone reports a bug, I want to be able to say... Send me the DEBUG=* output, but that soon becomes impractical if they are reporting from something with real usage. In those cases I'd like to see a list of all the debug namespaces. Then coming up with a DEBUG=a,b,c that would help us track down the problem would be easy. The only other way to find this information would be to look through the source for a huge dependency tree, noting all the debug namespaces.

example

DEBUG=? node app

output

express:application
express:foo
express:bar
send
my-module-a
my-module-b
my-module-c
my-module-d
my-module-e

I'll write it, just wanted to open an issue before I put any time into it. Should probably be one or two lines of code.

Create proper tests

We can't really test what happens once we pass the arguments to console.log, but at least we could write tests testing the arguments that would get passed to console.log. That way we can test the debug options and make sure the formatters work, etc.

is console.error essential?

I'm using another library that uses log4js which already overrides console.error and adds color formatting and timestamps for errors/warnings. This means all my debug output is red and prefixed with [ERROR].

Is there a way that if debug is imported first it can save an un-monkey-patched version of console.error so it can continue to do synchronous logging... or even to allow a choice of log or error in case people don't want sync logging in debug?

Idea: rewrite "%j" to "%o" on web browsers

screen shot 2014-05-30 at 9 23 59 pm

%j doesn't work in any web browsers, but %o logs the object just as if you logged it via console.log(o) directly.

Bonus: perhaps we rewrite vice-versa as well! So that you can use %o in node and get the proper JSON (or util.inspect()?) output on the terminal.

Please release a new version on npm

I'm tired of adding the direct repository for something this basic in my stack.
Will gladly do it if you don't have the time.

Thanks for the amazing work.

question: appropriate way to install via bower?

bower search visionmedia/debug yields:

Search results:
    visionmedia/debug git://github.com/visionmedia/debug

but
bower install visionmedia/debug yields:

bower debug#*               not-cached git://github.com/visionmedia/debug.git#*
bower debug#*                  resolve git://github.com/visionmedia/debug.git#*
bower debug#*                 download https://github.com/visionmedia/debug/archive/0.7.4.tar.gz
bower debug#*                  extract archive.tar.gz
bower debug#*                 resolved git://github.com/visionmedia/debug.git#0.7.4
bower                        ENOTFOUND Package visionmedia/debug=visionmedia/debug not found

any guidance appreciated!

regards,
tony.

Add .enabled flag

to the functions, for example this would be useful for conditional intervals:

var debug = require('debug')('something');

if (debug.enabled) {
  setInterval(checkSomething, 1000);
}

can't redirect output to file

Trying to do the equivalent of DEBUG=* node example/worker > out & as in the readme example, but I just can't get it to work. It keeps writing to terminal. Is this behavior still supported? What might be going wrong?

Using node 0.10.13 on darwin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.