Skip to content

Commit 4f7c988

Browse files
committed
Improve logging
1 parent 8340db2 commit 4f7c988

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

api/config/production.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
11
{
2+
"db": {
3+
"logging": [
4+
"error",
5+
"schema",
6+
"info",
7+
"log"
8+
]
9+
}
210
}

api/src/modules/geo-coding/geo-coding.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ export class GeoCodingService extends GeoCodingAbstractClass {
4444
const errors: any[] = [];
4545
for (let i: number = 0; i < sourcingData.length; i++) {
4646
const location: SourcingData = sourcingData[i];
47+
this.logger.debug(
48+
`Geocoding location: Country: ${location.locationCountryInput}, Address: ${location.locationAddressInput}, LAT: ${location.locationLatitude}, LONG: ${location.locationLongitude}`,
49+
);
4750
try {
4851
if (location.locationType === LOCATION_TYPES.UNKNOWN) {
4952
geoCodedSourcingData.push(

api/src/modules/geo-coding/geocoders/cache.geocoder.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Inject } from '@nestjs/common';
1+
import { Inject, Logger } from '@nestjs/common';
22
import { CACHE_MANAGER } from '@nestjs/cache-manager';
33
import {
44
GeocodeArgs,
@@ -11,6 +11,8 @@ import { GoogleMapsGeocoder } from 'modules/geo-coding/geocoders/google-maps.geo
1111
export const GEOCODING_CACHE_ENABLED: unique symbol = Symbol();
1212

1313
export class CacheGeocoder implements GeocoderInterface {
14+
private logger: Logger = new Logger(CacheGeocoder.name);
15+
1416
constructor(
1517
@Inject(GEOCODING_CACHE_ENABLED) private geocacheEnabled: boolean,
1618
@Inject(GoogleMapsGeocoder) private backendGeocoder: GeocoderInterface,
@@ -27,8 +29,15 @@ export class CacheGeocoder implements GeocoderInterface {
2729
cacheKey,
2830
);
2931

30-
if (cachedData) return cachedData;
32+
if (cachedData) {
33+
this.logger.debug(
34+
`Cache hit for location ${args.address} ${args.latlng} `,
35+
);
36+
return cachedData;
37+
}
38+
3139
const data: GeocodeResponse = await this.backendGeocoder.geocode(args);
40+
this.logger.debug('Set cache for location ' + args.address + args.latlng);
3241
await this.cacheManager.set(cacheKey, data);
3342
return data;
3443
}

0 commit comments

Comments
 (0)