From 13520aa194ae2847c395fb3381171d38c097287b Mon Sep 17 00:00:00 2001 From: WebStreamr <210764791+webstreamr@users.noreply.github.com> Date: Mon, 12 May 2025 09:51:34 +0000 Subject: [PATCH] chore(logging): simplify format definition, do nothing in test --- src/index.ts | 4 +--- src/utils/Fetcher.test.ts | 5 +++-- src/utils/Fetcher.ts | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/index.ts b/src/index.ts index 6283777..594ce30 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,9 +20,7 @@ const logger = winston.createLogger({ format: winston.format.combine( winston.format.cli(), winston.format.timestamp(), - winston.format.printf(({ level, message, timestamp }) => { - return `${timestamp} ${level}: ${message}`; - }), + winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`), ), }), ], diff --git a/src/utils/Fetcher.test.ts b/src/utils/Fetcher.test.ts index 477d57c..c7cdb3f 100644 --- a/src/utils/Fetcher.test.ts +++ b/src/utils/Fetcher.test.ts @@ -1,5 +1,6 @@ -import { Fetcher } from './Fetcher'; import makeFetchHappen from 'make-fetch-happen'; +import winston from 'winston'; +import { Fetcher } from './Fetcher'; import { Context } from '../types'; const mockedFetch = jest.fn(); @@ -10,7 +11,7 @@ jest.mock('make-fetch-happen', () => ({ }, })); -const fetcher = new Fetcher(makeFetchHappen.defaults()); +const fetcher = new Fetcher(makeFetchHappen.defaults(), winston.createLogger({ transports: [new winston.transports.Console({ level: 'nope' })] })); describe('fetch', () => { const ctx: Context = { ip: '127.0.0.1' }; diff --git a/src/utils/Fetcher.ts b/src/utils/Fetcher.ts index dd3c256..c7fb5b1 100644 --- a/src/utils/Fetcher.ts +++ b/src/utils/Fetcher.ts @@ -1,19 +1,19 @@ import { FetchInterface, FetchOptions } from 'make-fetch-happen'; import TTLCache from '@isaacs/ttlcache'; import UserAgent from 'user-agents'; -import { Logger, createLogger } from 'winston'; +import winston from 'winston'; import { Context } from '../types'; export class Fetcher { private readonly fetch: FetchInterface; - private readonly logger: Logger; + private readonly logger: winston.Logger; private readonly ipUserAgentCache: TTLCache; - constructor(fetch: FetchInterface, logger: Logger | undefined = undefined) { + constructor(fetch: FetchInterface, logger: winston.Logger) { this.fetch = fetch; - this.logger = logger || createLogger(); + this.logger = logger; this.ipUserAgentCache = new TTLCache({ max: 1024, ttl: 86400000 }); // 24h }