Skip to content

Commit

Permalink
feat(log): ghost log command
Browse files Browse the repository at this point in the history
closes #42
- read bunyan log outputted by ghost
- deps: slice-file@1.0.0
- deps: ghost-ignition@2.8.10 (used for the PrettyStream)
  • Loading branch information
acburdine committed Mar 16, 2017
1 parent f827ea4 commit 7e1a29a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 6 deletions.
17 changes: 17 additions & 0 deletions lib/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,23 @@ module.exports = {
}].concat(advancedOptions)
},

log: {
description: 'view logs of a running ghost process',

arguments: ['name'],
options: [{
name: 'number',
alias: 'n',
description: 'Number of lines to view',
defaultValue: 20
}, {
name: 'follow',
alias: 'f',
description: 'Follow the log file (similar to `tail -f`)',
flag: true
}]
},

ls: {
description: 'view running ghost processes'
},
Expand Down
49 changes: 49 additions & 0 deletions lib/commands/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
'use strict';
const path = require('path');
const includes = require('lodash/includes');
const sliceFile = require('slice-file');
const PrettyStream = require('ghost-ignition/lib/logging/PrettyStream');

const errors = require('../errors');
const Config = require('../utils/config');

module.exports.execute = function execute(name, options) {
let systemConfig = Config.load('system');
let instance = systemConfig.get(`instances.${name}`);

if (!instance) {
throw new errors.SystemError(`Ghost instance '${name}' does not exist`);
}

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

let instanceConfig = Config.load(instance.mode);

// Check if logging file transport is set in config
if (!includes(instanceConfig.get('logging.transports', []), 'file')) {
// TODO: fallback to process manager log retrieval?
throw new errors.ConfigError({
configKey: 'logging.transports',
configValue: instanceConfig.get('logging.transports').join(', '),
message: 'You have excluded file logging in your ghost config.' +
'Please add it to your transport config to use this command.',
environment: instance.mode
});
return;
}

let logFileName = path.join(process.cwd(), 'content/logs', `${instance.url.replace(/[^\w]/gi, '_')}_${instance.mode}.log`);
let slice = sliceFile(logFileName);
let prettyStream = new PrettyStream();

prettyStream.pipe(this.ui.stdout);

if (options.follow) {
slice.follow(-options.number).pipe(prettyStream);
return;
} else {
slice.slice(-options.number).pipe(prettyStream);
}
};
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"execa": "0.6.1",
"fkill": "4.1.0",
"fs-extra": "2.1.1",
"ghost-ignition": "^2.8.10",
"greenlock-cli": "2.2.6",
"inquirer": "3.0.6",
"knex-migrator": "2.0.16",
Expand All @@ -58,6 +59,7 @@
"rxjs": "5.2.0",
"semver": "5.3.0",
"shasum": "1.0.2",
"slice-file": "1.0.0",
"strip-ansi": "3.0.1",
"symlink-or-copy": "1.1.8",
"update-notifier": "2.1.0",
Expand Down
46 changes: 40 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1244,9 +1244,9 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

ghost-ignition@^2.8.2:
version "2.8.9"
resolved "https://registry.yarnpkg.com/ghost-ignition/-/ghost-ignition-2.8.9.tgz#8cb2ab812ce5f8e803c3cca869176c6dd0e0098b"
ghost-ignition@^2.8.10, ghost-ignition@^2.8.2:
version "2.8.10"
resolved "https://registry.yarnpkg.com/ghost-ignition/-/ghost-ignition-2.8.10.tgz#7bde7d3d7d87790736f9991fb4f497154e56db14"
dependencies:
bunyan "1.8.5"
bunyan-loggly "1.1.0"
Expand All @@ -1257,8 +1257,8 @@ ghost-ignition@^2.8.2:
lodash "^4.16.4"
moment "^2.15.2"
nconf "0.8.4"
node-uuid "1.4.7"
prettyjson "1.1.3"
uuid "^3.0.0"

glob-base@^0.3.0:
version "0.3.0"
Expand Down Expand Up @@ -1516,6 +1516,10 @@ inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1:
version "2.0.3"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de"

inherits@~1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/inherits/-/inherits-1.0.2.tgz#ca4309dadee6b54cc0b8d247e8d7c7a0975bdc9b"

ini@^1.3.0, ini@^1.3.4, ini@~1.3.0:
version "1.3.4"
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e"
Expand Down Expand Up @@ -2346,7 +2350,7 @@ node-pre-gyp@~0.6.31:
tar "~2.2.1"
tar-pack "~3.3.0"

node-uuid@1.4.7, node-uuid@~1.4.7:
node-uuid@~1.4.7:
version "1.4.7"
resolved "https://registry.yarnpkg.com/node-uuid/-/node-uuid-1.4.7.tgz#6da5a17668c4b3dd59623bda11cf7fa4c1f60a6f"

Expand Down Expand Up @@ -2678,6 +2682,15 @@ readable-stream@1.1.14, readable-stream@^1.1.12:
isarray "0.0.1"
string_decoder "~0.10.x"

"readable-stream@>=1.0.33-1 <1.1.0-0":
version "1.0.34"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.0.34.tgz#125820e34bc842d2f2aaafafe4c2916ee32c157c"
dependencies:
core-util-is "~1.0.0"
inherits "~2.0.1"
isarray "0.0.1"
string_decoder "~0.10.x"

readable-stream@^2.0.0, "readable-stream@^2.0.0 || ^1.1.13", readable-stream@^2.0.5, readable-stream@^2.2.2:
version "2.2.5"
resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.2.5.tgz#a0b187304e05bab01a4ce2b4cc9c607d5aa1d606"
Expand Down Expand Up @@ -3045,6 +3058,14 @@ slice-ansi@0.0.4:
version "0.0.4"
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-0.0.4.tgz#edbf8903f66f7ce2f8eafd6ceed65e264c831b35"

slice-file@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/slice-file/-/slice-file-1.0.0.tgz#8b6c79d0a50c3fc3c1159957478426443a9000b8"
dependencies:
inherits "~1.0.0"
split2 "^0.2.1"
through2 "^0.6.5"

slide@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/slide/-/slide-1.1.6.tgz#56eb027d65b4d2dce6cb2e2d32c4d4afc9e1d707"
Expand Down Expand Up @@ -3085,6 +3106,12 @@ spdx-license-ids@^1.0.2:
version "1.2.2"
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57"

split2@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/split2/-/split2-0.2.1.tgz#02ddac9adc03ec0bb78c1282ec079ca6e85ae900"
dependencies:
through2 "~0.6.1"

sprintf-js@~1.0.2:
version "1.0.3"
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
Expand Down Expand Up @@ -3273,6 +3300,13 @@ text-table@~0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"

through2@^0.6.5, through2@~0.6.1:
version "0.6.5"
resolved "https://registry.yarnpkg.com/through2/-/through2-0.6.5.tgz#41ab9c67b29d57209071410e1d7a7a968cd3ad48"
dependencies:
readable-stream ">=1.0.33-1 <1.1.0-0"
xtend ">=4.0.0 <4.1.0-0"

through@^2.3.6:
version "2.3.8"
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
Expand Down Expand Up @@ -3516,7 +3550,7 @@ xdg-basedir@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/xdg-basedir/-/xdg-basedir-3.0.0.tgz#496b2cc109eca8dbacfe2dc72b603c17c5870ad4"

xtend@^4.0.0:
"xtend@>=4.0.0 <4.1.0-0", xtend@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af"

Expand Down

0 comments on commit 7e1a29a

Please sign in to comment.