diff --git a/app/lib/logger.ts b/app/lib/logger.ts index b1a5a0e330a766a66e974f268f349fd7245d12b1..0fe2865b849f4ea81e889697798118c1ab5f3fd6 100644 --- a/app/lib/logger.ts +++ b/app/lib/logger.ts @@ -15,6 +15,7 @@ const moment = require('moment'); const path = require('path'); const winston = require('winston'); +const directory = require('../lib/system/directory'); /*************** * CALLBACK LOGGER @@ -147,6 +148,11 @@ logger.unmute = () => { } } +/** + * Default logging path + */ +logger.addHomeLogs(directory.INSTANCE_HOME) + /** * Convenience function to get logger directly */ diff --git a/bin/duniter b/bin/duniter index 6394374389e297938dfe9cf0aa4221343cb48918..60946d8e66b60339c941fc107373764248fe9a38 100755 --- a/bin/duniter +++ b/bin/duniter @@ -2,27 +2,28 @@ "use strict"; const co = require('co'); -const duniter = require('../index'); -const stack = duniter.statics.autoStack(); +const logger = require("../app/lib/logger").NewLogger(); -return co(function*() { +// Specific errors handling +process.on('uncaughtException', (err) => { + // Dunno why this specific exception is not caught + if (err.code && err.code !== "EADDRNOTAVAIL" && err.code !== "EINVAL" && err.code !== "ENOENT") { + logger.error(err.stack || err.message || err); + process.exit(2); + } +}); - // Specific errors handling - process.on('uncaughtException', (err) => { - // Dunno why this specific exception is not caught - if (err.code !== "EADDRNOTAVAIL" && err.code !== "EINVAL" && err.code !== "ENOENT") { - duniter.statics.logger.error(err); - process.exit(2); - } - }); +return co(function*() { try { + const duniter = require('../index'); + const stack = duniter.statics.autoStack(); yield stack.executeStack(process.argv); // Everything went well, close Duniter quietly. process.exit(); } catch (e) { // If an unhandled error occured - duniter.statics.logger.error(e); + logger.error(e.stack || e.message || e); process.exit(1); } finally { // If we did not succeed to close before, force close with error.