we-js-logger
Advanced tools
Comparing version 0.1.0 to 0.2.0
109
API.md
@@ -5,3 +5,3 @@ <!-- Generated by documentation.js. Update this documentation by updating the source code. --> | ||
[src/client.js:13-16](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/client.js#L13-L16 "Source code on GitHub") | ||
[src/client.js:13-16](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/client.js#L13-L16 "Source code on GitHub") | ||
@@ -12,3 +12,3 @@ A logger than can be used in browsers | ||
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default DEFAULT_CONFIG)** | ||
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default {})** | ||
@@ -19,3 +19,3 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a preconfigured `bunyan` logger instance | ||
[src/util/client/consoleLogger.js:6-6](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/consoleLogger.js#L6-L6 "Source code on GitHub") | ||
[src/util/client/consoleLogger.js:6-6](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/consoleLogger.js#L6-L6 "Source code on GitHub") | ||
@@ -26,3 +26,3 @@ Pretty logging to `console` for client applications | ||
[src/util/client/consoleLogger.js:13-45](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/consoleLogger.js#L13-L45 "Source code on GitHub") | ||
[src/util/client/consoleLogger.js:13-45](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/consoleLogger.js#L13-L45 "Source code on GitHub") | ||
@@ -39,3 +39,3 @@ Transport to `console` | ||
[src/util/client/logentriesLogger.js:10-16](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/logentriesLogger.js#L10-L16 "Source code on GitHub") | ||
[src/util/client/logentriesLogger.js:10-16](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/logentriesLogger.js#L10-L16 "Source code on GitHub") | ||
@@ -53,3 +53,3 @@ Custom bunyan stream that transports to Logentries from client applications | ||
[src/util/client/logentriesLogger.js:23-30](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/logentriesLogger.js#L23-L30 "Source code on GitHub") | ||
[src/util/client/logentriesLogger.js:23-30](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/logentriesLogger.js#L23-L30 "Source code on GitHub") | ||
@@ -66,3 +66,3 @@ Transport logs to Logentries | ||
[src/util/client/rollbarLogger.js:19-35](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/rollbarLogger.js#L19-L35 "Source code on GitHub") | ||
[src/util/client/rollbarLogger.js:19-35](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/rollbarLogger.js#L19-L35 "Source code on GitHub") | ||
@@ -87,3 +87,3 @@ Custom rollbar stream that transports to logentries from a browser | ||
[src/util/client/rollbarLogger.js:42-48](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/rollbarLogger.js#L42-L48 "Source code on GitHub") | ||
[src/util/client/rollbarLogger.js:42-48](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/client/rollbarLogger.js#L42-L48 "Source code on GitHub") | ||
@@ -98,5 +98,25 @@ Transport logs to Rollbar | ||
# bunyanToRollbarLevelMap | ||
[src/util/common/rollbar.js:9-16](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/rollbar.js#L9-L16 "Source code on GitHub") | ||
Map of bunyan log levels to Rollbar levels | ||
<https://github.com/trentm/node-bunyan#levels> | ||
<https://rollbar.com/docs/notifier/rollbar.js/api/#rollbardebuginfowarnwarningerrorcritical> | ||
# bunyanLevelToRollbarLevelName | ||
[src/util/common/rollbar.js:23-26](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/rollbar.js#L23-L26 "Source code on GitHub") | ||
Convert bunyan log level to rollbar level. Defaults to 'error'. | ||
**Parameters** | ||
- `level` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)](default bunyan.ERROR)** bunyan log level | ||
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Rollbar log level | ||
# NodeLogger | ||
[src/node.js:15-24](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/node.js#L15-L24 "Source code on GitHub") | ||
[src/node.js:15-24](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/node.js#L15-L24 "Source code on GitHub") | ||
@@ -107,17 +127,35 @@ A logger than can be used in node processes | ||
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default DEFAULT_CONFIG)** | ||
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default {})** | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a preconfigured `bunyan` logger instance | ||
# BUNYAN_CONFIG_FIELDS | ||
[src/util/common/config.js:9-14](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/config.js#L9-L14 "Source code on GitHub") | ||
Config keys that should always be passed to | ||
`bunyan.createLogger` | ||
# DEFAULT_ROOT_FIELDS | ||
[src/util/common/config.js:22-25](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/config.js#L22-L25 "Source code on GitHub") | ||
Whitelist of extra config keys that should be | ||
passed to `bunyan.createLogger` to form | ||
root logger fields. | ||
# DEFAULT_CONFIG | ||
[src/util/common/config.js:4-14](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/common/config.js#L4-L14 "Source code on GitHub") | ||
[src/util/common/config.js:28-39](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/config.js#L28-L39 "Source code on GitHub") | ||
# assembleConfig | ||
[src/util/common/config.js:24-32](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/common/config.js#L24-L32 "Source code on GitHub") | ||
[src/util/common/config.js:52-59](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/config.js#L52-L59 "Source code on GitHub") | ||
Merges config with DEFAULT_CONFIG, and appends passed in streams | ||
with pre-configured streams for the runtime | ||
with pre-configured streams for the runtime. | ||
This is used to configure this library, not bunyan as it has a lot of | ||
extra information. See `toBunyanConfig` below. | ||
**Parameters** | ||
@@ -130,5 +168,20 @@ | ||
# toBunyanConfig | ||
[src/util/common/config.js:70-72](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/common/config.js#L70-L72 "Source code on GitHub") | ||
Create a config objct for bunyan from a full `we-js-logger` config object. | ||
Extra keys passed to `bunyan.createLogger` become root logger fields, pass | ||
a custom `config.rootFields` to control this behavior | ||
**Parameters** | ||
- `config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** | ||
- `config.rootFields` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** extra fields to pass to bunyan | ||
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** config for bunyan.createLogger | ||
# ServerRollbarLogger | ||
[src/util/server/rollbarLogger.js:10-17](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/rollbarLogger.js#L10-L17 "Source code on GitHub") | ||
[src/util/server/rollbarLogger.js:10-17](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/server/rollbarLogger.js#L10-L17 "Source code on GitHub") | ||
@@ -147,3 +200,3 @@ Custom bunyan stream that transports to Rollbar from a node process. | ||
[src/util/server/rollbarLogger.js:27-37](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/rollbarLogger.js#L27-L37 "Source code on GitHub") | ||
[src/util/server/rollbarLogger.js:27-37](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/server/rollbarLogger.js#L27-L37 "Source code on GitHub") | ||
@@ -159,25 +212,5 @@ handles `err` and `req` properties, attaches any custom data, | ||
# bunyanToRollbarLevelMap | ||
[src/util/common/rollbar.js:9-16](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/common/rollbar.js#L9-L16 "Source code on GitHub") | ||
Map of bunyan log levels to Rollbar levels | ||
<https://github.com/trentm/node-bunyan#levels> | ||
<https://rollbar.com/docs/notifier/rollbar.js/api/#rollbardebuginfowarnwarningerrorcritical> | ||
# bunyanLevelToRollbarLevelName | ||
[src/util/common/rollbar.js:23-26](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/common/rollbar.js#L23-L26 "Source code on GitHub") | ||
Convert bunyan log level to rollbar level. Defaults to 'error'. | ||
**Parameters** | ||
- `level` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)](default bunyan.ERROR)** bunyan log level | ||
Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Rollbar log level | ||
# ServerLogentriesLogger | ||
[src/util/server/logentriesLogger.js:10-19](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/logentriesLogger.js#L10-L19 "Source code on GitHub") | ||
[src/util/server/logentriesLogger.js:10-19](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/server/logentriesLogger.js#L10-L19 "Source code on GitHub") | ||
@@ -199,3 +232,3 @@ Custom bunyan stream that transports to logentries from a node process | ||
[src/util/server/requestLogger.js:12-48](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/requestLogger.js#L12-L48 "Source code on GitHub") | ||
[src/util/server/requestLogger.js:12-48](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/server/requestLogger.js#L12-L48 "Source code on GitHub") | ||
@@ -214,3 +247,3 @@ Create a request loging express middleware | ||
[src/util/server/requestLogger.js:24-47](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/requestLogger.js#L24-L47 "Source code on GitHub") | ||
[src/util/server/requestLogger.js:24-47](https://github.com/wework/we-js-logger/blob/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599/src/util/server/requestLogger.js#L24-L47 "Source code on GitHub") | ||
@@ -217,0 +250,0 @@ Request Logger Middleware |
@@ -7,2 +7,8 @@ # Change Log | ||
#### [v0.2.0](https://github.com/wework/we-js-logger/compare/v0.1.0...v0.2.0) | ||
> 23 October 2016 | ||
* Fix config and be explicit about which fields are passed to bunyan [`f3e1a96`](https://github.com/wework/we-js-logger/commit/f3e1a9681b0dab3292c89b3e6f419dc0ce5d2599) | ||
#### [v0.1.0](https://github.com/wework/we-js-logger/compare/v0.0.9...v0.1.0) | ||
@@ -9,0 +15,0 @@ > 23 October 2016 |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var bunyan = _interopDefault(require('bunyan')); | ||
var pick = _interopDefault(require('lodash/pick')); | ||
var isFunction = _interopDefault(require('lodash/isFunction')); | ||
@@ -12,2 +13,15 @@ var LE = _interopDefault(require('le_js')); | ||
/** | ||
* Config keys that should always be passed to | ||
* `bunyan.createLogger` | ||
* @type {Array} | ||
*/ | ||
var BUNYAN_CONFIG_FIELDS = ['name', 'level', 'streams', 'serializers']; | ||
/** | ||
* Whitelist of extra config keys that should be | ||
* passed to `bunyan.createLogger` to form | ||
* root logger fields. | ||
* @type {Array} | ||
*/ | ||
var DEFAULT_ROOT_FIELDS = ['environment', 'release']; | ||
/** @type {Object} default config to Logger classes */ | ||
@@ -23,8 +37,12 @@ var DEFAULT_CONFIG = Object.freeze({ | ||
logentriesToken: null, | ||
rollbarToken: null | ||
rollbarToken: null, | ||
rootFields: DEFAULT_ROOT_FIELDS | ||
}); | ||
/** | ||
* Merges config with DEFAULT_CONFIG, and appends passed in streams | ||
* with pre-configured streams for the runtime | ||
* with pre-configured streams for the runtime. | ||
* | ||
* This is used to configure this library, not bunyan as it has a lot of | ||
* extra information. See `toBunyanConfig` below. | ||
* | ||
* @param {Object} config | ||
@@ -35,6 +53,19 @@ * @param {Function} getStreamsForRuntime - returns appended config.streams | ||
function assembleConfig(config, getStreamsForRuntime) { | ||
return Object.assign({}, DEFAULT_CONFIG, config, { | ||
streams: getStreamsForRuntime(config) | ||
var baseConfig = Object.assign({}, DEFAULT_CONFIG, config); | ||
return Object.assign(baseConfig, { | ||
streams: getStreamsForRuntime(baseConfig) | ||
}); | ||
} | ||
/** | ||
* Create a config objct for bunyan from a full `we-js-logger` config object. | ||
* Extra keys passed to `bunyan.createLogger` become root logger fields, pass | ||
* a custom `config.rootFields` to control this behavior | ||
* | ||
* @param {Object} config | ||
* @param {String[]} config.rootFields - extra fields to pass to bunyan | ||
* @return {Object} config for bunyan.createLogger | ||
*/ | ||
function toBunyanConfig(config) { | ||
return pick(config, BUNYAN_CONFIG_FIELDS.concat(config.rootFields)); | ||
} | ||
@@ -390,5 +421,5 @@ function ClientConsoleLogger() {} | ||
function ClientLogger() { | ||
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : DEFAULT_CONFIG; | ||
var config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var clientConfig = assembleConfig(config, getStreams); | ||
return bunyan.createLogger(clientConfig); | ||
return bunyan.createLogger(toBunyanConfig(clientConfig)); | ||
} | ||
@@ -395,0 +426,0 @@ /** |
@@ -6,2 +6,3 @@ 'use strict'; | ||
var bunyan = _interopDefault(require('bunyan')); | ||
var pick = _interopDefault(require('lodash/pick')); | ||
var Rollbar = _interopDefault(require('rollbar')); | ||
@@ -13,2 +14,23 @@ var bunyanFormat = _interopDefault(require('bunyan-format')); | ||
/** | ||
* Config keys that should always be passed to | ||
* `bunyan.createLogger` | ||
* @type {Array} | ||
*/ | ||
const BUNYAN_CONFIG_FIELDS = [ | ||
'name', | ||
'level', | ||
'streams', | ||
'serializers', | ||
]; | ||
/** | ||
* Whitelist of extra config keys that should be | ||
* passed to `bunyan.createLogger` to form | ||
* root logger fields. | ||
* @type {Array} | ||
*/ | ||
const DEFAULT_ROOT_FIELDS = [ | ||
'environment', | ||
'release', | ||
]; | ||
/** @type {Object} default config to Logger classes */ | ||
@@ -24,8 +46,12 @@ const DEFAULT_CONFIG = Object.freeze({ | ||
logentriesToken: null, | ||
rollbarToken: null | ||
rollbarToken: null, | ||
rootFields: DEFAULT_ROOT_FIELDS | ||
}); | ||
/** | ||
* Merges config with DEFAULT_CONFIG, and appends passed in streams | ||
* with pre-configured streams for the runtime | ||
* with pre-configured streams for the runtime. | ||
* | ||
* This is used to configure this library, not bunyan as it has a lot of | ||
* extra information. See `toBunyanConfig` below. | ||
* | ||
* @param {Object} config | ||
@@ -36,10 +62,19 @@ * @param {Function} getStreamsForRuntime - returns appended config.streams | ||
function assembleConfig(config, getStreamsForRuntime) { | ||
return Object.assign({}, | ||
DEFAULT_CONFIG, | ||
config, | ||
{ | ||
streams: getStreamsForRuntime(config) | ||
} | ||
); | ||
const baseConfig = Object.assign({}, DEFAULT_CONFIG, config); | ||
return Object.assign(baseConfig, { | ||
streams: getStreamsForRuntime(baseConfig) | ||
}); | ||
} | ||
/** | ||
* Create a config objct for bunyan from a full `we-js-logger` config object. | ||
* Extra keys passed to `bunyan.createLogger` become root logger fields, pass | ||
* a custom `config.rootFields` to control this behavior | ||
* | ||
* @param {Object} config | ||
* @param {String[]} config.rootFields - extra fields to pass to bunyan | ||
* @return {Object} config for bunyan.createLogger | ||
*/ | ||
function toBunyanConfig(config) { | ||
return pick(config, BUNYAN_CONFIG_FIELDS.concat(config.rootFields)); | ||
} | ||
@@ -156,5 +191,5 @@ /** | ||
*/ | ||
function NodeLogger(config = DEFAULT_CONFIG) { | ||
function NodeLogger(config = {}) { | ||
const serverConfig = assembleConfig(config, getStreams); | ||
const logger = bunyan.createLogger(serverConfig); | ||
const logger = bunyan.createLogger(toBunyanConfig(serverConfig)); | ||
logger.requestLogger = createRequestLogger(logger, serverConfig); | ||
@@ -161,0 +196,0 @@ logger.rollbarErrorMiddleware = Rollbar.errorHandler(serverConfig.rollbarToken); |
{ | ||
"name": "we-js-logger", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A logger for Node and Browser JS with Rollbar and Logentries transports", | ||
@@ -5,0 +5,0 @@ "author": "WeWork Digital <dev-team@wework.com>", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
70024
609
0