43 Commits

Author SHA1 Message Date
Hristo Iliev
50ffa9d85e Enable use of custom log function (#379)
* Enable use of custom log function

* Add test for custom log function
2016-12-17 22:56:14 -08:00
Andrew E. Rhyne
f77ca5d56c added linting and testing boilerplate with sanity check 2016-12-14 00:20:05 -08:00
Lazarev Alexandr
94d78b5b80 Fixed a typo (#356) 2016-12-13 23:21:11 -08:00
Nathan Rajlich
e58d54b46f Node: configurable util.inspect() options (#327)
* `formatArgs()` gets passed the args Array directly

Rather than working on `arguments`. The Node.js version
was for some reason turning the arguments into an Array
again so it was happening twice! This should make things
faster overall.

* whitespace

* rename `Readme.md` to `README.md`

* refactor the `debug()` constructor a bit

Now, debug instances are hot-enabelable. That is, you can
toggle the `debug.enabled` boolean on instances to enable
or disable an instance. There is still no global version of
this functionality.

Now all instances get a `useColors` and `colors` property,
even disabled ones, in case they get enabled later on. Boot-up
time impact should be negligible.

* node: allow configurable `util.inspect()` options

Via env variables by default. So to get more object depth,
you pass the `DEBUG_DEPTH=10` env var.

For the `showHidden` option, you set `DEBUG_SHOW_HIDDEN=on`.

See the Node.js docs for the complete list of `util.inspect()` options:
https://nodejs.org/api/util.html#util_util_inspect_object_options

* README: document inspect env variables
2016-12-12 15:13:35 -08:00
Nathan Rajlich
00f3046c30 Node: %O (big O) pretty-prints the object (#322)
* %O (big O) pretty-prints the object

For example:

```js
var debug = require('./')('foo')

var o = {
  foo: 'bar',
  b: new Buffer(10),
  c: Math.PI
}

debug('%O', o)
```

Previously:

```
  foo { foo: 'bar', b: <Buffer 01 00 00 00 01 00 00 00 c0 82>, c: 3.141592653589793 } +0ms
```

Now:

```
  foo { foo: 'bar',
  foo   b: <Buffer 01 00 00 00 01 00 00 00 c0 82>,
  foo   c: 3.141592653589793 } +0ms
```

This is a breaking change for anybody relying on the old `%O` behavior.
Though I don't think `%O` was working previously because the formatters
regexp wasn't checking for uppercase formatters (now fixed in this patch).

* use %O by default if no formatting string is given

* Readme: add Formatters section

Fixes #302.

* Readme: finish custom formatters example
2016-12-12 11:13:19 -08:00
Laurent
501521fcc6 Use same color for same namespace. (#338)
* Use same color for same namespace.

CF #258

* Remove unused var.
2016-12-06 09:54:01 -08:00
Nathan Rajlich
e2a1955330 Revert "handle regex special characters"
This reverts commit 8dd8345d1498b8c6a3c6d7f7f4ebc600cfd2195b.

We shouldn't have changed the original behavior, which
too many people are relying on at this point.

It's also technically a breaking change, which we shouldn't
have landed on a minor/patch version change. So in the interest
of not breaking people's logs in production, reverting this.

We can discuss in a new issue if we want to restore this patch
for a `v3` release, but at the moment I'm personally leaningo
towards *no*, for historical reasons (i.e. this is reminding
me of Node.js trying to remove `sys` if anybody reading this
remembers those days).

See the discussion in #250 for more backlog.
2016-11-21 19:19:24 -08:00
Nathan Rajlich
475e7b31f3 some random optimizations
Hopefully…
2016-11-07 10:46:22 -08:00
Joe Ibershoff
8dd8345d14 handle regex special characters 2016-01-15 15:23:45 -05:00
Jorge Bucaran
0b02d7c6c1 expose debug as default export
+ Similar to tj/co/blob/master/index.js
+ Allow to re-export debug from another module in ES6
2015-08-02 03:57:13 +09:00
Nathan Rajlich
592429f025 debug: prefer an instance log() function over the global one
Fixes #119.
2014-07-15 16:11:50 -07:00
Tiago Ribeiro
d92fe0e6e0 Add support for multiple wildcards in namespaces 2014-07-08 12:02:38 +01:00
Tim Oxley
dd32a4c902 Make console logging function configurable.
Split log() into 2 methods: formatArgs() and log(), allowing log to be
overridden on a per-namespace or global level. Global log settings trump
per-namespace settings.
2014-06-07 23:34:39 -07:00
Nathan Rajlich
872115d10a make ms diff be global, not be scope
Closes #88.
Closes #90.
2014-06-02 11:36:49 -07:00
Nathan Rajlich
4ddbb61abd debug: ignore empty strings in enable()
Stops the unnecessary /^$/ regexp from being "enabled".
2014-06-01 14:27:13 -07:00
Nathan Rajlich
e502a7df95 *: export the colors array
DRYs up some of the logic in the process,
since the "core" color handling code gets
moved to `debug.js`

Closes #20.
2014-06-01 10:32:30 -07:00
Nathan Rajlich
533406869c debug: fix passing an Error object in directly 2014-05-31 20:12:17 -07:00
Nathan Rajlich
40abfe54e8 Merge pull request #100 from visionmedia/update/add-custom-formatters
Add custom "%n" formatters
2014-05-31 19:11:56 -07:00
Nathan Rajlich
652feca774 debug: remove hacky placeholder logic
@visionmedia pointed out that it is not necessary, which is
good because it was very hacky.
2014-05-31 18:57:30 -07:00
Nathan Rajlich
7a3f318cb6 debug: add custom "formatters"
So that the browser, node, and possibly the end users can
define their own "%n" formatters for the "format" argument
while using debug.
2014-05-31 14:23:18 -07:00
Nathan Rajlich
61394bf18e debug: use "ms" module for humanizing the diff
This would be the first external dependency for `debug`,
so it's slightly controversial.
2014-05-31 13:24:29 -07:00
Nathan Rajlich
83bae02343 debug: invoke save() at the beginning of enable()
We modify the `namespaces` argument directly for some reason,
which ends up saving input that ends up being invalid RegExp code
upon the next `load()`+`enable()` call combo.

Avoid that completely by just saving the input directly first thing.
Fixes browsers since they actually use the "saved" value.
2014-05-30 22:14:10 -07:00
Nathan Rajlich
2cffe24185 rewrite: abstract common logic for Node & browsers 2014-05-30 00:10:10 -07:00
Antoine Lehurt
bb21abf651 Catch localStorage security error when cookies are blocked (Chrome)
If cookies are disabled on Chrome, `window.localStorage` throws an error
`Uncaught Error: SecurityError: DOM Exception 18`
2013-05-29 11:13:53 +02:00
TJ Holowaychuk
f4c8e1ea6c add .message error fallback 2013-04-16 07:09:48 -07:00
TJ Holowaychuk
97a362f7d0 add debug(err) support. Closes #46 2013-04-16 06:54:38 -07:00
Robert Sköld
83aaaac519 Mobile Safari (private mode) is broken with debug
Mobile Safari has a dumb feature where it goes ahead and throws an exception when trying to access the localStorage in private mode.  

Other people with the same issue: 
http://meta.stackoverflow.com/questions/123116/safari-5-1-2-log-in-doesnt-work  

Simply wrapping the local storage access in a try/catch should do the trick...
2013-01-31 17:48:20 +01:00
Robert Sköld
77531e47dd Adapted to new component spec. 2012-10-10 21:40:57 +02:00
TJ Holowaychuk
fd3ad212ad removed file heading comments 2012-05-04 14:01:23 -07:00
Vinay Pulim
883f44558c support "-" prefix on the client 2012-02-07 18:08:28 -05:00
Tj Holowaychuk
29f968022d Added humanize() to CS variant 2012-02-02 16:53:36 -08:00
Tj Holowaychuk
27fc4c58c7 Added debug.disable() to the CS variant 2012-02-02 16:48:22 -08:00
Tj Holowaychuk
8ea07bc911 Fixed: persist client-side variant again. Closes #9 2012-02-02 16:46:21 -08:00
Tj Holowaychuk
1335463519 Removed padding from CS variant 2012-02-02 16:41:54 -08:00
Tj Holowaychuk
6e5e31548b moar refactoring 2012-02-01 12:19:07 -08:00
Tj Holowaychuk
622f59a7a1 removed prev/names globals 2012-02-01 12:18:13 -08:00
Tj Holowaychuk
875a49733e misc refactoring 2012-02-01 12:17:06 -08:00
Tj Holowaychuk
9df0b38dfd added diff padding to the CS 2012-02-01 12:16:14 -08:00
Nathan Rajlich
426d6c2b1d Missing semicolon. 2012-02-01 11:56:04 -08:00
Nathan Rajlich
97c6ddf070 Add debug.enable and debug.enabled APIs.
Makes wildcard filters work once again.
2012-02-01 11:54:32 -08:00
Nathan Rajlich
811471fba2 Make it work in IE8. 2012-02-01 11:06:28 -08:00
Nathan Rajlich
81ed7be977 Don't use localStorage, require a debug.enable function instead. 2012-02-01 11:02:22 -08:00
Tj Holowaychuk
ecf3e067e1 Added quick hack of a client-side version
obviously wouldnt work for older browsers but who
cares ;)
2012-01-30 09:38:43 -08:00