Logging practices I follow
Make debugging easier
There’s so many little tricks I’ve acquired over the years on making software easier to debug. If you don’t make any effort to make debugging easy, you’re going to spend unacceptable amounts of time debugging each issue, as your software gets more and more complex. You’ll be terrified to make changes because even a couple new ... See more
There’s so many little tricks I’ve acquired over the years on making software easier to debug. If you don’t make any effort to make debugging easy, you’re going to spend unacceptable amounts of time debugging each issue, as your software gets more and more complex. You’ll be terrified to make changes because even a couple new ... See more
Marcus • Marcus' Blog
nico kokonas added
Logging, one of the three pillars of observability, can become very expensive with complex applications tying together many microservices due to *persistent* storage costs.
Aashay Sanghvi • B2B and Enterprise Product Ideas - January 2020
sari added
Here's a list of those log levels from lowest precedence to highest:
notset (0) - Indicates that ancestor loggers should be consulted for the log level or that all events are logged (default setting)
debug (10) - Detailed information that would be of interest to the developer for diagnostic purposes
info (20) - Information that confirms that your appl... See more
notset (0) - Indicates that ancestor loggers should be consulted for the log level or that all events are logged (default setting)
debug (10) - Detailed information that would be of interest to the developer for diagnostic purposes
info (20) - Information that confirms that your appl... See more
Shortwave — The smartest email app on planet Earth
Nicolay Gerold added
- Disable the global console object with ESLint.
- Don't use console for logging; instead, use a proper logging solution that has a log level built-in feature, such as Winston, Pino, Log4js, or tslog.
- Set the log level to DEBUG on localhost, and set it to whatever you want in production (e.g., ERROR or WARN ). Use log.debug() for development logs.
Th... See more
Link
DJ Scruggs added
you can try to debug a program by flying blind without the logs, or alternatively you can try to look at every row of the logs, but rather than either of these extremes you’ll do best if you have a method for distilling the logs into something actionable.
Balaji Srinivasan • The Network State: How To Start a New Country
I firmly believe writing code is not much different: through finding good names for functions, variables, and other constructs, we truly recognize the essence of the problem we are solving. The consequence of clarity gained is not just good names but also cleaner code and improved architecture .
Martin Sosic • On Importance of Naming in Programming | Wasp
Nicolay Gerold added
"I would go as far as to say that 90% of writing clean code is “just” naming things correctly."
Good name doesn’t misdirect, doesn’t omit, and doesn’t assume.
A good name should give you a good idea about what the variable contains or function does. A good name will tell you all there is to know or will tell you enough to know where to look next. It will not let you guess, or wonder. It will not misguide you. A good name is obvious, and expected. It is consistent. Not overly creative. It will not assume context or knowledge that the reader is not likely to have.
Write a comment above the function/variable where you describe what it is, in human language, as if you were describing it to your colleague. It might be one sentence or multiple sentences. This is the essence of what your function/variable does, what it is.
Now, you take the role of the sculptor, and you chisel at and shape that description of your function/variable until you get a name, by taking pieces of it away. You stop when you feel that one more hit of your imagined chisel at it would take too much away.
Is your name still too complex/confusing? If that is so, that means that the code behind is too complex, and should be reorganized! Go refactor it.
Ok, all done → you have a nice name!
That comment above the function/variable? Remove everything from it that is now captured in the code (name + arguments + type signature). If you can remove the whole comment, great. Sometimes you can’t, because some stuff can’t be captured in the code (e.g. certain assumptions, explanations, examples, …), and that is also okay. But don’t repeat in the comment what you can say in the code instead. Comments are a necessary evil and are here to capture knowledge that you can’t capture in your names and/or types.
Bad code gives you feedback, perfect code doesn’t. Err on the side of writing bad code
It’s really easy to write terrible code. But it’s also really easy to write code that follows absolutely every best practice, which has been unit, integration, fuzz, and mutation-tested for good measure – your startup will just run out of money before you finish.... See more
It’s really easy to write terrible code. But it’s also really easy to write code that follows absolutely every best practice, which has been unit, integration, fuzz, and mutation-tested for good measure – your startup will just run out of money before you finish.... See more
Marcus • Marcus' Blog
nico kokonas added