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

fix: avoid logging http errors when its logger is not on #1977

Merged
merged 1 commit into from
Apr 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/http/index.js
Original file line number Diff line number Diff line change
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