Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Nason committed Oct 23, 2016
1 parent cae2430 commit 55ca75e
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 107 deletions.
174 changes: 92 additions & 82 deletions API.md
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->

# we-js-logger/client
# ClientLogger

[src/client.js:5-5](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/client.js#L5-L5 "Source code on GitHub")
[src/client.js:13-16](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/client.js#L13-L16 "Source code on GitHub")

A logger than can be used in browsers

# we-js-logger/util/logger

[src/util/common/logger.js:9-67](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/logger.js#L9-L67 "Source code on GitHub")

Base logger class, used for both node and client loggers

Uses [bunyan](https://github.com/trentm/node-bunyan/) under the hood, which has a few quirks

# constructor

[src/util/common/logger.js:23-57](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/logger.js#L23-L57 "Source code on GitHub")

**Parameters**

- `options` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** logger configuration
- `options.name` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the name of the logger
- `options.environment` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** application environment
- `options.codeVersion` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** a code version, preferably a SHA
- `options.level` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** the level to log at
- `options.stdout` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** output to stdout
- `options.streams` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)** bunyan stream configuration
- `options.serializers` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** bunyan serializer configuration
- `options.logentriesToken` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Logentries API token
- `options.rollbarToken` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Rollbar token
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** (optional, default `{}`)
- `$0.name` (optional, default `'WeWork'`)
- `$0.environment`
- `$0.codeVersion`
- `$0.level` (optional, default `'info'`)
- `$0.stdout` (optional, default `true`)
- `$0.streams` (optional, default `[]`)
- `$0.serializers` (optional, default `bunyan.stdSerializers`)
- `$0.logentriesToken` (optional, default `''`)
- `$0.rollbarToken` (optional, default `''`)

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a configured bunyan instance
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default DEFAULT_CONFIG)**

# getStreams

[src/util/common/logger.js:64-66](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/logger.js#L64-L66 "Source code on GitHub")

returns bunyan streams -- meant to be overridden by subclasses of Logger

Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)**
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a preconfigured `bunyan` logger instance

# ClientConsoleLogger

[src/util/client/consoleLogger.js:6-6](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/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/cae24309f8808c8dd900e412cbacb5c373d0b92c/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/9cfc90bf37a69f474912dc405a04ef729da1d8a0/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/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/consoleLogger.js#L13-L45 "Source code on GitHub")

Transport to `console`

Expand All @@ -71,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/9cfc90bf37a69f474912dc405a04ef729da1d8a0/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/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/logentriesLogger.js#L10-L16 "Source code on GitHub")

Custom bunyan stream that transports to Logentries from client applications

Expand All @@ -84,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/9cfc90bf37a69f474912dc405a04ef729da1d8a0/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/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/client/logentriesLogger.js#L23-L30 "Source code on GitHub")

Transport logs to Logentries

Expand All @@ -94,12 +55,13 @@ Transport logs to Logentries

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**

# RollbarLogger
# ClientRollbarLogger

[src/util/client/rollbarLogger.js:16-34](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/client/rollbarLogger.js#L16-L34 "Source code on GitHub")
[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")

Custom rollbar stream that transports to logentries from a browser
Includes logic for handling global Rollbar instance, else initializing Rollbar here.
Wortks with a global Rollbar instance that is already initialized.
Note this expects rollbar to be loaded in the head, not via an npm module.
See <https://rollbar.com/docs/notifier/rollbar.js/#quick-start> for details on
integrating Rollbar in client apps

Expand All @@ -115,7 +77,7 @@ integrating Rollbar in client apps

## write

[src/util/client/rollbarLogger.js:41-47](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/client/rollbarLogger.js#L41-L47 "Source code on GitHub")
[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")

Transport logs to Rollbar

Expand All @@ -125,68 +87,86 @@ Transport logs to Rollbar

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**

## write
# NodeLogger

[src/util/server/rollbarLogger.js:29-44](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/server/rollbarLogger.js#L29-L44 "Source code on GitHub")
[src/node.js:15-24](https://github.com/wework/we-js-logger/blob/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/node.js#L15-L24 "Source code on GitHub")

handles `err` and `req` properties, attaches any custom data,
and calls the appropriate Rollbar method.
A logger than can be used in node processes

**Parameters**

- `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default {})**
- `config` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default DEFAULT_CONFIG)**

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a preconfigured `bunyan` logger instance

# we-js-logger/util/common/rollbar
# DEFAULT_CONFIG

[src/util/common/rollbar.js:12-19](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/rollbar.js#L12-L19 "Source code on GitHub")
[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")

Shared rollbar helpers
# assembleConfig

# bunyanToRollbarLevelMap
[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/rollbar.js:12-19](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/rollbar.js#L12-L19 "Source code on GitHub")
Merges config with DEFAULT_CONFIG, and appends passed in streams
with pre-configured streams for the runtime

Maps bunyan log levels to Rollbar levels
<https://github.com/trentm/node-bunyan#levels>
<https://rollbar.com/docs/notifier/rollbar.js/api/#rollbardebuginfowarnwarningerrorcritical>
**Parameters**

# bunyanLevelToRollbarLevelName
- `config` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `getStreamsForRuntime` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)** returns appended config.streams

[src/util/common/rollbar.js:25-28](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/common/rollbar.js#L25-L28 "Source code on GitHub")
Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** runtimeConfig

# 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")

Custom bunyan stream that transports to Rollbar from a node process.
See <https://rollbar.com/docs/notifier/node_rollbar/> for integration details

**Parameters**

- `level` **\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)](default bunyan.ERROR)** bunyan log level
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.token`
- `$0.codeVersion`
- `$0.environment`

Returns **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Rollbar log level
## write

# we-js-logger/node
[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/node.js:12-52](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/node.js#L12-L52 "Source code on GitHub")
handles `err` and `req` properties, attaches any custom data,
and calls the appropriate Rollbar method.

**Extends Logger**
**Parameters**

A logger than can be used in node processes
- `data` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default {})**

# we-js-logger/util/server/rollbarLogger
Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**

[src/util/server/rollbarLogger.js:12-19](https://github.com/wework/we-js-logger/blob/9cfc90bf37a69f474912dc405a04ef729da1d8a0/src/util/server/rollbarLogger.js#L12-L19 "Source code on GitHub")
# bunyanToRollbarLevelMap

Custom bunyan stream that transports to Rollbar from a node process.
See <https://rollbar.com/docs/notifier/node_rollbar/> for integration details
[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**

- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `$0.token`
- `$0.codeVersion`
- `$0.environment`
- `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/9cfc90bf37a69f474912dc405a04ef729da1d8a0/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/cae24309f8808c8dd900e412cbacb5c373d0b92c/src/util/server/logentriesLogger.js#L10-L19 "Source code on GitHub")

Custom bunyan stream that transports to logentries from a node process

Expand All @@ -200,3 +180,33 @@ Custom bunyan stream that transports to logentries from a node process
- `$0.level`

Returns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** bunyan stream config

# createRequestLogger

[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")

Create a request loging express middleware

**Parameters**

- `logger` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** a logger instance
- `options` **\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default { headerName: DEFAULT_HEADER_NAME })**
- `options.headerName` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?**

Returns **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**

# requestLoggerMiddleware

[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")

Request Logger Middleware
Adds base logging to every request
Attaches a `log` child to each request object

**Parameters**

- `req` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `res` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)**
- `next` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**

Returns **[undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)**
Loading

0 comments on commit 55ca75e

Please sign in to comment.