debug-js / debug Goto Github PK
View Code? Open in Web Editor NEWA tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
License: MIT License
A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
License: MIT License
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.
For now, I will simply wrap debug to add this functionality, but I think it would be very useful to have it baked into the module itself.
not sure I really like it being per-prefix anymore
Requiring debug using component:
var debug = require('visionmedia-debug')
Produces error:
Uncaught Error: failed to require "./lib/debug" from "visionmedia-debug/index.js"
Encountered in my component example
either statically or even at runtime would be fine
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.
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:
%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)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?
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.
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
I tried
node --debug app.js
but no cigar ...
Please publish a new version with the browserify key fix :)
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.
(process.env.DEBUG || '')
.split(/[\s,]+/)
Usually use like DEBUG=worker,http node app.js
, so I really can not understand the '\s' there.
Adding debug.js produces this error:
Uncaught ReferenceError: module is not defined
Seems to be related to recent component changes.
localStorage by default
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?
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);
});
It'd be nice to be able to configure a set of replacement regular expressions that are applied against all output-to-be-logged. For instance, I'd love to be able to do s/\d{12}(\d{4})/************\1/g to prevent any logging of credit card numbers.
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.
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');
We are getting an error. I don't see it specified anywhere.
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).
On modern webkit it is possible to style the console output: http://dev.hubspot.com/blog/styling-consolelog
when trying to do npm install debug it will install version 0.7.4 not the latest 0.8.1
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
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.
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?
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"
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.
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!
when tty show ms diff between calls, otherwise UTC
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?
https://github.com/visionmedia/debug/blob/master/package.json#L11
Similar to the browserify field except it will be tool agnostic. Script already supports it and browserify v2 will as well.
"browser": "./debug.js"
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.
DEBUG=? node app
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.
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.
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?
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.
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.
to the functions, for example this would be useful for conditional intervals:
var debug = require('debug')('something');
if (debug.enabled) {
setInterval(checkSomething, 1000);
}
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
.
http://www.draw.io/?share=#rNLYsAm2RNrT9RmIOzFLExNbeSpqcvTUQAQDVrll3YunblT4zR
What is achievable now is the 'implemented' part. Also it would be nice to have a browser interface similar to https://github.com/bobrik/pupergrep or http://log.io
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.