diff --git a/src/.eslintrc.json b/src/.eslintrc.json new file mode 100644 index 0000000000..2ff50f91ec --- /dev/null +++ b/src/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-console": "error" + } +} diff --git a/src/common/Error/handler.ts b/src/common/Error/handler.ts index 30abdde6d7..d8d405fa0e 100644 --- a/src/common/Error/handler.ts +++ b/src/common/Error/handler.ts @@ -1,4 +1,5 @@ import * as Sentry from '@sentry/react' +import { logger } from '../../logger' import { SENTRY_CONFIG } from '../../config/config' export const initErrorHandler = () => { @@ -7,7 +8,7 @@ export const initErrorHandler = () => { location.search.indexOf('noSentry=true') !== -1 || location.hostname === 'localhost' ) { - console.log('No error handler for this environment') + logger.info('No error handler for this environment') return } diff --git a/src/logger/index.ts b/src/logger/index.ts index bde445c9c8..b5e1d120e8 100644 --- a/src/logger/index.ts +++ b/src/logger/index.ts @@ -1,6 +1,6 @@ import Logger from 'pino' import { createPinoBrowserSend, createWriteStream } from 'pino-logflare' -import { getConfigurationOption } from 'src/config/config' +import { getConfigurationOption } from '../config/config' const logLevel = getConfigurationOption('REACT_APP_LOG_LEVEL', 'info') diff --git a/src/modules/admin/pages/adminUsers.tsx b/src/modules/admin/pages/adminUsers.tsx index 14a91b85d2..80b37a5fd0 100644 --- a/src/modules/admin/pages/adminUsers.tsx +++ b/src/modules/admin/pages/adminUsers.tsx @@ -1,6 +1,7 @@ import { Box, Text } from 'theme-ui' import { useEffect, useState } from 'react' import { format } from 'date-fns' +import { logger } from '../../../logger' import Table from '../components/Table/Table' import type { ITableProps, @@ -91,7 +92,7 @@ const AdminUsers = observer(() => { const index = Fuse.createIndex(fuseOptions.keys, usersdata) fuse.setCollection(usersdata, index) } catch (error) { - console.log({ error }) + logger.info({ error }) } setLoading(false) } diff --git a/src/pages/Maps/Maps.tsx b/src/pages/Maps/Maps.tsx index 86cd3e61fb..3505172c5e 100644 --- a/src/pages/Maps/Maps.tsx +++ b/src/pages/Maps/Maps.tsx @@ -9,6 +9,7 @@ import { Box } from 'theme-ui' import './styles.css' +import { logger } from '../../logger' import type { ILatLng } from 'src/models/maps.models' import { GetLocation } from 'src/utils/geolocation' import type { Map } from 'react-leaflet' @@ -68,7 +69,7 @@ class MapsPage extends React.Component { lng: position.coords.longitude, }) } catch (error) { - console.error(error) + logger.error(error) // do nothing if location cannot be retrieved } } diff --git a/src/pages/common/UploadedFile/FirebaseFileUploader.tsx b/src/pages/common/UploadedFile/FirebaseFileUploader.tsx index b93fc45bdf..555219885f 100644 --- a/src/pages/common/UploadedFile/FirebaseFileUploader.tsx +++ b/src/pages/common/UploadedFile/FirebaseFileUploader.tsx @@ -47,7 +47,7 @@ export class FirebaseFileUploader extends React.Component { } public handleUploadError = (error: any) => { this.setState({ isUploading: false }) - console.error(error) + logger.error(error) } // on success update progress and pass back complete url to parent component public handleUploadSuccess = async (filename: string) => { diff --git a/src/serviceWorkerRegistration.ts b/src/serviceWorkerRegistration.ts index b90c74017c..5b48bab3a8 100644 --- a/src/serviceWorkerRegistration.ts +++ b/src/serviceWorkerRegistration.ts @@ -1,5 +1,5 @@ // https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#clientsclaim - +import { logger } from './logger' import { Workbox } from 'workbox-window' // initial code adapted from create-react-app (v4) @@ -91,7 +91,7 @@ function checkValidServiceWorker(swUrl: string, callback: RegisterSWCallback) { } }) .catch(() => { - console.log( + logger.info( 'No internet connection found. App is running in offline mode.', ) }) @@ -104,7 +104,7 @@ export function unregister() { registration.unregister() }) .catch((error) => { - console.error(error.message) + logger.error(error.message) }) } } diff --git a/src/stores/Admin/admin.store.ts b/src/stores/Admin/admin.store.ts index ca6e76f5b7..c70e5d9aeb 100644 --- a/src/stores/Admin/admin.store.ts +++ b/src/stores/Admin/admin.store.ts @@ -4,6 +4,7 @@ import { action, observable, makeObservable } from 'mobx' import type { IUser, UserRole } from 'src/models/user.models' import type { ITag } from 'src/models/tags.model' import { functions } from 'src/utils/firebase' +import { logger } from '../../logger' /********************************************************************************* * The admin store contains methods for updating user permissions. @@ -74,7 +75,7 @@ export class AdminStore extends ModuleStore { const email = res.data return email } catch (error) { - console.error(error) + logger.error(error) return `unable to get user email - ${error.message}` } } diff --git a/src/stores/Howto/howto.store.tsx b/src/stores/Howto/howto.store.tsx index 44bee11d56..402032febc 100644 --- a/src/stores/Howto/howto.store.tsx +++ b/src/stores/Howto/howto.store.tsx @@ -287,8 +287,8 @@ export class HowtoStore extends ModuleStore { await this.setActiveHowtoBySlug(updated?.slug || '') } } catch (err) { - console.log({ err }) - console.error(err) + logger.info({ err }) + logger.error(err) throw new Error(err) } } @@ -420,7 +420,7 @@ export class HowtoStore extends ModuleStore { } } } catch (err) { - console.error(err) + logger.error(err) throw new Error(err) } } @@ -443,7 +443,7 @@ export class HowtoStore extends ModuleStore { await this.setActiveHowtoBySlug(howto.slug) } } catch (err) { - console.error(err) + logger.error(err) throw new Error(err) } } diff --git a/src/stores/Research/research.store.tsx b/src/stores/Research/research.store.tsx index eab4b36a11..72c36cc9ce 100644 --- a/src/stores/Research/research.store.tsx +++ b/src/stores/Research/research.store.tsx @@ -300,7 +300,7 @@ export class ResearchStore extends ModuleStore { this.activeResearchItem = createdItem }) } catch (error) { - console.error(error) + logger.error(error) throw new Error(error?.message) } } @@ -359,7 +359,7 @@ export class ResearchStore extends ModuleStore { }) } } catch (err) { - console.error(err) + logger.error(err) throw new Error(err) } } @@ -422,7 +422,7 @@ export class ResearchStore extends ModuleStore { } } } catch (err) { - console.error(err) + logger.error(err) throw new Error(err) } } diff --git a/src/stores/Theme/theme.store.tsx b/src/stores/Theme/theme.store.tsx index 72be7c298d..c713d87a6a 100644 --- a/src/stores/Theme/theme.store.tsx +++ b/src/stores/Theme/theme.store.tsx @@ -4,6 +4,7 @@ import preciousPlasticTheme from 'src/themes/precious-plastic' import projectKampTheme from 'src/themes/project-kamp' import fixingFashionTheme from 'src/themes/fixing-fashion' import { getConfigurationOption } from 'src/config/config' +import { logger } from '../../logger' const themeMap = { 'precious-plastic': preciousPlasticTheme, @@ -21,7 +22,7 @@ export class ThemeStore { constructor() { makeAutoObservable(this) - console.log(`Current theme:`, this.currentTheme) + logger.debug(`Current theme:`, this.currentTheme) } @action diff --git a/src/stores/User/user.store.ts b/src/stores/User/user.store.ts index 0fcf49fb40..990a6cc429 100644 --- a/src/stores/User/user.store.ts +++ b/src/stores/User/user.store.ts @@ -381,7 +381,7 @@ export class UserStore extends ModuleStore { //TODO: ensure current user is updated } } catch (err) { - console.error(err) + logger.error(err) throw new Error(err) } } diff --git a/src/stores/databaseV2/CollectionReference.tsx b/src/stores/databaseV2/CollectionReference.tsx index ba7bc3ab37..365b3fb4a6 100644 --- a/src/stores/databaseV2/CollectionReference.tsx +++ b/src/stores/databaseV2/CollectionReference.tsx @@ -7,6 +7,7 @@ import type { import type { Observer } from 'rxjs' import { Observable } from 'rxjs' import { DocReference } from './DocReference' +import { logger } from '../../logger' export class CollectionReference { constructor(private endpoint: string, private clients: DBClients) {} @@ -58,9 +59,6 @@ export class CollectionReference { totals.live = updates.length await cacheDB.setBulkDocs(endpoint, updates) const allDocs = await cacheDB.getCollection(endpoint) - // console.group(`[${endpoint}] docs retrieved`) - // console.table(totals) - // console.groupEnd() obs.next(allDocs) }) // 4. Check for any document deletes, and remove as appropriate @@ -130,7 +128,7 @@ export class CollectionReference { limit, }) } catch (error) { - console.error(error) + logger.error(error) // at least we can say we tried... } } diff --git a/src/stores/databaseV2/clients/dexie.tsx b/src/stores/databaseV2/clients/dexie.tsx index 90204ddac7..45ceeae24c 100644 --- a/src/stores/databaseV2/clients/dexie.tsx +++ b/src/stores/databaseV2/clients/dexie.tsx @@ -7,6 +7,7 @@ import type { } from '../types' import { DB_QUERY_DEFAULTS } from '../utils/db.utils' import { DB_ENDPOINTS } from '../endpoints' +import { logger } from '../../../logger' /** * Update the cache number either when making changes to db architecture @@ -91,7 +92,7 @@ export class DexieClient implements AbstractDBClient { case '>': return ref.where(field).below(value) default: - console.error('no dexie query mapping for ' + operator) + logger.error('no dexie query mapping for ' + operator) throw new Error( 'mapping has not been created for dexie query: ' + operator, ) @@ -108,7 +109,7 @@ export class DexieClient implements AbstractDBClient { // test open db, catch errors for upgrade version not defined or // idb not supported db.open().catch(async (err) => { - console.error(err) + logger.error(err) // NOTE - invalid state error suggests dexie not supported, so // try reloading with cachedb disabled (see db index for implementation) if (err.name === Dexie.errnames.InvalidState) { diff --git a/src/utils/firebase.ts b/src/utils/firebase.ts index 607ae3f7e7..2e3fd234b4 100644 --- a/src/utils/firebase.ts +++ b/src/utils/firebase.ts @@ -5,6 +5,7 @@ import 'firebase/storage' import 'firebase/functions' import 'firebase/database' import { FIREBASE_CONFIG, SITE } from '../config/config' +import { logger } from '../logger' // initialise with config settings, additional firestore config to support future changes firebase.initializeApp(FIREBASE_CONFIG) @@ -18,15 +19,15 @@ const functions = firebase.functions() // use emulators when running on localhost:4000 if (SITE === 'emulated_site') { - console.log(`Connecting to emulated services:`) + logger.debug(`Connecting to emulated services:`) firestore.useEmulator('localhost', 4003) - console.log(`Connecting rtdb on port `, 4006) + logger.debug(`Connecting rtdb on port `, 4006) rtdb.useEmulator('localhost', 4006) - console.log(`Connecting storage on port `, 4007) + logger.debug(`Connecting storage on port `, 4007) storage.useEmulator('localhost', 4007) - console.log(`Connecting auth on port `, 4005) + logger.debug(`Connecting auth on port `, 4005) auth.useEmulator(`http://localhost:4005`) - console.log(`Connecting functions on port `, 4002) + logger.debug(`Connecting functions on port `, 4002) functions.useEmulator('localhost', 4002) }