Replace default logger

Hello, did anybody manage to completely replace the logs from Crawlee with console logs ? If yes, can you please share your implementation ?
2 Replies
Hall
Hall3mo ago
Someone will reply to you shortly. In the meantime, this might help:
optimistic-gold
optimistic-gold3mo ago
you can extend the log class and write your own _log method
/* eslint-disable @typescript-eslint/no-explicit-any */
import { LogLevel, Logger, LoggerOptions } from '@crawlee/playwright';

export class CustomLogger extends Logger {
constructor(
options: LoggerOptions,
) {
super(options);
}

override _log(
level: LogLevel,
message: string,
data?: any,
exception?: unknown,
opts?: Record<string, any>,
): void {

}
}
/* eslint-disable @typescript-eslint/no-explicit-any */
import { LogLevel, Logger, LoggerOptions } from '@crawlee/playwright';

export class CustomLogger extends Logger {
constructor(
options: LoggerOptions,
) {
super(options);
}

override _log(
level: LogLevel,
message: string,
data?: any,
exception?: unknown,
opts?: Record<string, any>,
): void {

}
}
then you can inject it into the global config
log.setOptions({
logger: new CustomLogger(log.getOptions()),
});
log.setOptions({
logger: new CustomLogger(log.getOptions()),
});

Did you find this page helpful?