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

Commit

Permalink
fix: avoid logging http errors when its logger is not on (#1977)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored and alanshaw committed Apr 4, 2019
1 parent 4d303e8 commit 20beea2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/http/index.js
Expand Up @@ -15,6 +15,8 @@ const MulticastDNS = require('libp2p-mdns')
const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap')
const errorHandler = require('./error-handler')
const LOG = 'ipfs:http-api'
const LOG_ERROR = 'ipfs:http-api:error'

function hapiInfoToMultiaddr (info) {
let hostname = info.host
Expand Down Expand Up @@ -48,8 +50,8 @@ function serverCreator (serverAddrs, createServer, ipfs) {
class HttpApi {
constructor (options) {
this._options = options || {}
this._log = debug('ipfs:http-api')
this._log.error = debug('ipfs:http-api:error')
this._log = debug(LOG)
this._log.error = debug(LOG_ERROR)

if (process.env.IPFS_MONITORING) {
// Setup debug metrics collection
Expand Down Expand Up @@ -147,7 +149,7 @@ class HttpApi {
options: {
prettyPrint: process.env.NODE_ENV !== 'production',
logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'],
level: process.env.DEBUG ? 'debug' : 'error'
level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal')
}
})

Expand Down Expand Up @@ -183,9 +185,9 @@ class HttpApi {
await server.register({
plugin: Pino,
options: {
prettyPrint: Boolean(process.env.DEBUG),
prettyPrint: Boolean(debug.enabled(LOG)),
logEvents: ['onPostStart', 'onPostStop', 'response', 'request-error'],
level: process.env.DEBUG ? 'debug' : 'error'
level: debug.enabled(LOG) ? 'debug' : (debug.enabled(LOG_ERROR) ? 'error' : 'fatal')
}
})

Expand Down

0 comments on commit 20beea2

Please sign in to comment.