diff --git a/app/lib/directory.js b/app/lib/directory.js index 4627c1e23d4defc700fdce7bece8cfeaa38cb41d..dcf61945081213c71465882a82c271357b2acfcd 100644 --- a/app/lib/directory.js +++ b/app/lib/directory.js @@ -10,10 +10,15 @@ module.exports = { INSTANCE_NAME: getDomain(opts.mdb), INSTANCE_HOME: getHomePath(opts.mdb, opts.home), + INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home), getHome: (profile, dir) => getHomePath(profile, dir) }; +function getLogsPath(profile, dir) { + return path.join(getHomePath(profile, dir), 'ucoin.log'); +} + function getHomePath(profile, dir) { return path.normalize(getUserHome(dir) + '/') + getDomain(profile); } diff --git a/app/lib/sanitize.js b/app/lib/sanitize.js index 5fa468542434dcd20d1149700933f6751a1a3753..e339b7aadd79fe07e669e739ea4e3c7dd1a371a8 100644 --- a/app/lib/sanitize.js +++ b/app/lib/sanitize.js @@ -56,7 +56,7 @@ module.exports = function sanitize (json, contract) { // Test json member type let tjson = typeof json[prop]; if (~['Array', 'Object'].indexOf(t)) { - if (tjson == 'object') { + if (tjson == 'object' && json[prop] !== null) { tjson = json[prop].length == undefined ? 'Object' : 'Array'; } } @@ -87,7 +87,7 @@ module.exports = function sanitize (json, contract) { } } // Recursivity - if (t == 'Object') { + if (t == 'Object' && json[prop] !== null) { json[prop] = sanitize(json[prop], contract[prop]); } } diff --git a/bin/daemon b/bin/daemon index 051bd70ecaa1c77a82c13370920e09aa352430c0..381bd8482d5d0848ab65d65946dba89095090c9c 100755 --- a/bin/daemon +++ b/bin/daemon @@ -3,6 +3,9 @@ var directory = require('../app/lib/directory'); var path = require('path'); +var Tail = require('always-tail'); +var fs = require('fs'); +var util = require('util'); var daemon = require("daemonize2").setup({ main: "ucoind", @@ -20,6 +23,19 @@ switch (process.argv[2]) { daemon.stop(); break; + case "logs": + let stats = fs.statSync(directory.INSTANCE_HOMELOG_FILE); + let fileSizeInBytes = stats.size; + let lastLines = 0.995 * fileSizeInBytes; + var tail = new Tail(directory.INSTANCE_HOMELOG_FILE, '\n', { + interval: 5, + start: Math.max(0, lastLines) + }); + tail.on("line", function(data) { + console.log(data); + }); + break; + case "restart": daemon.stop(function(err) { err && console.error(err); diff --git a/install.sh b/install.sh index 2a5b38a6e85cc303d1ef438926b6c52d959ac973..862795f7d9bfc85293daa4dc1bdfa3b6e6855ea5 100644 --- a/install.sh +++ b/install.sh @@ -11,7 +11,7 @@ if [ -z "$UCOIN_DIR" ]; then fi ucoin_latest_version() { - echo "v0.13.1" + echo "v0.13.2" } ucoin_repo_url() { diff --git a/package.json b/package.json index 06b6c7f9b15addfc8239113c4d04b980234fe686..12d5f6e6a005ce30ac4e14d18583dae9c36a3a01 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ucoin", - "version": "0.13.1", + "version": "0.13.2", "engines": { "node": ">=4.2.0", "npm": ">=2.11" @@ -33,6 +33,7 @@ "url": "https://github.com/ucoin-io/ucoin/issues" }, "dependencies": { + "always-tail": "0.2.0", "async": "0.2.9", "bindings": "1.2.1", "co": "4.6.0", diff --git a/test/integration/branches.js b/test/integration/branches.js index e35399de231e9d33444d46bfd9296a1557dc1e13..41fd23de63d089d0e8045f72130e4a58bfdb7897 100644 --- a/test/integration/branches.js +++ b/test/integration/branches.js @@ -225,7 +225,7 @@ describe("Branches", function() { it('should have a 3 blocks fork window size', function() { return expectAnswer(rp('http://127.0.0.1:7778/node/summary', { json: true }), function(res) { res.should.have.property('ucoin').property('software').equal('ucoind'); - res.should.have.property('ucoin').property('version').equal('0.13.1'); + res.should.have.property('ucoin').property('version').equal('0.13.2'); res.should.have.property('ucoin').property('forkWindowSize').equal(3); }); }); diff --git a/ucoin.sh b/ucoin.sh index 6cf02408bf769ce65caee7ca172b2b42469a5ac8..a13c1ddfb7316cccf89178bca53cc3f13396f1ea 100755 --- a/ucoin.sh +++ b/ucoin.sh @@ -35,7 +35,7 @@ ucoind() { # UCOIN DAEMON MANAGEMENT #--------------------------------- - start|stop|restart) + start|stop|restart|logs) $NODE "$UCOIN_DIR/bin/daemon" $* ;;