Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit 20beea2

Browse files
jacobheunAlan Shaw
authored and
Alan Shaw
committed
fix: avoid logging http errors when its logger is not on (#1977)
1 parent 4d303e8 commit 20beea2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/http/index.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const MulticastDNS = require('libp2p-mdns')
1515
const WS = require('libp2p-websockets')
1616
const Bootstrap = require('libp2p-bootstrap')
1717
const errorHandler = require('./error-handler')
18+
const LOG = 'ipfs:http-api'
19+
const LOG_ERROR = 'ipfs:http-api:error'
1820

1921
function hapiInfoToMultiaddr (info) {
2022
let hostname = info.host
@@ -48,8 +50,8 @@ function serverCreator (serverAddrs, createServer, ipfs) {
4850
class HttpApi {
4951
constructor (options) {
5052
this._options = options || {}
51-
this._log = debug('ipfs:http-api')
52-
this._log.error = debug('ipfs:http-api:error')
53+
this._log = debug(LOG)
54+
this._log.error = debug(LOG_ERROR)
5355

5456
if (process.env.IPFS_MONITORING) {
5557
// Setup debug metrics collection
@@ -147,7 +149,7 @@ class HttpApi {
147149
options: {
148150
prettyPrint: process.env.NODE_ENV !== 'production',
149151
logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'],
150-
level: process.env.DEBUG ? 'debug' : 'error'
152+
level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal')
151153
}
152154
})
153155

@@ -183,9 +185,9 @@ class HttpApi {
183185
await server.register({
184186
plugin: Pino,
185187
options: {
186-
prettyPrint: Boolean(process.env.DEBUG),
188+
prettyPrint: Boolean(debug.enabled(LOG)),
187189
logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'],
188-
level: process.env.DEBUG ? 'debug' : 'error'
190+
level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal')
189191
}
190192
})
191193

0 commit comments

Comments
 (0)