Skip to content

Commit

Permalink
fix: use roarr logger
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jan 11, 2019
1 parent 2092e6e commit b197210
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,11 @@ try {
}

```

## Logging

This package is using [`roarr`](https://www.npmjs.com/package/roarr) logger to log the program's state.

Export `ROARR_LOG=true` environment variable to enable log printing to stdout.

Use [`roarr-cli`](https://github.com/gajus/roarr-cli) program to pretty-print the logs.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"dependencies": {
"ajv": "^6.6.2",
"bluefeather": "^2.9.0",
"debug": "^4.1.1",
"deep-map-keys": "^1.2.0",
"es6-error": "^4.1.1",
"lodash": "^4.17.11",
"qs": "^6.6.0",
"roarr": "^2.12.1",
"xfetch": "^3.14.3"
},
"description": "TMDb SDK.",
Expand Down
7 changes: 7 additions & 0 deletions src/Logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @flow

import Roarr from 'roarr';

export default Roarr.child({
package: 'tmdb'
});
10 changes: 5 additions & 5 deletions src/Tmdb.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
import {
camelCase
} from 'lodash';
import {
createDebug
} from './factories';
import Logger from './Logger';
import {
NotFoundError,
RemoteError,
Expand All @@ -32,7 +30,9 @@ type QueryType = {
[key: string]: string | number | null
};

const debug = createDebug('Tmdb');
const log = Logger.child({
namespace: 'Tmdb'
});

class Tmdb {
apiKey: string;
Expand Down Expand Up @@ -76,7 +76,7 @@ class Tmdb {
// time is wrong, we don't bombard the TMDb server with requests.
const cooldownTime = Math.max(rateLimitReset - currentTime, 30);

debug('reached rate limit; waiting %d seconds', cooldownTime);
log.debug('reached rate limit; waiting %d seconds', cooldownTime);

await delay(cooldownTime * 1000);

Expand Down
7 changes: 0 additions & 7 deletions src/factories/createDebug.js

This file was deleted.

3 changes: 0 additions & 3 deletions src/factories/index.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow

export {default as Tmdb} from './Tmdb';
export {
default as Tmdb
} from './Tmdb';
export {
NotFoundError,
RemoteError,
Expand Down

0 comments on commit b197210

Please sign in to comment.