-
-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
4 changed files
with
108 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters