Skip to content

Commit

Permalink
Add docs on logger (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-wade committed May 31, 2016
1 parent 29fa5f2 commit 3ec320f
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 53 deletions.
67 changes: 67 additions & 0 deletions docs/logging.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
Include a logger in your module with:

```javascript
var logger = require('react-server').logging.getLogger(__LOGGER__);
```

This `logger` has methods for many log levels. In order: emergency, alert,
critical, error, warning, notice, info, debug.

Example:

```javascript
logger.debug(`result: ${result}`);
```

Standard log-level methods accept an additional argument, which can be an
arbitrary data structure.

Example:

```javascript
try {
some_work();
} catch (err) {
logger.error("Error calling some_work()", err);
}
```

It also has a `time` method for timing named metrics. Metric names
should be dot-separated and be few in number (i.e. don't include object
IDs or other variables with many potential values).

Example:

```javascript
logger.time(`result.${http_status_code}`, time_in_ms);
```

Another way to log timings is with a `timer` object.

Example:

```javascript
var timer = logger.timer('some_work');
some_work().then(timer.stop);
```

It also has a `gauge` method for tracking integer values.

Example:

```javascript
logger.gauge("response_size_in_bytes", size_in_bytes);
```

If you need more than one logger in your module, you can distinguish them
with labels:

Example:

```javascript
var fooLogger = logging.getLogger(__LOGGER__({ label: "foo" }));
var barLogger = logging.getLogger(__LOGGER__({ label: "bar" }));
```

See [react-server-gulp-module-tagger]() for more details on how `__LOGGER__` is
replaced.
54 changes: 1 addition & 53 deletions packages/react-server/core/logging.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,4 @@
/*
* Include a logger in your module with:
*
* var logger = require('react-server').logging.getLogger(__LOGGER__);
*
* This `logger` has methods for each level specified in logging/common.js.
*
* Example:
*
* logger.debug(`result: ${result}`);
*
* Standard log-level methods accept an additional argument, which can be an
* arbitrary data structure.
*
* Example:
*
* try {
* some_work();
* } catch (err) {
* logger.error("Error calling some_work()", err);
* }
*
* It *also* has a `time` method for timing named metrics. Metric names
* should be dot-separated and be few in number (i.e. don't include object
* IDs or other variables with many potential values).
*
* Example:
*
* logger.time(`result.${http_status_code}`, time_in_ms);
*
* Another way to log timings is with a `timer` object.
*
* Example:
*
* var timer = logger.timer('some_work');
*
* some_work().then(timer.stop);
*
* It *also* has a `gauge` method for tracking integer values.
*
* Example:
*
* logger.gauge("response_size_in_bytes", size_in_bytes);
*
* If you need more than one logger in your module, you can distinguish them
* with labels:
*
* Example:
*
* var fooLogger = logging.getLogger(__LOGGER__({ label: "foo" }));
* var barLogger = logging.getLogger(__LOGGER__({ label: "bar" }));
*
*/
// See docs/logging
if (SERVER_SIDE) {
module.exports = require('./logging/server.js');
} else {
Expand Down

0 comments on commit 3ec320f

Please sign in to comment.