Feature/add context to logger (#745)

* Add contexts

* Update changelog
pull/747/head
Thomas Kaul 2 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/),
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
### Added

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

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

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

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

@ -458,7 +458,8 @@ export class PortfolioCalculatorNew {
);
} else if (!currentPosition.quantity.eq(0)) {
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;
}
@ -523,7 +524,8 @@ export class PortfolioCalculatorNew {
} catch (error) {
Logger.error(
`Failed to fetch info for date ${startDate} with exception`,
error
error,
'PortfolioCalculatorNew'
);
return null;
}

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

@ -72,7 +72,8 @@ export class SubscriptionController {
});
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 {
@ -87,7 +88,10 @@ export class SubscriptionController {
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`);
}
@ -104,7 +108,7 @@ export class SubscriptionController {
userId: this.request.user.id
});
} catch (error) {
Logger.error(error);
Logger.error(error, 'SubscriptionController');
throw new HttpException(
getReasonPhrase(StatusCodes.BAD_REQUEST),

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

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

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

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

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

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

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

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

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

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

@ -54,11 +54,12 @@ export class TwitterBotService {
);
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) {
Logger.error(error);
Logger.error(error, 'TwitterBotService');
}
}
}

Loading…
Cancel
Save