Skip to content

Commit

Permalink
update tests and use bunyan constant
Browse files Browse the repository at this point in the history
  • Loading branch information
mattjstar committed Jan 6, 2017
1 parent 6345059 commit 87687fc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 42 deletions.
42 changes: 21 additions & 21 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ClientLogger

[src/client.js:16-24](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/client.js#L16-L24 "Source code on GitHub")
[src/client.js:16-24](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/client.js#L16-L24 "Source code on GitHub")

A logger than can be used in browsers

Expand All @@ -14,13 +14,13 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# ClientConsoleLogger

[src/util/client/consoleLogger.js:6-6](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/consoleLogger.js#L6-L6 "Source code on GitHub")

Pretty logging to `console` for client applications

## write

[src/util/client/consoleLogger.js:13-45](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/consoleLogger.js#L13-L45 "Source code on GitHub")

Transport to `console`

Expand All @@ -32,7 +32,7 @@ Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re

# ClientLogentriesLogger

[src/util/client/logentriesLogger.js:10-16](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/logentriesLogger.js#L10-L16 "Source code on GitHub")

Custom bunyan stream that transports to Logentries from client applications

Expand All @@ -45,7 +45,7 @@ Custom bunyan stream that transports to Logentries from client applications

## write

[src/util/client/logentriesLogger.js:23-30](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/logentriesLogger.js#L23-L30 "Source code on GitHub")

Transport logs to Logentries

Expand All @@ -57,7 +57,7 @@ Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re

# ClientRollbarLogger

[src/util/client/rollbarLogger.js:19-35](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/rollbarLogger.js#L19-L35 "Source code on GitHub")

Custom rollbar stream that transports to logentries from a browser
Wortks with a global Rollbar instance that is already initialized.
Expand All @@ -77,7 +77,7 @@ integrating Rollbar in client apps

## write

[src/util/client/rollbarLogger.js:42-48](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/client/rollbarLogger.js#L42-L48 "Source code on GitHub")

Transport logs to Rollbar

Expand All @@ -89,7 +89,7 @@ Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re

# NodeLogger

[src/node.js:18-28](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/node.js#L18-L28 "Source code on GitHub")
[src/node.js:18-28](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/node.js#L18-L28 "Source code on GitHub")

A logger than can be used in node processes

Expand All @@ -101,33 +101,33 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# BUNYAN_CONFIG_FIELDS

[src/util/common/config.js:9-14](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L9-L14 "Source code on GitHub")
[src/util/common/config.js:9-14](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/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/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L22-L25 "Source code on GitHub")
[src/util/common/config.js:22-25](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/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.

# BUNYAN_LOGGER_LEVELS

[src/util/common/config.js:32-39](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L32-L39 "Source code on GitHub")
[src/util/common/config.js:32-32](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/common/config.js#L32-L32 "Source code on GitHub")

Array of bunyan's different log levels.
<https://github.com/trentm/node-bunyan#levels>

# DEFAULT_CONFIG

[src/util/common/config.js:42-54](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L42-L54 "Source code on GitHub")
[src/util/common/config.js:35-47](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/common/config.js#L35-L47 "Source code on GitHub")

# assembleConfig

[src/util/common/config.js:67-74](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L67-L74 "Source code on GitHub")
[src/util/common/config.js:60-67](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/common/config.js#L60-L67 "Source code on GitHub")

Merges config with DEFAULT_CONFIG, and appends passed in streams
with pre-configured streams for the runtime.
Expand All @@ -144,7 +144,7 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# toBunyanConfig

[src/util/common/config.js:85-87](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/config.js#L85-L87 "Source code on GitHub")
[src/util/common/config.js:78-80](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/common/config.js#L78-L80 "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
Expand All @@ -159,7 +159,7 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# ServerRollbarLogger

[src/util/server/rollbarLogger.js:10-17](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/server/rollbarLogger.js#L10-L17 "Source code on GitHub")

Custom bunyan stream that transports to Rollbar from a node process.
See <https://rollbar.com/docs/notifier/node_rollbar/> for integration details
Expand All @@ -173,7 +173,7 @@ See <https://rollbar.com/docs/notifier/node_rollbar/> for integration details

## write

[src/util/server/rollbarLogger.js:27-37](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/server/rollbarLogger.js#L27-L37 "Source code on GitHub")

handles `err` and `req` properties, attaches any custom data,
and calls the appropriate Rollbar method.
Expand All @@ -186,15 +186,15 @@ Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Re

# bunyanToRollbarLevelMap

[src/util/common/rollbar.js:9-16](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/rollbar.js#L9-L16 "Source code on GitHub")
[src/util/common/rollbar.js:9-16](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/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/9969decd2ed8415f12759f3765a900c0fdf294e7/src/util/common/rollbar.js#L23-L26 "Source code on GitHub")
[src/util/common/rollbar.js:23-26](https://github.com/wework/we-js-logger/blob/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/common/rollbar.js#L23-L26 "Source code on GitHub")

Convert bunyan log level to rollbar level. Defaults to 'error'.

Expand All @@ -206,7 +206,7 @@ Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# ServerLogentriesLogger

[src/util/server/logentriesLogger.js:10-19](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/server/logentriesLogger.js#L10-L19 "Source code on GitHub")

Custom bunyan stream that transports to logentries from a node process

Expand All @@ -223,7 +223,7 @@ Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refer

# createRequestLogger

[src/util/server/requestLogger.js:12-48](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/server/requestLogger.js#L12-L48 "Source code on GitHub")

Create a request loging express middleware

Expand All @@ -239,7 +239,7 @@ Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Ref

# requestLoggerMiddleware

[src/util/server/requestLogger.js:24-47](https://github.com/wework/we-js-logger/blob/9969decd2ed8415f12759f3765a900c0fdf294e7/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/63450596a0a4d2b7433ac1afee8dc5d283a82521/src/util/server/requestLogger.js#L24-L47 "Source code on GitHub")

Request Logger Middleware
Adds base logging to every request
Expand Down
11 changes: 2 additions & 9 deletions src/util/common/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bunyan from 'bunyan';
import bunyan, { levelFromName } from 'bunyan';
import pick from 'lodash/pick';

/**
Expand Down Expand Up @@ -29,14 +29,7 @@ const DEFAULT_ROOT_FIELDS = [
* https://github.com/trentm/node-bunyan#levels
* @type {Array}
*/
export const BUNYAN_LOGGER_LEVELS = [
'trace',
'debug',
'info',
'warn',
'error',
'fatal',
]
export const BUNYAN_LOGGER_LEVELS = Object.keys(levelFromName);

/** @type {Object} default config to Logger classes */
export const DEFAULT_CONFIG = Object.freeze({
Expand Down
42 changes: 30 additions & 12 deletions test/specs/logger.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,20 +112,38 @@ describe('we-js-logger', () => {
log._emit = sinon.stub();
});

describe('hides secrets for fields', () => {
it('works', () => {
log.info({ scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(log._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
});
it('hides secrets for fields', () => {
log.info({ scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(log._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
});

it('hides secrets for msg', () => {
log.info('Testing Log', { scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
});

describe('hides secrets for msg', () => {
it('works', () => {
log.info('Testing Log', { scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(log._emit).to.have.been.calledOnce;
expect(log._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
describe('child log', () => {
let childLog;

beforeEach(() => {
childLog = log.child({ component: 'child/test' });
childLog._emit = sinon.stub();
});

it('hides secrets for fields', () => {
childLog.info({ scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(childLog._emit).to.have.been.calledOnce;
expect(childLog._emit.firstCall.args[0].scrubMe).to.equal('[SECRET]');
expect(childLog._emit.firstCall.args[0].tlc).to.equal('No Scrubs');
});

it('hides secrets for msg', () => {
childLog.info('Testing Log', { scrubMe: 'This should be ignored', tlc: 'No Scrubs' });
expect(childLog._emit).to.have.been.calledOnce;
expect(childLog._emit.firstCall.args[0].msg).to.equal("Testing Log { scrubMe: '[SECRET]', tlc: 'No Scrubs' }");
});
});
});
Expand Down

0 comments on commit 87687fc

Please sign in to comment.