Skip to content
Snippets Groups Projects
Commit 214648e4 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

Fix #303 Live logs

parent 1e0faefb
Branches
Tags
No related merge requests found
...@@ -10,10 +10,15 @@ module.exports = { ...@@ -10,10 +10,15 @@ module.exports = {
INSTANCE_NAME: getDomain(opts.mdb), INSTANCE_NAME: getDomain(opts.mdb),
INSTANCE_HOME: getHomePath(opts.mdb, opts.home), INSTANCE_HOME: getHomePath(opts.mdb, opts.home),
INSTANCE_HOMELOG_FILE: getLogsPath(opts.mdb, opts.home),
getHome: (profile, dir) => getHomePath(profile, dir) getHome: (profile, dir) => getHomePath(profile, dir)
}; };
function getLogsPath(profile, dir) {
return path.join(getHomePath(profile, dir), 'ucoin.log');
}
function getHomePath(profile, dir) { function getHomePath(profile, dir) {
return path.normalize(getUserHome(dir) + '/') + getDomain(profile); return path.normalize(getUserHome(dir) + '/') + getDomain(profile);
} }
......
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
var directory = require('../app/lib/directory'); var directory = require('../app/lib/directory');
var path = require('path'); var path = require('path');
var Tail = require('always-tail');
var fs = require('fs');
var util = require('util');
var daemon = require("daemonize2").setup({ var daemon = require("daemonize2").setup({
main: "ucoind", main: "ucoind",
...@@ -20,6 +23,19 @@ switch (process.argv[2]) { ...@@ -20,6 +23,19 @@ switch (process.argv[2]) {
daemon.stop(); daemon.stop();
break; 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": case "restart":
daemon.stop(function(err) { daemon.stop(function(err) {
err && console.error(err); err && console.error(err);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
"url": "https://github.com/ucoin-io/ucoin/issues" "url": "https://github.com/ucoin-io/ucoin/issues"
}, },
"dependencies": { "dependencies": {
"always-tail": "0.2.0",
"async": "0.2.9", "async": "0.2.9",
"bindings": "1.2.1", "bindings": "1.2.1",
"co": "4.6.0", "co": "4.6.0",
......
...@@ -35,7 +35,7 @@ ucoind() { ...@@ -35,7 +35,7 @@ ucoind() {
# UCOIN DAEMON MANAGEMENT # UCOIN DAEMON MANAGEMENT
#--------------------------------- #---------------------------------
start|stop|restart) start|stop|restart|logs)
$NODE "$UCOIN_DIR/bin/daemon" $* $NODE "$UCOIN_DIR/bin/daemon" $*
;; ;;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment