How to enable debugging output in Ghost

As I understand Ghost uses ghost-ignition to collect debugging information. How do I enable output when running ghost?

For example, yesterday I was debugging sources with node --inspect-brk current/index.js to figure out why tags page returns 404. The problem was that I didn’t have articles with such tags. I discovered that by inspecting an SQL query in models/plugins/has-posts.js:

const addHasPostsWhere = (tableName, config) => {
    const comparisonField = `${tableName}.id`;

    return function (qb) {
        return qb.whereIn(comparisonField, function () {
            const innerQb = this
                .whereRaw(`${config.joinTable}.${config.joinTo} = ${comparisonField}`)
                .join('posts', '', `${config.joinTable}.post_id`)
                .andWhere('posts.status', '=', 'published');

            debug(`QUERY has posts: ${innerQb.toSQL().sql}`);

            return innerQb;

But then I saw this he statement inside:

debug(`QUERY has posts: ${innerQb.toSQL().sql}`);

Which if enabled would help me figure out the problem faster. How can run Ghost to have an output from these debug statements?

We use the debug module inside of ignition.

You enable it by using a DEBUG environment variable, e.g.

# This will enable debugging for everything
DEBUG=* node current/index.js

And you can make it more specific like

# This will enable debugging for the `knex:query` debugger
DEBUG=knex:query node current/index.js

You can also comma separate the different debuggers to enable - you’ll find more information in the README of the package linked above!

1 Like

Awesome, thanks for the quick response! I’ll explore this functionality


I noticed the Ignition project has been archived but there’s no deprecation notice whatsoever.
What should be used for replacement?


If you’re looking for a way to log your local Ghost instance, I use the following command to start Ghost:

NODE_ENV=development ghost run

In addition to more verbose logging in the console, you can also use the {{log}} helper to output template data/contexts to the terminal.

I also can never remember this command :laughing: so I alias it in my terminal profile to gbug:

alias gbug="NODE_ENV=development ghost run"

A shortcut for this is ghost run -D!

If you need advanced debug (usually when you’re working on Ghost Core), as Fabien mentioned, you can use the DEBUG environment variable

1 Like

Awesome tip! Thank you @vikaspotluri123

Thanks for the answer.

So, in my code, I should replace these code occurrences with just console.*()?

Example: replace

const debug = require('ghost-ignition').debug('adapter');

// ...

debug('key:', var);


console.debug('key', var);


If you’re trying to use the Ignition-equivalent of debug, that’s part of @tryghost/debug. Note that this is just a thin wrapper around the debug package so if you don’t need those features, you can just use that.

Thanks a lot, I was able to remove the retired dependency and replace it by the new one.