Skip to content
This repository was archived by the owner on Jan 5, 2023. It is now read-only.

Commit f782fb6

Browse files
Merge pull request #23 from Nike-Inc/pr/20
Pr/20
2 parents 063d575 + ca26e94 commit f782fb6

10 files changed

+170
-204
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
The changelog for BOKOR includes information about the each release including any update notes, release notes as well as bug fixes, updates to existing features and new features.
44

5+
---
6+
## 2.0.0
7+
8+
### Release Notes
9+
#### Added
10+
11+
- Migrated logging to Bunyan - thanks! [Erik Sutherland](https://github.com/MrRacoon)
12+
- Replaced deprecated istanbul with nyc for code coverage
13+
- Updated dependencies for security
14+
515
---
616
## 1.3.3
717

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,16 @@ bokorServer/
287287
```
288288

289289
## Logs
290-
`====[ cache miss ]====`
290+
Bokor uses [Bunyan](https://github.com/trentm/node-bunyan) for logging. Bunyan is a simple and fast JSON logging library.
291+
Bunyan has many features. One of them allows pretty-printing of the log. We show this feature in the below [Demo From Source](#demo-from-source)
291292

292-
❤️ If the request does not find a prerecorded response it will log cache miss in the color red.
293+
`(cache=miss)`
293294

294-
`====[ cache hit ]====`
295+
❤️ If the request does not find a prerecorded response it will log cache miss.
295296

296-
💚 If the request finds a prerecorded response it will log cache hit in the color green.
297+
`(cache=hit)`
298+
299+
💚 If the request finds a prerecorded response it will log cache hit.
297300

298301
## Demo from Source
299302
Follow the below steps to run the Bokor Demo.
@@ -303,7 +306,7 @@ $ git clone https://github.com/Nike-Inc/bokor.git
303306
$ cd bokor
304307
$ npm install
305308
$ cd examples/source_example/
306-
$ node server.js
309+
$ node server.js | ../../node_modules/.bin/bunyan
307310
```
308311

309312
Record a response
@@ -320,20 +323,20 @@ $ curl http://localhost:7777/users/jimmyeisenhauer
320323
## Tests
321324

322325
```
323-
$ npm test
326+
$ npm run coverage
324327
```
325328

326329
## FAQ
327330
### Where did the name Bokor come from?
328331
It is a long story, but one of my favorite quotes is:
329332

330-
#####“any sufficiently advanced technology is indistinguishable from magic.”
333+
##### “any sufficiently advanced technology is indistinguishable from magic.”
331334

332335
-arthur c. clarke
333336

334337
So of course I penned a similar quote around test automation.
335338

336-
#####“software tests that unexplainably pass or fail are indistinguishable from voodoo.”
339+
##### “software tests that unexplainably pass or fail are indistinguishable from voodoo.”
337340
-james r. eisenhauer
338341

339342
And a Bokor is a voodoo sorcerer for hire who are said to serve the loa 'with both hands', practicing for both good and evil.

lib/bokor.js

+15-14
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,38 @@ var bokorOptions = {};
2020
require('colors');
2121
require('http');
2222

23+
function start(options) {
2324

25+
// -- sepia config --------------
26+
// default bokor admin server on by default
27+
var sepia;
28+
if (options.admin === false) {
29+
sepia = require('./sepia');
30+
} else {
31+
sepia = require('./sepia').withSepiaServer();
32+
}
2433

25-
function start(options) {
34+
var logger = sepia.logger;
2635

2736
// -- bokor config --------------
2837
if (options.servers != null) {
2938
bokorOptions.servers = options.servers;
3039
} else {
31-
console.log('CONFIGURATION ERROR: Missing server config'.red);
40+
logger.error('CONFIGURATION ERROR: Missing server config');
3241
return;
3342
}
3443

3544
if (options.filters != null) {
3645
bokorOptions.filters = options.filters;
3746
} else {
38-
console.log('CONFIGURATION ERROR: Missing filters config'.red);
47+
logger.error('CONFIGURATION ERROR: Missing filters config');
3948
return;
4049
}
4150

4251
bokorOptions.port = options.port || 7777; // bokor server port
4352
bokorOptions.staticFileLocation = options.staticFileLocation || 'static_files'; // bokor server static file location
4453
bokorOptions.secure = options.secure === undefined ? true : false;
4554

46-
// -- sepia config --------------
47-
// default bokor admin server on by default
48-
var sepia;
49-
if (options.admin === false) {
50-
sepia = require('./sepia');
51-
} else {
52-
sepia = require('./sepia').withSepiaServer();
53-
}
5455

5556
sepia.configure({
5657
verbose: true,
@@ -120,8 +121,8 @@ function start(options) {
120121
host: serverConfig.url
121122
}
122123
}, function(e) {
123-
console.log('[ERROR] proxying to endpoint: '.red + serverConfig.url);
124-
console.log(e);
124+
logger.error({ url: serverConfig.url }, 'proxying to endpoint');
125+
logger.error({ err: e });
125126
res.send(JSON.stringify({ bokorProxyError: 1 }));
126127
});
127128
});
@@ -131,7 +132,7 @@ function start(options) {
131132

132133
return new Promise(function (resolve) {
133134
server.listen(server.get('port'), function() {
134-
console.log('bokor'.red + ' server'.blue + ' rolled '.green.bold + 'lucky '.blue + server.get('port'));
135+
logger.info({ port: server.get('port') }, 'bokor listening');
135136
resolve(server);
136137
});
137138
});

lib/sepia/README.md

-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# This is a heavily modified version of sepia for bokor
22
# Thanks linkedin for the inspiration and code!
33

4-
5-
6-
7-
8-
94
# sepia - the way things used to be
105

116
Sepia is a VCR-like module for node.js that records HTTP interactions, then

lib/sepia/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function shutdown(next) {
5959
}
6060

6161
var sepiaUtil = require('./src/util');
62+
module.exports.logger = sepiaUtil.internal.log;
6263
module.exports.filter = sepiaUtil.addFilter;
6364
module.exports.substitute = sepiaUtil.addSubstitution;
6465
module.exports.fixtureDir = sepiaUtil.setFixtureDir;

lib/sepia/src/logger.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
var bunyan = require('bunyan');
2+
3+
const logger = bunyan.createLogger({
4+
name: 'bokor',
5+
});
6+
7+
module.exports = logger;

lib/sepia/src/util.js

+17-37
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,9 @@ var url = require('url');
1717
var path = require('path');
1818
var crypto = require('crypto');
1919
var fs = require('fs');
20+
var logger = require('./logger');
2021
var Levenshtein = require('levenshtein');
2122

22-
const COLOR_RESET = '\033[0m';
23-
const COLOR_RED_BOLD = '\033[1;31m';
24-
const COLOR_GREEN_BOLD = '\033[1;32m';
25-
const COLOR_BLUE_BOLD = '\033[1;34m';
26-
2723
// -- GLOBAL STATE HANDLING ----------------------------------------------------
2824

2925
var globalOptions = {};
@@ -220,18 +216,6 @@ function usesGlobalFixtures(reqUrl) {
220216

221217
// -- LOGGING ------------------------------------------------------------------
222218

223-
function log(color, args) {
224-
if (!globalOptions.verbose) {
225-
return;
226-
}
227-
228-
var args = Array.prototype.slice.call(args);
229-
args.unshift(color);
230-
args.push(COLOR_RESET);
231-
232-
console.log.apply(console, args);
233-
}
234-
235219
function logFixtureStatus(filename, filenameParts) {
236220
if (!globalOptions.verbose) {
237221
return;
@@ -240,19 +224,17 @@ function logFixtureStatus(filename, filenameParts) {
240224
filename = filename + '.headers';
241225

242226
if (fs.existsSync(filename)) {
243-
log(COLOR_GREEN_BOLD, [
244-
'\n ====[ cache hit ]====\n',
245-
filenameParts, '\n',
246-
'filename:', filename, '\n',
247-
'======================\n'
248-
]);
227+
logger.info({
228+
cache: 'hit',
229+
filenameParts: filenameParts,
230+
filename: filename,
231+
});
249232
} else {
250-
log(COLOR_RED_BOLD, [
251-
'\n ====[ cache miss ]====\n',
252-
filenameParts, '\n',
253-
'filename:', filename, '\n',
254-
'======================\n'
255-
]);
233+
logger.info({
234+
cache: 'miss',
235+
filenameParts: filenameParts,
236+
filename: filename,
237+
});
256238
}
257239
}
258240

@@ -262,13 +244,11 @@ function logFixtureDebugStatus(filename, bestMatchingFixture, fileHash) {
262244
}
263245

264246
// Print the hashParts
265-
log(COLOR_BLUE_BOLD, [
266-
'\n ==== Best matching Fixture ====\n',
267-
'to :', filename, '\n',
268-
'filename:', bestMatchingFixture, '\n\n',
269-
'hashParts:', fileHash, '\n',
270-
'======================\n'
271-
]);
247+
logger.info({
248+
to: filename,
249+
filename: bestMatchingFixture,
250+
hashParts: fileHash,
251+
});
272252
}
273253

274254
// -- FILENAME CONSTRUCTION ----------------------------------------------------
@@ -476,7 +456,7 @@ module.exports.internal.mkdirpSync = mkdirpSync;
476456
module.exports.internal.filterByWhitelist = filterByWhitelist;
477457
module.exports.internal.usesGlobalFixtures = usesGlobalFixtures;
478458
module.exports.internal.touchOnHit = touchOnHit;
479-
module.exports.internal.log = log;
459+
module.exports.internal.log = logger;
480460
module.exports.internal.logFixtureStatus = logFixtureStatus;
481461
module.exports.internal.logFixtureDebugStatus = logFixtureDebugStatus;
482462
module.exports.internal.parseCookiesNames = parseCookiesNames;

0 commit comments

Comments
 (0)