Skip to content

Commit

Permalink
feat: support all bunyan-compatible logger APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
AVVS committed Apr 26, 2017
1 parent 32e0e3d commit bed3cf1
Show file tree
Hide file tree
Showing 4 changed files with 335 additions and 222 deletions.
29 changes: 1 addition & 28 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,30 +1,3 @@
{
"extends": "airbnb-base",
"parser": "babel-eslint",
"plugins": [
"mocha",
"promise"
],
"env": {
"mocha": true
},
"rules": {
"no-param-reassign": [2, {"props": false}],
"global-require": 0,
"no-underscore-dangle": 0,
"no-case-declarations": 0,
"prefer-arrow-callback": 0,
"promise/param-names": 2,
"promise/always-return": 2,
"promise/catch-or-return": 2,
"promise/no-native": 2,
"import/no-extraneous-dependencies": 0,
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "never",
"exports": "never",
"functions": "never",
}]
}
"extends": "makeomatic"
}
43 changes: 22 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,26 @@
},
"homepage": "https://github.com/makeomatic/ms-amqp-transport#readme",
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-eslint": "^7.1.1",
"babel-plugin-transform-class-properties": "^6.19.0",
"babel-plugin-transform-object-rest-spread": "^6.19.0",
"babel-plugin-transform-strict-mode": "^6.18.0",
"babel-register": "^6.18.0",
"benchmark": "^2.1.2",
"bunyan": "^1.8.5",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-plugin-transform-strict-mode": "^6.24.1",
"babel-register": "^6.24.1",
"benchmark": "^2.1.4",
"bunyan": "^1.8.10",
"chai": "^3.4.1",
"cz-conventional-changelog": "^1.2.0",
"eslint": "^3.10.2",
"eslint-config-airbnb-base": "^11.0.1",
"cz-conventional-changelog": "^2.0.0",
"eslint": "^3.19.0",
"eslint-config-airbnb-base": "^11.1.3",
"eslint-config-makeomatic": "^1.0.1",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-mocha": "^4.7.0",
"eslint-plugin-promise": "^3.4.0",
"eslint-plugin-mocha": "^4.9.0",
"eslint-plugin-promise": "^3.5.0",
"isparta": "^4.0.0",
"istanbul": "^0.4.5",
"microtime": "^2.1.2",
"mocha": "^3.2.0",
"microtime": "^2.1.3",
"mocha": "^3.3.0",
"ms-validation": "^3.0.0",
"semantic-release": "^6.3.2",
"stdout-stream": "^1.4.0"
Expand All @@ -57,16 +58,16 @@
},
"dependencies": {
"amqp-coffee": "^0.1.28",
"bluebird": "^3.4.6",
"bluebird": "^3.5.0",
"bunyan-noop": "^2.0.0",
"common-errors": "^1.0.0",
"debug": "^2.3.3",
"eventemitter3": "^2.0.2",
"hashlru": "^1.0.6",
"is": "^3.2.0",
"debug": "^2.6.4",
"eventemitter3": "^2.0.3",
"hashlru": "^2.2.0",
"is": "^3.2.1",
"json-stringify-safe": "^5.0.1",
"lodash": "^4.17.2",
"object-hash": "^1.1.5",
"object-hash": "^1.1.8",
"uuid": "^3.0.0"
},
"release": {
Expand Down
22 changes: 14 additions & 8 deletions src/amqp.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ const os = require('os');
const fmt = require('util').format;
const is = require('is');
const ld = require('lodash').runInContext();
const Bunyan = require('bunyan');
const blackhole = require('bunyan-noop');
const HLRU = require('hashlru');
const hash = require('object-hash');
const assert = require('assert');
const every = require('lodash/every');

// local deps
const pkg = require('../package.json');
Expand All @@ -31,6 +31,8 @@ const { InvalidOperationError, ValidationError } = Errors;
*/
class AMQPTransport extends EventEmitter {

static logLevels = ['trace', 'debug', 'info', 'warn', 'error', 'fatal'];

static defaultOpts = require('./defaults.js');

static extendMessageProperties = [
Expand Down Expand Up @@ -63,14 +65,16 @@ class AMQPTransport extends EventEmitter {
}

// validate configuration
const { error } = validator.validateSync('amqp', config);
if (error) throw error;
assert.ifError(validator.validateSync('amqp', config).error, `Invalid config: ${JSON.stringify(config)}`);

// bunyan logger
if (config.debug && !config.log) {
this.log = require('./utils/logger.js');
} else if (config.log && typeof config.log === 'object') {
const compatibleLogger = every(AMQPTransport.logLevels, level => is.fn(config.log[level]));
this.log = compatibleLogger ? config.log : require('bunyan-noop')();
} else {
this.log = is.instance(config.log, Bunyan) ? config.log : blackhole();
this.log = require('bunyan-noop')();
}

// setup instance
Expand Down Expand Up @@ -138,10 +142,12 @@ class AMQPTransport extends EventEmitter {
switch (amqp.state) {
case 'opening':
case 'open':
case 'reconnecting':
case 'reconnecting': {
const msg = 'connection was already initialized, close it first';
const err = new InvalidOperationError(msg);
return Promise.reject(err);
}

default:
// already closed, but make sure
amqp.close();
Expand Down Expand Up @@ -753,8 +759,8 @@ class AMQPTransport extends EventEmitter {
* Specifies default publishing options
* @param {Object} options
* @param {String} options.exchange - will be overwritten by exchange thats passed
* in the publish/send methods
* https://github.com/dropbox/amqp-coffee/blob/6d99cf4c9e312c9e5856897ab33458afbdd214e5/src/lib/Publisher.coffee#L90
* in the publish/send methods
* https://github.com/dropbox/amqp-coffee/blob/6d99cf4c9e312c9e5856897ab33458afbdd214e5/src/lib/Publisher.coffee#L90
* @return {Object}
*/
_publishOptions(options = {}) {
Expand Down
Loading

0 comments on commit bed3cf1

Please sign in to comment.