Skip to content

Commit f5a9111

Browse files
committed
fix(log): don't error out if the log file doesn't exist
closes #303
1 parent 43ceff1 commit f5a9111

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/commands/log.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
'use strict';
2+
const fs = require('fs-extra');
23
const path = require('path');
34
const includes = require('lodash/includes');
45
const lastLines = require('read-last-lines');
@@ -21,10 +22,6 @@ class LogCommand extends Command {
2122
return Promise.reject(new errors.SystemError(`Ghost instance '${argv.name}' does not exist`));
2223
}
2324

24-
// Change into the cwd of the running ghost instance so we can do things
25-
// relative to that
26-
process.chdir(instance.dir);
27-
2825
if (instance.running) {
2926
instance.loadRunningEnvironment();
3027
}
@@ -42,9 +39,17 @@ class LogCommand extends Command {
4239
}));
4340
}
4441

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

45+
if (!fs.existsSync(logFileName)) {
46+
if (argv.follow) {
47+
this.ui.log('Log file has not been created yet, therefore the follow option won\'t work', 'yellow');
48+
}
49+
50+
return Promise.resolve();
51+
}
52+
4853
prettyStream.on('error', (error) => {
4954
if (!(error instanceof SyntaxError)) {
5055
throw error;

0 commit comments

Comments
 (0)