Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic logging that can be enabled with --verbose #10

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (argv.help) {
'',
'Options:',
'--help Display this help message and exit',
'--verbose Enable logging',
'--port <port> The port to listen on (default: 4567)',
'--path <path> The path to use for the LevelDB store (in-memory by default)',
'--createTableMs <ms> Amount of time tables stay in CREATING state (default: 500)',
Expand All @@ -21,4 +22,9 @@ if (argv.help) {
].join('\n'))
}

var winston = require('winston');
winston.cli();
winston.level = argv.verbose ? 'debug' : 'off';

require('./index.js')(argv).listen(argv.port || 4567)
winston.info('starting dynalite server on %d', argv.port || 4567)
7 changes: 6 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var http = require('http'),
crypto = require('crypto'),
crc32 = require('buffer-crc32'),
winston = require('winston'),
validations = require('./validations'),
db = require('./db')

Expand Down Expand Up @@ -191,8 +192,12 @@ function httpHandler(store, req, res) {
throw e
}

winston.debug('[action]', action, data);
actions[action](store, data, function(err, data) {
if (err && err.statusCode) return sendData(req, res, err.body, err.statusCode)
if (err && err.statusCode) {
winston.error(err.body);
return sendData(req, res, err.body, err.statusCode);
}
if (err) throw err
sendData(req, res, data)
})
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,17 @@
"author": "Michael Hart <michael.hart.au@gmail.com>",
"license": "MIT",
"dependencies": {
"async": "~0.2.9",
"big.js": "~2.4.1",
"buffer-crc32": "~0.2.1",
"levelup": "~0.18.2",
"memdown": "~0.7.0",
"lazy": "~1.0.11",
"level-sublevel": "~5.1.1",
"levelup": "~0.18.2",
"lock": "~0.0.4",
"lazy": "~1.0.11",
"memdown": "~0.7.0",
"minimist": "~0.0.5",
"once": "~1.3.0",
"async": "~0.2.9",
"big.js": "~2.4.1",
"minimist": "~0.0.5"
"winston": "~0.7.3"
},
"optionalDependencies": {
"leveldown": "~0.10.0"
Expand Down