<commit_before>'use strict';
const path = require('path');
const includes = require('lodash/includes');
const lastLines = require('read-last-lines');
const Tail = require('tail').Tail;
const Promise = require('bluebird');
const PrettyStream = require('ghost-ignition/lib/logging/PrettyStream');

const errors = require('../errors');
const Command = require('../command');

class LogCommand extends Command {
    run(argv) {
        if (!argv.name) {
            Command.checkValidInstall('log');
        }

        let instance = this.system.getInstance(argv.name);

        if (!instance) {
            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);

        instance.loadRunningEnvironment();

        // Check if logging file transport is set in config
        if (!includes(instance.config.get('logging.transports', []), 'file')) {
            // TODO: fallback to process manager log retrieval?
            return Promise.reject(new errors.ConfigError({
                config: {
                    'logging.transports': instance.config.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: this.system.environment
            }));
        }

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

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

        prettyStream.pipe(this.ui.stdout);
<commit_msg>fix(log): only load running environment if ghost is running<commit_after>'use strict';
const path = require('path');
const includes = require('lodash/includes');
const lastLines = require('read-last-lines');
const Tail = require('tail').Tail;
const Promise = require('bluebird');
const PrettyStream = require('ghost-ignition/lib/logging/PrettyStream');

const errors = require('../errors');
const Command = require('../command');

class LogCommand extends Command {
    run(argv) {
        if (!argv.name) {
            Command.checkValidInstall('log');
        }

        let instance = this.system.getInstance(argv.name);

        if (!instance) {
            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();
        }

        // Check if logging file transport is set in config
        if (!includes(instance.config.get('logging.transports', []), 'file')) {
            // TODO: fallback to process manager log retrieval?
            return Promise.reject(new errors.ConfigError({
                config: {
                    'logging.transports': instance.config.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: this.system.environment
            }));
        }

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

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

        prettyStream.pipe(this.ui.stdout);

{'fraction_non_alphanumeric': 0.1339641434262948, 'fraction_numerical': 0.0, 'mean_word_length': 2.341930116472546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4290435', 'n_tokens_mistral': 1024, 'n_tokens_neox': 993, 'n_words': 276}