DEV Community

Cover image for Conditional logging
Sibelius Seraphini for Woovi

Posted on

3

Conditional logging

As your codebase grows and your system increases in complexity you need to add logs to be able to understand how your program state varies across execution.

When debugging your system you can use a debugger or add some on-off console.log to understand what is happening in your program execution.
The problem with this approach is that you need to instrument your code to be effective in solving or understanding what is going on.

Conditional Logging

Another way to solve this is to have the logs in place, but only enable them conditionally.
If you enable all the logs are the time, you only get a lot of noise that won't help you.
If you are using JavaScript, you can use the package debug to add logs that are active by the DEBUG environment variable.

debug

What to log conditionally?

HTTP requests can be conditionally logged, so you understand what requests your program is doing and which parameters and responses.
Conditionally logging Event-Driven events can be useful for understanding what events are being emitted in which part of the code.

In short

Instrumenting your codebase gets more important as the size and complexity of your product grows.
Use conditional logging to enable only useful logs for your needs.


Woovi
Woovi is a Startup that enables shoppers to pay as they like. To make this possible, Woovi provides instant payment solutions for merchants to accept orders.

If you want to work with us, we are hiring!

Do your career a favor. Join DEV. (The website you're on right now)

It takes one minute, it's free, and is worth it for your career.

Get started

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay