chore(logging): simplify format definition, do nothing in test

This commit is contained in:
WebStreamr 2025-05-12 09:51:34 +00:00
parent 3c76e182ed
commit 13520aa194
No known key found for this signature in database
3 changed files with 8 additions and 9 deletions

View file

@ -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}`),
),
}),
],

View file

@ -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' };

View file

@ -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<string, string>;
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
}