From 787e14727a40d58a623086737cc5072027c49934 Mon Sep 17 00:00:00 2001 From: Shehab Mohsen <97417536+ShehabMohsen@users.noreply.github.com> Date: Mon, 9 Jan 2023 04:24:26 -0500 Subject: [PATCH] chore: Decouple verbose logging from staging (#160) * Decoupled verbose logs from staging mode. * Added verbose logs option to README. --- README.md | 3 +++ src/utils/config.js | 3 +++ src/utils/devLog.ts | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63d38a7..6ed93fa 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,9 @@ NEXT_PUBLIC_APP_URL=https://app.animethemes.moe ; Set to any truthy value to activate staging mode. ; In staging mode a warning banner is displayed at the top of the page. NEXT_PUBLIC_STAGING=true + +; To enable verbose logging. +NEXT_PUBLIC_VERBOSE_LOGS=true ``` For more information on environment variables see the [Next.js documentation](https://nextjs.org/docs/basic-features/environment-variables). diff --git a/src/utils/config.js b/src/utils/config.js index 38d7ed4..11fb0e4 100644 --- a/src/utils/config.js +++ b/src/utils/config.js @@ -24,6 +24,8 @@ const AUDIO_URL = process.env.NEXT_PUBLIC_AUDIO_URL; const APP_URL = process.env.NEXT_PUBLIC_APP_URL; const STAGING = !!process.env.NEXT_PUBLIC_STAGING; +const VERBOSE_LOGS = !!process.env.NEXT_PUBLIC_VERBOSE_LOGS; + function validateConfig() { let isValid = true; @@ -58,5 +60,6 @@ module.exports = { AUDIO_URL, APP_URL, STAGING, + VERBOSE_LOGS, validateConfig, }; diff --git a/src/utils/devLog.ts b/src/utils/devLog.ts index 2f9459f..533dff1 100644 --- a/src/utils/devLog.ts +++ b/src/utils/devLog.ts @@ -1,5 +1,5 @@ import * as log from "next/dist/build/output/log"; -import { STAGING } from "./config"; +import { VERBOSE_LOGS } from "./config"; function info(...message: string[]) { logIfDevelopment(log.info, ...message); @@ -14,7 +14,7 @@ function error(...message: string[]) { } function logIfDevelopment(fn: (...message: string[]) => void, ...message: string[]) { - if (process.env.NODE_ENV === "development" || STAGING) { + if (process.env.NODE_ENV === "development" || VERBOSE_LOGS) { fn(...message); } }