Feature/add context to logger (#745)

* Add contexts

* Update changelog
pull/747/head
Thomas Kaul 3 years ago committed by GitHub
parent 718b0de0a7
commit e4908b51aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Added
- Added the contexts to the logger commands
## 1.124.0 - 06.03.2022 ## 1.124.0 - 06.03.2022
### Added ### Added

@ -42,7 +42,7 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
done(null, user); done(null, user);
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'GoogleStrategy');
done(error, false); done(error, false);
} }
} }

@ -95,7 +95,7 @@ export class WebAuthService {
}; };
verification = await verifyRegistrationResponse(opts); verification = await verifyRegistrationResponse(opts);
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'WebAuthService');
throw new InternalServerErrorException(error.message); throw new InternalServerErrorException(error.message);
} }
@ -193,7 +193,7 @@ export class WebAuthService {
}; };
verification = verifyAuthenticationResponse(opts); verification = verifyAuthenticationResponse(opts);
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'WebAuthService');
throw new InternalServerErrorException({ error: error.message }); throw new InternalServerErrorException({ error: error.message });
} }

@ -40,7 +40,7 @@ export class ImportController {
userId: this.request.user.id userId: this.request.user.id
}); });
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, ImportController);
throw new HttpException( throw new HttpException(
{ {

@ -144,7 +144,7 @@ export class InfoService {
const contributors = await get(); const contributors = await get();
return contributors?.length; return contributors?.length;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'InfoService');
return undefined; return undefined;
} }
@ -165,7 +165,7 @@ export class InfoService {
const { stargazers_count } = await get(); const { stargazers_count } = await get();
return stargazers_count; return stargazers_count;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'InfoService');
return undefined; return undefined;
} }

@ -458,7 +458,8 @@ export class PortfolioCalculatorNew {
); );
} else if (!currentPosition.quantity.eq(0)) { } else if (!currentPosition.quantity.eq(0)) {
Logger.warn( Logger.warn(
`Missing initial value for symbol ${currentPosition.symbol} at ${currentPosition.firstBuyDate}` `Missing initial value for symbol ${currentPosition.symbol} at ${currentPosition.firstBuyDate}`,
'PortfolioCalculatorNew'
); );
hasErrors = true; hasErrors = true;
} }
@ -523,7 +524,8 @@ export class PortfolioCalculatorNew {
} catch (error) { } catch (error) {
Logger.error( Logger.error(
`Failed to fetch info for date ${startDate} with exception`, `Failed to fetch info for date ${startDate} with exception`,
error error,
'PortfolioCalculatorNew'
); );
return null; return null;
} }

@ -238,7 +238,10 @@ export class PortfolioCalculator {
if (!marketSymbolMap[nextDate]?.[item.symbol]) { if (!marketSymbolMap[nextDate]?.[item.symbol]) {
invalidSymbols.push(item.symbol); invalidSymbols.push(item.symbol);
hasErrors = true; hasErrors = true;
Logger.warn(`Missing value for symbol ${item.symbol} at ${nextDate}`); Logger.warn(
`Missing value for symbol ${item.symbol} at ${nextDate}`,
'PortfolioCalculator'
);
continue; continue;
} }
let lastInvestment: Big = new Big(0); let lastInvestment: Big = new Big(0);
@ -270,7 +273,8 @@ export class PortfolioCalculator {
invalidSymbols.push(item.symbol); invalidSymbols.push(item.symbol);
hasErrors = true; hasErrors = true;
Logger.warn( Logger.warn(
`Missing value for symbol ${item.symbol} at ${currentDate}` `Missing value for symbol ${item.symbol} at ${currentDate}`,
'PortfolioCalculator'
); );
continue; continue;
} }
@ -514,7 +518,8 @@ export class PortfolioCalculator {
); );
} else if (!currentPosition.quantity.eq(0)) { } else if (!currentPosition.quantity.eq(0)) {
Logger.warn( Logger.warn(
`Missing initial value for symbol ${currentPosition.symbol} at ${currentPosition.firstBuyDate}` `Missing initial value for symbol ${currentPosition.symbol} at ${currentPosition.firstBuyDate}`,
'PortfolioCalculator'
); );
hasErrors = true; hasErrors = true;
} }
@ -581,7 +586,8 @@ export class PortfolioCalculator {
} catch (error) { } catch (error) {
Logger.error( Logger.error(
`Failed to fetch info for date ${startDate} with exception`, `Failed to fetch info for date ${startDate} with exception`,
error error,
'PortfolioCalculator'
); );
return null; return null;
} }

@ -72,7 +72,8 @@ export class SubscriptionController {
}); });
Logger.log( Logger.log(
`Subscription for user '${this.request.user.id}' has been created with a coupon for ${coupon.duration}` `Subscription for user '${this.request.user.id}' has been created with a coupon for ${coupon.duration}`,
'SubscriptionController'
); );
return { return {
@ -87,7 +88,10 @@ export class SubscriptionController {
req.query.checkoutSessionId req.query.checkoutSessionId
); );
Logger.log(`Subscription for user '${userId}' has been created via Stripe`); Logger.log(
`Subscription for user '${userId}' has been created via Stripe`,
'SubscriptionController'
);
res.redirect(`${this.configurationService.get('ROOT_URL')}/account`); res.redirect(`${this.configurationService.get('ROOT_URL')}/account`);
} }
@ -104,7 +108,7 @@ export class SubscriptionController {
userId: this.request.user.id userId: this.request.user.id
}); });
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'SubscriptionController');
throw new HttpException( throw new HttpException(
getReasonPhrase(StatusCodes.BAD_REQUEST), getReasonPhrase(StatusCodes.BAD_REQUEST),

@ -98,7 +98,7 @@ export class SubscriptionService {
return session.client_reference_id; return session.client_reference_id;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'SubscriptionService');
} }
} }

@ -95,7 +95,7 @@ export class SymbolService {
results.items = items; results.items = items;
return results; return results;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'SymbolService');
throw error; throw error;
} }

@ -40,7 +40,7 @@ export class DataGatheringService {
const isDataGatheringNeeded = await this.isDataGatheringNeeded(); const isDataGatheringNeeded = await this.isDataGatheringNeeded();
if (isDataGatheringNeeded) { if (isDataGatheringNeeded) {
Logger.log('7d data gathering has been started.'); Logger.log('7d data gathering has been started.', 'DataGatheringService');
console.time('data-gathering-7d'); console.time('data-gathering-7d');
await this.prismaService.property.create({ await this.prismaService.property.create({
@ -64,7 +64,7 @@ export class DataGatheringService {
where: { key: PROPERTY_LAST_DATA_GATHERING } where: { key: PROPERTY_LAST_DATA_GATHERING }
}); });
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'DataGatheringService');
} }
await this.prismaService.property.delete({ await this.prismaService.property.delete({
@ -73,7 +73,10 @@ export class DataGatheringService {
} }
}); });
Logger.log('7d data gathering has been completed.'); Logger.log(
'7d data gathering has been completed.',
'DataGatheringService'
);
console.timeEnd('data-gathering-7d'); console.timeEnd('data-gathering-7d');
} }
} }
@ -84,7 +87,10 @@ export class DataGatheringService {
}); });
if (!isDataGatheringLocked) { if (!isDataGatheringLocked) {
Logger.log('Max data gathering has been started.'); Logger.log(
'Max data gathering has been started.',
'DataGatheringService'
);
console.time('data-gathering-max'); console.time('data-gathering-max');
await this.prismaService.property.create({ await this.prismaService.property.create({
@ -108,7 +114,7 @@ export class DataGatheringService {
where: { key: PROPERTY_LAST_DATA_GATHERING } where: { key: PROPERTY_LAST_DATA_GATHERING }
}); });
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'DataGatheringService');
} }
await this.prismaService.property.delete({ await this.prismaService.property.delete({
@ -117,7 +123,10 @@ export class DataGatheringService {
} }
}); });
Logger.log('Max data gathering has been completed.'); Logger.log(
'Max data gathering has been completed.',
'DataGatheringService'
);
console.timeEnd('data-gathering-max'); console.timeEnd('data-gathering-max');
} }
} }
@ -128,7 +137,10 @@ export class DataGatheringService {
}); });
if (!isDataGatheringLocked) { if (!isDataGatheringLocked) {
Logger.log(`Symbol data gathering for ${symbol} has been started.`); Logger.log(
`Symbol data gathering for ${symbol} has been started.`,
'DataGatheringService'
);
console.time('data-gathering-symbol'); console.time('data-gathering-symbol');
await this.prismaService.property.create({ await this.prismaService.property.create({
@ -159,7 +171,7 @@ export class DataGatheringService {
where: { key: PROPERTY_LAST_DATA_GATHERING } where: { key: PROPERTY_LAST_DATA_GATHERING }
}); });
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'DataGatheringService');
} }
await this.prismaService.property.delete({ await this.prismaService.property.delete({
@ -168,7 +180,10 @@ export class DataGatheringService {
} }
}); });
Logger.log(`Symbol data gathering for ${symbol} has been completed.`); Logger.log(
`Symbol data gathering for ${symbol} has been completed.`,
'DataGatheringService'
);
console.timeEnd('data-gathering-symbol'); console.timeEnd('data-gathering-symbol');
} }
} }
@ -205,14 +220,17 @@ export class DataGatheringService {
}); });
} }
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'DataGatheringService');
} finally { } finally {
return undefined; return undefined;
} }
} }
public async gatherProfileData(aDataGatheringItems?: IDataGatheringItem[]) { public async gatherProfileData(aDataGatheringItems?: IDataGatheringItem[]) {
Logger.log('Profile data gathering has been started.'); Logger.log(
'Profile data gathering has been started.',
'DataGatheringService'
);
console.time('data-gathering-profile'); console.time('data-gathering-profile');
let dataGatheringItems = aDataGatheringItems?.filter( let dataGatheringItems = aDataGatheringItems?.filter(
@ -248,7 +266,8 @@ export class DataGatheringService {
} catch (error) { } catch (error) {
Logger.error( Logger.error(
`Failed to enhance data for symbol ${symbol} by ${dataEnhancer.getName()}`, `Failed to enhance data for symbol ${symbol} by ${dataEnhancer.getName()}`,
error error,
'DataGatheringService'
); );
} }
} }
@ -294,11 +313,18 @@ export class DataGatheringService {
} }
}); });
} catch (error) { } catch (error) {
Logger.error(`${symbol}: ${error?.meta?.cause}`); Logger.error(
`${symbol}: ${error?.meta?.cause}`,
error,
'DataGatheringService'
);
} }
} }
Logger.log('Profile data gathering has been completed.'); Logger.log(
'Profile data gathering has been completed.',
'DataGatheringService'
);
console.timeEnd('data-gathering-profile'); console.timeEnd('data-gathering-profile');
} }
@ -361,7 +387,8 @@ export class DataGatheringService {
`Failed to gather data for symbol ${symbol} from ${dataSource} at ${format( `Failed to gather data for symbol ${symbol} from ${dataSource} at ${format(
currentDate, currentDate,
DATE_FORMAT DATE_FORMAT
)}.` )}.`,
'DataGatheringService'
); );
} }
@ -377,14 +404,15 @@ export class DataGatheringService {
} }
} catch (error) { } catch (error) {
hasError = true; hasError = true;
Logger.error(error); Logger.error(error, 'DataGatheringService');
} }
if (symbolCounter > 0 && symbolCounter % 100 === 0) { if (symbolCounter > 0 && symbolCounter % 100 === 0) {
Logger.log( Logger.log(
`Data gathering progress: ${( `Data gathering progress: ${(
this.dataGatheringProgress * 100 this.dataGatheringProgress * 100
).toFixed(2)}%` ).toFixed(2)}%`,
'DataGatheringService'
); );
} }
@ -474,7 +502,7 @@ export class DataGatheringService {
} }
public async reset() { public async reset() {
Logger.log('Data gathering has been reset.'); Logger.log('Data gathering has been reset.', 'DataGatheringService');
await this.prismaService.property.deleteMany({ await this.prismaService.property.deleteMany({
where: { where: {

@ -76,7 +76,7 @@ export class AlphaVantageService implements DataProviderInterface {
return response; return response;
} catch (error) { } catch (error) {
Logger.error(error, symbol); Logger.error(error, 'AlphaVantageService');
return {}; return {};
} }

@ -82,7 +82,7 @@ export class DataProviderService {
return r; return r;
}, {}); }, {});
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'DataProviderService');
} finally { } finally {
return response; return response;
} }

@ -69,7 +69,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
} }
}; };
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'GhostfolioScraperApiService');
} }
return {}; return {};
@ -110,7 +110,7 @@ export class GhostfolioScraperApiService implements DataProviderInterface {
} }
}; };
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'GhostfolioScraperApiService');
} }
return {}; return {};

@ -72,7 +72,7 @@ export class GoogleSheetsService implements DataProviderInterface {
[symbol]: historicalData [symbol]: historicalData
}; };
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'GoogleSheetsService');
} }
return {}; return {};
@ -121,7 +121,7 @@ export class GoogleSheetsService implements DataProviderInterface {
return response; return response;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'GoogleSheetsService');
} }
return {}; return {};

@ -125,7 +125,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
}; };
} }
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'RakutenRapidApiService');
} }
return {}; return {};
@ -160,7 +160,7 @@ export class RakutenRapidApiService implements DataProviderInterface {
const { fgi } = await get(); const { fgi } = await get();
return fgi; return fgi;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'RakutenRapidApiService');
return undefined; return undefined;
} }

@ -177,7 +177,8 @@ export class YahooFinanceService implements DataProviderInterface {
return response; return response;
} catch (error) { } catch (error) {
Logger.warn( Logger.warn(
`Skipping yahooFinance2.getHistorical("${aSymbol}"): [${error.name}] ${error.message}` `Skipping yahooFinance2.getHistorical("${aSymbol}"): [${error.name}] ${error.message}`,
'YahooFinanceService'
); );
return {}; return {};
@ -232,7 +233,7 @@ export class YahooFinanceService implements DataProviderInterface {
return response; return response;
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'YahooFinanceService');
return {}; return {};
} }
@ -296,7 +297,7 @@ export class YahooFinanceService implements DataProviderInterface {
}); });
} }
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'YahooFinanceService');
} }
return { items }; return { items };

@ -149,7 +149,8 @@ export class ExchangeRateDataService {
// Fallback with error, if currencies are not available // Fallback with error, if currencies are not available
Logger.error( Logger.error(
`No exchange rate has been found for ${aFromCurrency}${aToCurrency}` `No exchange rate has been found for ${aFromCurrency}${aToCurrency}`,
'ExchangeRateDataService'
); );
return aValue; return aValue;
} }

@ -54,11 +54,12 @@ export class TwitterBotService {
); );
Logger.log( Logger.log(
`Fear & Greed Index has been tweeted: https://twitter.com/ghostfolio_/status/${createdTweet.id}` `Fear & Greed Index has been tweeted: https://twitter.com/ghostfolio_/status/${createdTweet.id}`,
'TwitterBotService'
); );
} }
} catch (error) { } catch (error) {
Logger.error(error); Logger.error(error, 'TwitterBotService');
} }
} }
} }

Loading…
Cancel
Save