Skip to content

Commit

Permalink
馃帹 transform console.log into logging (#8671)
Browse files Browse the repository at this point in the history
closes #8361

- the console.log are not appearing in the logs
- fix jscs
- remove chalk.green from ghost server
  • Loading branch information
kirrg001 authored and ErisDS committed Jul 11, 2017
1 parent b374112 commit e54d959
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 36 deletions.
48 changes: 22 additions & 26 deletions core/server/ghost-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ var debug = require('debug')('ghost:server'),
_ = require('lodash'),
errors = require('./errors'),
events = require('./events'),
logging = require('./logging'),
config = require('./config'),
utils = require('./utils'),
i18n = require('./i18n'),
i18n = require('./i18n'),
moment = require('moment');

/**
Expand Down Expand Up @@ -145,7 +146,7 @@ GhostServer.prototype.restart = function () {
* To be called after `stop`
*/
GhostServer.prototype.hammertime = function () {
console.log(chalk.green(i18n.t('notices.httpServer.cantTouchThis')));
logging.info(i18n.t('notices.httpServer.cantTouchThis'));

return Promise.resolve(this);
};
Expand Down Expand Up @@ -192,52 +193,47 @@ GhostServer.prototype.closeConnections = function () {
GhostServer.prototype.logStartMessages = function () {
// Startup & Shutdown messages
if (config.get('env') === 'production') {
console.log(
chalk.red('Currently running Ghost 1.0.0 Beta, this is NOT suitable for production! \n'),
chalk.white('Please switch to the stable branch. \n'),
chalk.white('More information on the Ghost 1.0.0 Beta at: ') + chalk.cyan('https://dev.ghost.org/1-0-0-beta') + '\n',
chalk.gray(i18n.t('notices.httpServer.ctrlCToShutDown'))
logging.error('\nCurrently running Ghost 1.0.0 Beta, this is NOT suitable for production!\n' +
chalk.white('Please switch to the stable branch. \n') +
chalk.white('More information on the Ghost 1.0.0 Beta at: ') + chalk.cyan('https://dev.ghost.org/1-0-0-beta') + '\n'
);

logging.info(i18n.t('notices.httpServer.ctrlCToShutDown'));
} else {
console.log(
chalk.yellow('Welcome to the Ghost 1.0.0 Beta - this version of Ghost is for development only.')
);
console.log(
chalk.green(i18n.t('notices.httpServer.ghostIsRunningIn', {env: config.get('env')})),
i18n.t('notices.httpServer.listeningOn'),
config.get('server').socket || config.get('server').host + ':' + config.get('server').port,
i18n.t('notices.httpServer.urlConfiguredAs', {url: utils.url.urlFor('home', true)}),
chalk.gray(i18n.t('notices.httpServer.ctrlCToShutDown'))
);
logging.warn('Welcome to the Ghost 1.0.0 Beta - this version of Ghost is for development only.');
logging.info(i18n.t('notices.httpServer.ghostIsRunningIn', {env: config.get('env')}));
logging.info(i18n.t('notices.httpServer.listeningOn', {
host: config.get('server').socket || config.get('server').host,
port: config.get('server').port
}));
logging.info(i18n.t('notices.httpServer.urlConfiguredAs', {url: utils.url.urlFor('home', true)}));
logging.info(i18n.t('notices.httpServer.ctrlCToShutDown'));
}

function shutdown() {
console.log(chalk.red(i18n.t('notices.httpServer.ghostHasShutdown')));
logging.warn(i18n.t('notices.httpServer.ghostHasShutdown'));

if (config.get('env') === 'production') {
console.log(
i18n.t('notices.httpServer.yourBlogIsNowOffline')
);
logging.warn(i18n.t('notices.httpServer.yourBlogIsNowOffline'));
} else {
console.log(
logging.warn(
i18n.t('notices.httpServer.ghostWasRunningFor'),
moment.duration(process.uptime(), 'seconds').humanize()
);
}

process.exit(0);
}

// ensure that Ghost exits correctly on Ctrl+C and SIGTERM
process.
removeAllListeners('SIGINT').on('SIGINT', shutdown).
removeAllListeners('SIGTERM').on('SIGTERM', shutdown);
process.removeAllListeners('SIGINT').on('SIGINT', shutdown).removeAllListeners('SIGTERM').on('SIGTERM', shutdown);
};

/**
* ### Log Shutdown Messages
*/
GhostServer.prototype.logShutdownMessages = function () {
console.log(chalk.red(i18n.t('notices.httpServer.ghostIsClosingConnections')));
logging.warn(i18n.t('notices.httpServer.ghostIsClosingConnections'));
};

module.exports = GhostServer;
14 changes: 7 additions & 7 deletions core/server/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,14 @@
"httpServer": {
"cantTouchThis": "Can't touch this",
"ghostIsRunning": "Ghost is running...",
"yourBlogIsAvailableOn": "\nYour blog is now available on {url}",
"ctrlCToShutDown": "\nCtrl+C to shut down",
"yourBlogIsAvailableOn": "Your blog is now available on {url}",
"ctrlCToShutDown": "Ctrl+C to shut down",
"ghostIsRunningIn": "Ghost is running in {env}...",
"listeningOn": "\nListening on",
"urlConfiguredAs": "\nUrl configured as: {url}",
"ghostHasShutdown": "\nGhost has shut down",
"yourBlogIsNowOffline": "\nYour blog is now offline",
"ghostWasRunningFor": "\nGhost was running for",
"listeningOn": "Listening on: {host}:{port}",
"urlConfiguredAs": "Url configured as: {url}",
"ghostHasShutdown": "Ghost has shut down",
"yourBlogIsNowOffline": "Your blog is now offline",
"ghostWasRunningFor": "Ghost was running for",
"ghostIsClosingConnections": "Ghost is closing connections"
},
"mail": {
Expand Down
7 changes: 4 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// # Ghost Startup
// Orchestrates the startup of Ghost when run from command line.
console.time('Ghost boot');

var debug = require('debug')('ghost:boot:index'),
var startTime = Date.now(),
debug = require('debug')('ghost:boot:index'),
ghost, express, logging, errors, utils, parentApp;

debug('First requires...');
Expand All @@ -25,7 +25,8 @@ ghost().then(function (ghostServer) {
debug('Starting Ghost');
// Let Ghost handle starting our server instance.
return ghostServer.start(parentApp).then(function afterStart() {
console.timeEnd('Ghost boot');
logging.info('Ghost boot', (Date.now() - startTime) / 1000 + 's');

// if IPC messaging is enabled, ensure ghost sends message to parent
// process on successful start
if (process.send) {
Expand Down

0 comments on commit e54d959

Please sign in to comment.