-
Notifications
You must be signed in to change notification settings - Fork 23
Debugging
Eduardo Bouças edited this page Feb 5, 2020
·
1 revision
All plugin methods receive a debug
named parameter. This is a function that uses the debug module and it can be used to show additional information about the application execution, which may be useful when debugging.
In the example below, we're building a source plugin that retrieves entries from a remote API. Right after we get the entries from the API, we use debug
to inspect its response.
module.exports.bootstrap = async ({
debug,
getPluginContext,
log,
options,
refresh,
setPluginContext
}) => {
const context = getPluginContext();
const { data: entries } = await axios.get(
"https://jsonplaceholder.typicode.com/posts"
);
debug("Fetched entries: %O", entries);
setPluginContext({
entries
});
}
If you run the application normally, this information will not be shown. But you can change that by running Sourcebit with a DEBUG
environment variable containing the right namespace (which works as a wildcard).
Each plugin contains its own namespace in the format plugin:<name of the plugin>
(e.g. plugin:sourcebit-source-contentful
).
# Show debug information for the Contentful source plugin
DEBUG=plugin:sourcebit-source-contentful sourcebit fetch
# Show debug information for all plugins
DEBUG=plugin:* sourcebit fetch
# Show debug information for everything (plugins + core app)
DEBUG=* sourcebit fetch