From the Apify example docs, I can see that if you use console.log()
within handlePageFunction
, it is logged directly to the terminal console. The same is true for the Apify utils log
. For example:
handlePageFunction: async ({ request, page }) => {
console.log('This is logged to the terminal console');
log.info('So is this.')
...
}
However when I am defining my own functions inside handlePageFunction this, I cannot get anything logged to the terminal console. I expect the console.log is going to the browser console, but in Apify the browser window appears and disappears quickly. (It's also possible to use apify-cli which wouldn't even show a browser at all.)
handlePageFunction: async ({ request, page }) => {
...
const myFunction = () => {
console.log('This disappears into the ether.');
log.info('This causes the script to fail with error, "log is not defined"');
}
myFunction();
}
How do I use the Apify utils.log from within a nested javascript function?