From 0d070c91dc8d4e4f04a17d63419c19a0d3e24b56 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 12 Jan 2015 08:16:08 -0800 Subject: [PATCH] Fix Aphlict logging Summary: Yeahhhhhhhh.... - Open a "stream", not a "steam". - Make error easier for users to understand. - Write to the log in debug mode so the issue is more apparent. Test Plan: - Started server with bad permissions, got usable error message. - Started server with good permissions, got logfile. Reviewers: joshuaspence, btrahan Reviewed By: btrahan Subscribers: Korvin, epriestley Differential Revision: https://secure.phabricator.com/D11339 --- .../PhabricatorAphlictManagementWorkflow.php | 4 +--- support/aphlict/server/aphlict_server.js | 24 ++++++++++++++++--- support/aphlict/server/lib/AphlictLog.js | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php b/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php index cc21d68d6f..59ba40b8a4 100644 --- a/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php +++ b/src/applications/aphlict/management/PhabricatorAphlictManagementWorkflow.php @@ -136,9 +136,7 @@ abstract class PhabricatorAphlictManagementWorkflow $server_argv[] = '--ssl-cert='.$ssl_cert; } - if (!$this->debug) { - $server_argv[] = '--log='.$log; - } + $server_argv[] = '--log='.$log; if ($this->clientHost) { $server_argv[] = '--client-host='.$this->clientHost; diff --git a/support/aphlict/server/aphlict_server.js b/support/aphlict/server/aphlict_server.js index 9649c50c8a..aa5784f16b 100644 --- a/support/aphlict/server/aphlict_server.js +++ b/support/aphlict/server/aphlict_server.js @@ -43,7 +43,25 @@ var debug = new JX.AphlictLog() var config = parse_command_line_arguments(process.argv); process.on('uncaughtException', function(err) { - debug.log('\n<<< UNCAUGHT EXCEPTION! >>>\n' + err.stack); + var context = null; + if ((err.code == 'EACCES') && + (err.path == config.log)) { + context = util.format( + 'Unable to open logfile ("%s"). Check that permissions are set ' + + 'correctly.', + err.path); + } + + var message = [ + '\n<<< UNCAUGHT EXCEPTION! >>>', + ]; + if (context) { + message.push(context); + } + message.push(err.stack); + + debug.log(message.join('\n\n')); + process.exit(1); }); @@ -69,8 +87,8 @@ if (ssl_config.enabled) { } // Add the logfile so we'll fail if we can't write to it. -if (config.logfile) { - debug.addLogfile(config.logfile); +if (config.log) { + debug.addLogfile(config.log); } // If we're just doing a configuration test, exit here before starting any diff --git a/support/aphlict/server/lib/AphlictLog.js b/support/aphlict/server/lib/AphlictLog.js index 73b9031194..15c7dbc719 100644 --- a/support/aphlict/server/lib/AphlictLog.js +++ b/support/aphlict/server/lib/AphlictLog.js @@ -20,7 +20,7 @@ JX.install('AphlictLog', { mode: 066 }; - var logfile = fs.createWriteSteam(path, options); + var logfile = fs.createWriteStream(path, options); this._writeToLogs.push(logfile);