You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/GETTING_STARTED.md
+53-4Lines changed: 53 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -250,16 +250,28 @@ If you want to know more about libp2p peer discovery, you should read the follow
250
250
251
251
## Debugging
252
252
253
-
When running libp2p you may want to see what things are happening behind the scenes. You can see trace logs by setting the `DEBUG` environment variable when running in Node.js, and by setting `debug` as a localStorage item when running in the browser. Some examples:
253
+
When running libp2p you may want to see what things are happening behind the scenes. You can see trace logs by setting the `DEBUG` environment variable when running in Node.js, and by setting `debug` as a localStorage item when running in the browser.
254
+
255
+
You may wish to start with trace logging, then narrow down the scope to just the components you are interested in.
256
+
257
+
Wildcards in components names are supported (`*`), and components can be excluded by prefxing their name with `-`.
If you are running multiple nodes in the same process (for example during a test run), separating their log output can be difficult.
290
+
291
+
In this situation you can use the `prefixLogger` from the `@libp2p/logger` module:
292
+
293
+
```ts
294
+
import { prefixLogger } from'@libp2p/logger'
295
+
import { createLibp2p } from'libp2p'
296
+
297
+
const dialer =awaitcreateLibp2p({
298
+
logger: prefixLogger('dialer')
299
+
// ... other options
300
+
})
301
+
302
+
const listener =awaitcreateLibp2p({
303
+
logger: prefixLogger('listener')
304
+
// ... other options
305
+
})
306
+
```
307
+
308
+
All logs will be prefixed by the string passed to the prefix logger, so later you can do:
309
+
310
+
```console
311
+
DEBUG=dialer:*,listener:* node ./index.js
312
+
listener:libp2p:transports adding transport @libp2p/tcp +0ms
313
+
dialer:libp2p libp2p is starting +0ms
314
+
listener:libp2p libp2p is starting +0ms
315
+
dialer:libp2p:connection-manager started +0ms
316
+
listener:libp2p:connection-manager started +0ms
317
+
listener:libp2p:transports creating listener for @libp2p/tcp on /ip4/127.0.0.1/tcp/0 +6ms
318
+
dialer:libp2p libp2p has started +7ms
319
+
listener:libp2p libp2p has started +7ms
320
+
```
321
+
322
+
...and apply component log filters via the `DEBUG` env var as normal, e.g. `DEBUG=listener:libp2p:tcp:*` to just see TCP transport logs for the listener node, etc.
323
+
275
324
## React Native
276
325
277
326
Libp2p can be used in React Native applications. However, there are some limitations and considerations to take into account as not all transports are supported and some of the underlying dependencies may not work as expected. There is on-going work to address these issues, particularly around the support of TCP. For a demo on how to use libp2p in a React Native application, see https://github.com/ipfs-shipyard/js-libp2p-react-native
0 commit comments