diff --git a/cli.js b/cli.js index 95faf63..2e3b885 100755 --- a/cli.js +++ b/cli.js @@ -11,6 +11,7 @@ if (argv.help) { '', 'Options:', '--help Display this help message and exit', + '--verbose Enable logging', '--port The port to listen on (default: 4567)', '--path The path to use for the LevelDB store (in-memory by default)', '--createTableMs Amount of time tables stay in CREATING state (default: 500)', @@ -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) diff --git a/index.js b/index.js index 965daff..d0c457f 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ var http = require('http'), crypto = require('crypto'), crc32 = require('buffer-crc32'), + winston = require('winston'), validations = require('./validations'), db = require('./db') @@ -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) }) diff --git a/package.json b/package.json index 96ea2be..465d8ea 100644 --- a/package.json +++ b/package.json @@ -21,16 +21,17 @@ "author": "Michael Hart ", "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"