Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Sep 11, 2023
1 parent 8340db2 commit 4f7c988
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
8 changes: 8 additions & 0 deletions api/config/production.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
{
"db": {
"logging": [
"error",
"schema",
"info",
"log"
]
}
}
3 changes: 3 additions & 0 deletions api/src/modules/geo-coding/geo-coding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
const errors: any[] = [];
for (let i: number = 0; i < sourcingData.length; i++) {
const location: SourcingData = sourcingData[i];
this.logger.debug(
`Geocoding location: Country: ${location.locationCountryInput}, Address: ${location.locationAddressInput}, LAT: ${location.locationLatitude}, LONG: ${location.locationLongitude}`,
);
try {
if (location.locationType === LOCATION_TYPES.UNKNOWN) {
geoCodedSourcingData.push(
Expand Down
13 changes: 11 additions & 2 deletions api/src/modules/geo-coding/geocoders/cache.geocoder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Inject } from '@nestjs/common';
import { Inject, Logger } from '@nestjs/common';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import {
GeocodeArgs,
Expand All @@ -11,6 +11,8 @@ import { GoogleMapsGeocoder } from 'modules/geo-coding/geocoders/google-maps.geo
export const GEOCODING_CACHE_ENABLED: unique symbol = Symbol();

export class CacheGeocoder implements GeocoderInterface {
private logger: Logger = new Logger(CacheGeocoder.name);

constructor(
@Inject(GEOCODING_CACHE_ENABLED) private geocacheEnabled: boolean,
@Inject(GoogleMapsGeocoder) private backendGeocoder: GeocoderInterface,
Expand All @@ -27,8 +29,15 @@ export class CacheGeocoder implements GeocoderInterface {
cacheKey,
);

if (cachedData) return cachedData;
if (cachedData) {
this.logger.debug(
`Cache hit for location ${args.address} ${args.latlng} `,
);
return cachedData;
}

const data: GeocodeResponse = await this.backendGeocoder.geocode(args);
this.logger.debug('Set cache for location ' + args.address + args.latlng);
await this.cacheManager.set(cacheKey, data);
return data;
}
Expand Down

0 comments on commit 4f7c988

Please sign in to comment.