Skip to content

Commit ce7dd46

Browse files
VIA-545 SB Enable console logging in lower environments.
1 parent c1f1f14 commit ce7dd46

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

.env.template

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ SSM_PREFIX=/local/
33

44
# logging
55
PINO_LOG_LEVEL=info
6+
NEXT_PUBLIC_SUPRESS_CONSOLE=false
67
PROFILE_PERFORMANCE=true
78
DEPLOY_ENVIRONMENT=local
89

infrastructure/environments/dev/locals.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ locals {
2525
application_environment_variables = {
2626
SSM_PREFIX = "/${local.prefix}/"
2727

28-
PINO_LOG_LEVEL = "info"
29-
DEPLOY_ENVIRONMENT = local.environment
30-
PROFILE_PERFORMANCE = "true"
28+
PINO_LOG_LEVEL = "info"
29+
NEXT_PUBLIC_SUPRESS_CONSOLE = "false"
30+
DEPLOY_ENVIRONMENT = local.environment
31+
PROFILE_PERFORMANCE = "true"
3132

3233
CONTENT_API_ENDPOINT = "https://int.api.service.nhs.uk/"
3334
CONTENT_CACHE_PATH = "s3://${local.content_cache_bucket_name}"

infrastructure/environments/preprod/locals.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ locals {
2525
application_environment_variables = {
2626
SSM_PREFIX = "/${local.prefix}/"
2727

28-
PINO_LOG_LEVEL = "info"
29-
DEPLOY_ENVIRONMENT = local.environment
30-
PROFILE_PERFORMANCE = "true"
28+
PINO_LOG_LEVEL = "info"
29+
NEXT_PUBLIC_SUPRESS_CONSOLE = "false"
30+
DEPLOY_ENVIRONMENT = local.environment
31+
PROFILE_PERFORMANCE = "true"
3132

3233
CONTENT_API_ENDPOINT = "https://int.api.service.nhs.uk/"
3334
CONTENT_CACHE_PATH = "s3://${local.content_cache_bucket_name}"

infrastructure/environments/prod/locals.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ locals {
2525
application_environment_variables = {
2626
SSM_PREFIX = "/${local.prefix}/"
2727

28-
PINO_LOG_LEVEL = "info"
29-
DEPLOY_ENVIRONMENT = local.environment
30-
PROFILE_PERFORMANCE = "true"
28+
PINO_LOG_LEVEL = "info"
29+
NEXT_PUBLIC_SUPRESS_CONSOLE = "true"
30+
DEPLOY_ENVIRONMENT = local.environment
31+
PROFILE_PERFORMANCE = "true"
3132

3233
CONTENT_API_ENDPOINT = "https://api.service.nhs.uk/"
3334
CONTENT_CACHE_PATH = "s3://${local.content_cache_bucket_name}"

infrastructure/environments/test/locals.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ locals {
2525
application_environment_variables = {
2626
SSM_PREFIX = "/${local.prefix}/"
2727

28-
PINO_LOG_LEVEL = "debug"
29-
DEPLOY_ENVIRONMENT = local.environment
30-
PROFILE_PERFORMANCE = "true"
28+
PINO_LOG_LEVEL = "debug"
29+
NEXT_PUBLIC_SUPRESS_CONSOLE = "true"
30+
DEPLOY_ENVIRONMENT = local.environment
31+
PROFILE_PERFORMANCE = "true"
3132

3233
CONTENT_API_ENDPOINT = "https://int.api.service.nhs.uk/"
3334
CONTENT_CACHE_PATH = "s3://${local.content_cache_bucket_name}"

src/app/_components/client-unhandled-error-logger/ClientUnhandledErrorLogger.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ import { ClientSideErrorTypes } from "@src/utils/constants";
55
import { useRouter } from "next/navigation";
66
import { useEffect } from "react";
77

8+
const supressConsole = (process.env.NEXT_PUBLIC_SUPRESS_CONSOLE ?? "true") !== "false";
89
let router;
910

1011
const reportClientSideUnhandledError = (errorEvent: ErrorEvent) => {
11-
errorEvent.preventDefault();
12-
logClientSideError(ClientSideErrorTypes.UNHANDLED_ERROR).catch(() => {
12+
if (supressConsole) errorEvent.preventDefault();
13+
14+
logClientSideError(ClientSideErrorTypes.UNHANDLED_ERROR).catch((err: Error) => {
15+
if (!supressConsole) console.error(err.message);
1316
// do not show anything to the user; catching prevents an infinite loop if the logger itself throws an error which is unhandled
1417
});
1518
router.push("/service-failure");
1619
};
1720

1821
const reportClientSideUnhandledPromiseRejectionError = () => {
19-
logClientSideError(ClientSideErrorTypes.UNHANDLED_PROMISE_REJECT_ERROR).catch(() => {
22+
logClientSideError(ClientSideErrorTypes.UNHANDLED_PROMISE_REJECT_ERROR).catch((err: Error) => {
23+
if (!supressConsole) console.error(err.message);
2024
// do not show anything to the user; catching prevents an infinite loop if the logger itself throws an error which is unhandled
2125
});
2226
router.push("/service-failure");

0 commit comments

Comments
 (0)