Skip to content

Commit dfbac9c

Browse files
committed
readme refactor
1 parent ce1a236 commit dfbac9c

1 file changed

Lines changed: 69 additions & 49 deletions

File tree

README.md

Lines changed: 69 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
[![Build Status](https://travis-ci.org/visionmedia/debug.svg?branch=master)](https://travis-ci.org/visionmedia/debug) [![Coverage Status](https://coveralls.io/repos/github/visionmedia/debug/badge.svg?branch=master)](https://coveralls.io/github/visionmedia/debug?branch=master) [![Slack](https://visionmedia-community-slackin.now.sh/badge.svg)](https://visionmedia-community-slackin.now.sh/) [![OpenCollective](https://opencollective.com/debug/backers/badge.svg)](#backers)
33
[![OpenCollective](https://opencollective.com/debug/sponsors/badge.svg)](#sponsors)
44

5+
<img width="647" src="https://user-images.githubusercontent.com/71256/29091486-fa38524c-7c37-11e7-895f-e7ec8e1039b6.png">
56

6-
7-
A tiny node.js debugging utility modelled after node core's debugging technique.
7+
A tiny JavaScript debugging utility modelled after Node.js core's debugging
8+
technique. Works in Node.js and web browsers.
89

910
**Discussion around the V3 API is under way [here](https://github.com/visionmedia/debug/issues/370)**
1011

@@ -27,7 +28,7 @@ var debug = require('debug')('http')
2728

2829
// fake app
2930

30-
debug('booting %s', name);
31+
debug('booting %o', name);
3132

3233
http.createServer(function(req, res){
3334
debug(req.method + ' ' + req.url);
@@ -51,52 +52,62 @@ setInterval(function(){
5152
}, 1000);
5253
```
5354

54-
The __DEBUG__ environment variable is then used to enable these based on space or comma-delimited names. Here are some examples:
55+
The `DEBUG` environment variable is then used to enable these based on space or
56+
comma-delimited names.
5557

56-
![debug http and worker](http://f.cl.ly/items/18471z1H402O24072r1J/Screenshot.png)
58+
Here are some examples:
5759

58-
![debug worker](http://f.cl.ly/items/1X413v1a3M0d3C2c1E0i/Screenshot.png)
60+
<img width="647" alt="screen shot 2017-08-08 at 12 53 04 pm" src="https://user-images.githubusercontent.com/71256/29091703-a6302cdc-7c38-11e7-8304-7c0b3bc600cd.png">
61+
<img width="647" alt="screen shot 2017-08-08 at 12 53 38 pm" src="https://user-images.githubusercontent.com/71256/29091700-a62a6888-7c38-11e7-800b-db911291ca2b.png">
62+
<img width="647" alt="screen shot 2017-08-08 at 12 53 25 pm" src="https://user-images.githubusercontent.com/71256/29091701-a62ea114-7c38-11e7-826a-2692bedca740.png">
5963

6064
#### Windows note
6165

62-
On Windows the environment variable is set using the `set` command.
66+
On Windows the environment variable is set using the `set` command.
6367

64-
```cmd
65-
set DEBUG=*,-not_this
66-
```
68+
```cmd
69+
set DEBUG=*,-not_this
70+
```
6771

68-
Note that PowerShell uses different syntax to set environment variables.
72+
Note that PowerShell uses different syntax to set environment variables.
6973

70-
```cmd
71-
$env:DEBUG = "*,-not_this"
72-
```
74+
```cmd
75+
$env:DEBUG = "*,-not_this"
76+
```
7377

7478
Then, run the program to be debugged as usual.
7579

7680
## Millisecond diff
7781

78-
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
82+
When actively developing an application it can be useful to see when the time spent between one `debug()` call and the next. Suppose for example you invoke `debug()` before requesting a resource, and after as well, the "+NNNms" will show you how much time was spent between calls.
7983

80-
![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png)
84+
![](http://f.cl.ly/items/2i3h1d3t121M2Z1A3Q0N/Screenshot.png)
8185

82-
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
86+
When stdout is not a TTY, `Date#toISOString()` is used, making it more useful for logging the debug information as shown below:
87+
88+
![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png)
8389

84-
![](http://f.cl.ly/items/112H3i0e0o0P0a2Q2r11/Screenshot.png)
8590

8691
## Conventions
8792

88-
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
93+
If you're using this in one or more of your libraries, you _should_ use the name of your library so that developers may toggle debugging as desired without guessing names. If you have more than one debuggers you _should_ prefix them with your library name and use ":" to separate features. For example "bodyParser" from Connect would then be "connect:bodyParser". If you append a "*" to the end of your name, it will always be enabled regardless of the setting of the DEBUG environment variable. You can then use it for normal output as well as debug output.
8994

9095
## Wildcards
9196

92-
The `*` character may be used as a wildcard. Suppose for example your library has debuggers named "connect:bodyParser", "connect:compress", "connect:session", instead of listing all three with `DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do `DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
97+
The `*` character may be used as a wildcard. Suppose for example your library has
98+
debuggers named "connect:bodyParser", "connect:compress", "connect:session",
99+
instead of listing all three with
100+
`DEBUG=connect:bodyParser,connect:compress,connect:session`, you may simply do
101+
`DEBUG=connect:*`, or to run everything using this module simply use `DEBUG=*`.
93102

94-
You can also exclude specific debuggers by prefixing them with a "-" character. For example, `DEBUG=*,-connect:*` would include all debuggers except those starting with "connect:".
103+
You can also exclude specific debuggers by prefixing them with a "-" character.
104+
For example, `DEBUG=*,-connect:*` would include all debuggers except those
105+
starting with "connect:".
95106

96107
## Environment Variables
97108

98-
When running through Node.js, you can set a few environment variables that will
99-
change the behavior of the debug logging:
109+
When running through Node.js, you can set a few environment variables that will
110+
change the behavior of the debug logging:
100111

101112
| Name | Purpose |
102113
|-----------|-------------------------------------------------|
@@ -106,16 +117,16 @@ Then, run the program to be debugged as usual.
106117
| `DEBUG_SHOW_HIDDEN` | Shows hidden properties on inspected objects. |
107118

108119

109-
__Note:__ The environment variables beginning with `DEBUG_` end up being
110-
converted into an Options object that gets used with `%o`/`%O` formatters.
111-
See the Node.js documentation for
112-
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
113-
for the complete list.
120+
__Note:__ The environment variables beginning with `DEBUG_` end up being
121+
converted into an Options object that gets used with `%o`/`%O` formatters.
122+
See the Node.js documentation for
123+
[`util.inspect()`](https://nodejs.org/api/util.html#util_util_inspect_object_options)
124+
for the complete list.
114125

115126
## Formatters
116127

117-
118-
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting. Below are the officially supported formatters:
128+
Debug uses [printf-style](https://wikipedia.org/wiki/Printf_format_string) formatting.
129+
Below are the officially supported formatters:
119130

120131
| Formatter | Representation |
121132
|-----------|----------------|
@@ -126,9 +137,12 @@ Then, run the program to be debugged as usual.
126137
| `%j` | JSON. Replaced with the string '[Circular]' if the argument contains circular references. |
127138
| `%%` | Single percent sign ('%'). This does not consume an argument. |
128139

140+
129141
### Custom formatters
130142

131-
You can add custom formatters by extending the `debug.formatters` object. For example, if you wanted to add support for rendering a Buffer as hex with `%h`, you could do something like:
143+
You can add custom formatters by extending the `debug.formatters` object.
144+
For example, if you wanted to add support for rendering a Buffer as hex with
145+
`%h`, you could do something like:
132146

133147
```js
134148
const createDebug = require('debug')
@@ -142,14 +156,16 @@ debug('this is hex: %h', new Buffer('hello world'))
142156
// foo this is hex: 68656c6c6f20776f726c6421 +0ms
143157
```
144158

145-
## Browser support
146-
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
147-
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
148-
if you don't want to build it yourself.
149159

150-
Debug's enable state is currently persisted by `localStorage`.
151-
Consider the situation shown below where you have `worker:a` and `worker:b`,
152-
and wish to debug both. You can enable this using `localStorage.debug`:
160+
## Browser Support
161+
162+
You can build a browser-ready script using [browserify](https://github.com/substack/node-browserify),
163+
or just use the [browserify-as-a-service](https://wzrd.in/) [build](https://wzrd.in/standalone/debug@latest),
164+
if you don't want to build it yourself.
165+
166+
Debug's enable state is currently persisted by `localStorage`.
167+
Consider the situation shown below where you have `worker:a` and `worker:b`,
168+
and wish to debug both. You can enable this using `localStorage.debug`:
153169

154170
```js
155171
localStorage.debug = 'worker:*'
@@ -172,21 +188,21 @@ setInterval(function(){
172188

173189
#### Web Inspector Colors
174190

175-
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
176-
option. These are WebKit web inspectors, Firefox ([since version
177-
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
178-
and the Firebug plugin for Firefox (any version).
191+
Colors are also enabled on "Web Inspectors" that understand the `%c` formatting
192+
option. These are WebKit web inspectors, Firefox ([since version
193+
31](https://hacks.mozilla.org/2014/05/editable-box-model-multiple-selection-sublime-text-keys-much-more-firefox-developer-tools-episode-31/))
194+
and the Firebug plugin for Firefox (any version).
179195

180-
Colored output looks something like:
196+
Colored output looks something like:
181197

182-
![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png)
198+
![](https://cloud.githubusercontent.com/assets/71256/3139768/b98c5fd8-e8ef-11e3-862a-f7253b6f47c6.png)
183199

184200

185201
## Output streams
186202

187203
By default `debug` will log to stderr, however this can be configured per-namespace by overriding the `log` method:
188204

189-
Example _stdout.js_:
205+
Example [_stdout.js_](./examples/node/stdout.js):
190206

191207
```js
192208
var debug = require('debug');
@@ -210,16 +226,20 @@ log('still goes to stdout, but via console.info now');
210226

211227
## Checking whether a debug target is enabled
212228

213-
After you've created a debug instance, you can check whether it is enabled by its `.enabled` property:
229+
After you've created a debug instance, you can determine whether or not it is
230+
enabled by checking the `enabled` property:
214231

215232
```javascript
216233
const debug = require('debug')('http');
217234

218-
if(debug.enabled) {
219-
// ...
235+
if (debug.enabled) {
236+
// do stuff...
220237
}
221238
```
222239

240+
You can also manually toggle this property to force the debug instance to be
241+
enabled or disabled.
242+
223243

224244
## Authors
225245

@@ -302,7 +322,7 @@ Become a sponsor and get your logo on our README on Github with a link to your s
302322

303323
(The MIT License)
304324

305-
Copyright (c) 2014-2016 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
325+
Copyright (c) 2014-2017 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
306326

307327
Permission is hereby granted, free of charge, to any person obtaining
308328
a copy of this software and associated documentation files (the

0 commit comments

Comments
 (0)