diff --git a/src/logger.js b/src/logger.js new file mode 100644 index 0000000..cd16caf --- /dev/null +++ b/src/logger.js @@ -0,0 +1,18 @@ +export default class Logger { + static dispatch(verb, ...args) { + /* eslint-disable-next-line no-console */ + console[verb](...args) + } + + static log(...args) { + Logger.dispatch('log', ...args) + } + + static debug(...args) { + Logger.dispatch('debug', ...args) + } + + static error(...args) { + Logger.dispatch('error', ...args) + } +} diff --git a/src/ocean-agent.js b/src/ocean-agent.js index 37865ba..902ac9c 100644 --- a/src/ocean-agent.js +++ b/src/ocean-agent.js @@ -1,5 +1,5 @@ /* global fetch */ -/* eslint-disable no-console */ +import Logger from 'logger' export default class OceanAgent { constructor(connectionUrl) { @@ -20,17 +20,17 @@ export default class OceanAgent { headers: { 'Content-type': 'application/json' } }) .then(response => { - console.log('Success:', response) + Logger.log('Success:', response) if (response.ok) { - console.log('Success:', response) + Logger.log('Success:', response) return true } - console.log('Failed: ', response.status, response.statusText) + Logger.log('Failed: ', response.status, response.statusText) return false // throw new Error(response.statusText ? response.statusText : `publish asset failed with status ${response.status}`) }) .catch(error => { - console.log(`Publish asset to ocean database could not be completed: ${error.message()}`) + Logger.log(`Publish asset to ocean database could not be completed: ${error.message()}`) return false }) } diff --git a/src/ocean-keeper.js b/src/ocean-keeper.js index 1f8b5fa..a00cafb 100644 --- a/src/ocean-keeper.js +++ b/src/ocean-keeper.js @@ -1,7 +1,6 @@ -/* eslint-disable no-console */ - import Web3 from 'web3' import ContractLoader from './contractLoader' +import Logger from './logger' const DEFAULT_GAS = 300000 @@ -94,7 +93,7 @@ export default class OceanKeeper { paid: await this.verifyOrderPayment(event.args._id).then((received) => received), key: null })) - console.debug('got orders: ', orders) + Logger.debug('got orders: ', orders) return orders } @@ -110,7 +109,7 @@ export default class OceanKeeper { price, { from: publisherAddress, gas: this.defaultGas } ) - console.log('registered: ', result) + Logger.log('registered: ', result) return assetId } @@ -172,7 +171,7 @@ export default class OceanKeeper { event.watch((error, result) => { // eslint-disable-line security/detect-non-literal-fs-filename event.stopWatching() if (error) { - console.log(`Error in keeper ${eventName} event: `, error) + Logger.log(`Error in keeper ${eventName} event: `, error) } callback(result, error) })