Skip to content

Commit

Permalink
fix(log): don't error out if the log file doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
acburdine committed Jul 8, 2017
1 parent 43ceff1 commit 51434b8
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/commands/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
'use strict';
const fs = require('fs-extra');
const path = require('path');
const includes = require('lodash/includes');
const lastLines = require('read-last-lines');
Expand All @@ -21,10 +22,6 @@ class LogCommand extends Command {
return Promise.reject(new errors.SystemError(`Ghost instance '${argv.name}' does not exist`));
}

// Change into the cwd of the running ghost instance so we can do things
// relative to that
process.chdir(instance.dir);

if (instance.running) {
instance.loadRunningEnvironment();
}
Expand All @@ -42,9 +39,17 @@ class LogCommand extends Command {
}));
}

let logFileName = path.join(process.cwd(), 'content/logs', `${instance.config.get('url').replace(/[^\w]/gi, '_')}_${this.system.environment}.log`);
let logFileName = path.join(instance.dir, 'content/logs', `${instance.config.get('url').replace(/[^\w]/gi, '_')}_${this.system.environment}.log`);
let prettyStream = new PrettyStream();

if (!fs.existsSync(logFileName)) {
if (argv.follow) {
this.ui.log('Log file has not been created yet, therefore the follow option won\'t work', 'yellow');
}

return Promise.resolve();
}

prettyStream.on('error', (error) => {
if (!(error instanceof SyntaxError)) {
throw error;
Expand Down

0 comments on commit 51434b8

Please sign in to comment.