Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: Abundance of logging everywhere #48 #72

Merged
merged 1 commit into from
Oct 5, 2024

Conversation

codistiano
Copy link
Contributor

📋 Description

This pull request implements a way to log only important messages rather than each and in every point of the process.

🔨 Changes Made

Implementation Details:

  • Moved the requiring of the dotenv package
  • Created a function in the index.js file, that works as follows:
if (process.env.NODE_ENV === 'production') { // Checks if it is in production 
    const originalLog = console.log;

    // Replacing console.log with a custom function to make it work only when it is an important message
    console.log = function (message) {
        // List of the important messages keywords that should still be logged in production
        const importantMessages = [
            'Server',
            'Database',
            'MongoDB',
            'Error'  // Important keywords can be added here
        ];

        // To log only important messages in production we check the availability of any important keyword
        if (importantMessages.some((important) => message.includes(important))) {
            originalLog(message);  // Uses the original console.log to log the message that was hold earlier
        }
    };
}

✅ Checklist

Before submitting the PR, please make sure you have completed the following:

  • My code follows the style guidelines of this project.
  • You understood my comments on the code, particularly in hard-to-understand areas.
  • My changes generate no new warnings.
  • AND most importantly, adding an environmental variable in the deploying app (vercel) which should be as follows: NODE_ENV=production, NODE_ENV as a key and production as a value because it is what will be checked for the feature to be implemented

🤝🏼 Fixed Issue in this PR

Copy link

vercel bot commented Oct 4, 2024

@codistiano is attempting to deploy a commit to the Vishal Kumar 's projects Team on Vercel.

A member of the Team first needs to authorize it.

@codistiano
Copy link
Contributor Author

Please Check this PR @vishalverma9572

How to Check Locally

Just add the environmental variable as NODE_ENV=production and it is all set

@vishalverma9572 vishalverma9572 merged commit 91afb78 into vishalverma9572:main Oct 5, 2024
1 of 3 checks passed
@vishalverma9572
Copy link
Owner

@codistiano, merged!

@vishalverma9572 vishalverma9572 added hacktoberfest security hacktoberfest-accepted This PR is accepted under hacketoberfest labels Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest hacktoberfest-accepted This PR is accepted under hacketoberfest security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants