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
.distinct(`${config.joinTable}.${config.joinTo}`)
.select()
.from(config.joinTable)
.whereRaw(`${config.joinTable}.${config.joinTo} = ${comparisonField}`)
.join('posts', 'posts.id', `${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?
egg
July 31, 2019, 8:15am
2
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
eexit
April 19, 2022, 9:27am
4
maxkoretskyi:
ghost-ignition
Hello,
I noticed the Ignition project has been archived but there’s no deprecation notice whatsoever.
What should be used for replacement?
Thanks!
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 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
RyanF
April 19, 2022, 3:40pm
7
Awesome tip! Thank you @vikaspotluri123
eexit
April 26, 2022, 7:32am
8
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);
By:
console.debug('key', var);
Thanks!
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.
eexit
June 8, 2022, 8:35pm
10
Thanks a lot, I was able to remove the retired dependency and replace it by the new one.