crawlee-pino 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,28 @@
1
+ import { Logger as CrawleeLogger, LogLevel } from 'crawlee';
2
+ const LEVEL_CRAWLEE_TO_PINO = {
3
+ [LogLevel.SOFT_FAIL]: 'fatal',
4
+ [LogLevel.ERROR]: 'error',
5
+ [LogLevel.WARNING]: 'warn',
6
+ [LogLevel.INFO]: 'info',
7
+ [LogLevel.DEBUG]: 'debug',
8
+ [LogLevel.PERF]: 'trace',
9
+ [LogLevel.OFF]: 'silent',
10
+ };
11
+ const PREFIX_DELIMITER = ':';
12
+ export class CrawleePino extends CrawleeLogger {
13
+ constructor(options) {
14
+ super(options);
15
+ this.pino = options.pino;
16
+ }
17
+ _log(level, message, data, exception, options) {
18
+ const { prefix, suffix } = options || {};
19
+ let msg = message;
20
+ if (options === null || options === void 0 ? void 0 : options.prefix) {
21
+ msg = `${prefix}${PREFIX_DELIMITER} ${msg}`;
22
+ }
23
+ if (options === null || options === void 0 ? void 0 : options.suffix) {
24
+ msg = `${msg} ${suffix}`;
25
+ }
26
+ this.pino[LEVEL_CRAWLEE_TO_PINO[level]]({ data, exception }, msg);
27
+ }
28
+ }
@@ -0,0 +1,15 @@
1
+ import { Logger as CrawleeLogger, LogLevel } from 'crawlee';
2
+ import { type Logger as PinoLogger } from 'pino';
3
+ type Exception = Parameters<InstanceType<typeof CrawleeLogger>['_log']>[3];
4
+ interface LogOptions {
5
+ prefix: string;
6
+ suffix: string;
7
+ }
8
+ export declare class CrawleePino extends CrawleeLogger {
9
+ private pino;
10
+ constructor(options?: {
11
+ pino: PinoLogger;
12
+ });
13
+ _log(level: LogLevel, message: string, data?: any, exception?: Exception, options?: LogOptions): void;
14
+ }
15
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crawlee-pino",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "🌲 use Pino to log within Crawlee",
5
5
  "type": "module",
6
6
  "exports": {