Conversation
bcc8f4e to
ca03e8b
Compare
add pino and winston
ca03e8b to
82f2c92
Compare
more changes due to pino and winston
| All Crawlee logging goes through the <ApiLink to="core/interface/CrawleeLogger">`CrawleeLogger`</ApiLink> interface. To plug in your own logger, extend the <ApiLink to="core/class/BaseCrawleeLogger">`BaseCrawleeLogger`</ApiLink> abstract class and implement two methods: | ||
|
|
||
| - **`logWithLevel(level, message, data)`** — dispatches a log message to your logging library. The `level` parameter uses <ApiLink to="core/enum/LogLevel">`LogLevel`</ApiLink> constants (`ERROR = 1`, `SOFT_FAIL = 2`, `WARNING = 3`, `INFO = 4`, `DEBUG = 5`, `PERF = 6`). Map these to your logger's native levels. | ||
| - **`createChild(options)`** — creates a child logger instance. Crawlee creates child loggers with prefixes (e.g. `CheerioCrawler`, `AutoscaledPool`, `SessionPool`) so each internal component is easily identifiable in the output. |
There was a problem hiding this comment.
Out of curiosity - why does the implementer need to implement this method?
Describing the fields on the options type (or adding a link to the API docs) might clarify this a little.
There was a problem hiding this comment.
yes, this deserves more clarity. main reason for createChild is we use child loggers on multiple places.
docs/guides/custom-logger/pino.ts
Outdated
|
|
||
| logWithLevel(level: number, message: string, data?: Record<string, unknown>): void { | ||
| const pinoLevel = CRAWLEE_TO_PINO[level] ?? 'info'; | ||
| const prefix = this.getOptions().prefix; |
There was a problem hiding this comment.
It seems the prefix option requires some special handling.
Can we / is it worth mentioning this somewhere in the guide? Are there any other options fields that require special care?
There was a problem hiding this comment.
this is good catch, it is not needed. In crawlee we never use prefix directly with log function, we use prefix only through createChild (and then it is handled automatically by child instance).
|
|
||
| All Crawlee logging goes through the <ApiLink to="core/interface/CrawleeLogger">`CrawleeLogger`</ApiLink> interface. To plug in your own logger, extend the <ApiLink to="core/class/BaseCrawleeLogger">`BaseCrawleeLogger`</ApiLink> abstract class and implement two methods: | ||
|
|
||
| - **`logWithLevel(level, message, data)`** — dispatches a log message to your logging library. The `level` parameter uses <ApiLink to="core/enum/LogLevel">`LogLevel`</ApiLink> constants (`ERROR = 1`, `SOFT_FAIL = 2`, `WARNING = 3`, `INFO = 4`, `DEBUG = 5`, `PERF = 6`). Map these to your logger's native levels. |
There was a problem hiding this comment.
Same here, can we have a description of what message and data types are (and how do these differ)?
janbuchar
left a comment
There was a problem hiding this comment.
Take care of Jindra's comments. LGTM otherwise.
closes #3460