Apify

Apify and Crawlee Official Forum

b
F
A
J
A

How to extend log messages?

Are there any plans to extend Crawlee logger?
Ref: https://crawlee.dev/api/core/class/Logger

I found this to set the skipTime option
Plain Text
const Apify = require('apify');

const { utils: { log } } = Apify;

log.setOptions({
    logger: new log.LoggerText({ skipTime: false }),
});

but it doesn't seem to work. I got Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'log')

My code:
Plain Text
import Apify from 'apify'
const { utils: { log } } = Apify;

log.setOptions({
    logger: new log.LoggerText({ skipTime: false }),
});

// https://crawlee.dev/api/playwright-crawler/class/PlaywrightCrawler
const crawler = new PlaywrightCrawler(
    launchContext: {
        launchOptions: {
            headless: true,
            stealth: true,
            viewport: { width:600, height:300 }
        },
    },
    async requestHandler({ request, page, enqueueLinks, log }) {
        const title = await page.title();
        log.info(`Titre: ${title} Url: ${request.loadedUrl}`);
    }
t
1 comment
The reason is because utils is no longer exported from the apify package, therefore it is undefined. That's why you get the error of Cannot read 'log' of undefined. log doesn't exist on undefined.

Instead, you should import log from crawlee like this:

Plain Text
import { log, LoggerText } from 'crawlee';

log.setOptions({
    logger: new LoggerText({ skipTime: false }),
});
Add a reply
Sign up and join the conversation on Discord
Join