Logging should never be used as a debugging tool for your code.
1 14 Jun 2018 21:30 by u/roznak
Logging should never be used as a debugging tool for your code.
Yes you know who you are: Those that logs useless stack traces when they get this exception.
It is not the purpose of your log file to show you how your code functions. You code should make that clear in the code and not through logging. If the only way to understand your code us using a log file then your design is wrong.
The purpose of log files is to guide the none-developer IT service team and testers to what the program is doing so they don't need to contact you to fix the issue. Even when you have long gone and the company lost the source code, the log files should be easy enough to read so an analyst can reconstruct the program.
It is harder than you think it is. You probably need to redesign your code in such a way that methods returns useful information that can be used for logging and normal functionality.
In addition tell the logging what you are going to do next.
Rough example to get the idea.
10:30:40 - Retrieving list of customers for company 'WYZ'
10.30:41 - 100 customers retrieved.
10:30:42 - Verifying the list if we have corrupt date
10:30;42 - 2 instances of corrupt data found and removed
10:30:42 - emailing 98 customers for company 'WYZ'
10:30:45 - 97 customers successfully emailed, 2 failed.
10;30:45 - - Customer 'abbbcc@hotmal.com' failed to deliver
10;30:45 - - Customer 'abbbcc122@Live.com' failed to deliver
10:30:45 - Updating database for 97 customers that succeeded and 2 failed.
People share your experiences! :-)
8 comments
0 u/MrBoneCrusher 14 Jun 2018 22:39
Completely retarded. No, logging shouldn't be your first line of debugging, but when a piece of software craps out on a customer's computer then logs are essential to understanding the problem. Have you ever even had a real development job?
0 u/roznak [OP] 15 Jun 2018 17:32
Logs should be the last resource to find the cause. Your job as a developer is to create good code. You should test every possibility before you deploy it.
The interesting thing is when you develop your code in such a way that it makes logs very readable, it actually helps you developing better products and way easier to test. On top of that your development will speed up making you even a better developer.
0 u/PointsOutIdiots 15 Jun 2018 00:43
You're an idiot.
0 u/MrBoneCrusher 15 Jun 2018 03:46
I don't get why this dude thinks he can essentially hijack /v/programming and treat it like his blog and post shitty programming advice.
0 u/roznak [OP] 15 Jun 2018 19:47
Stop complaining and discuss why it is shitty.
0 u/Wrathfullyawakenedww 15 Jun 2018 04:52
Beavers might infest your computer... dammit!
0 u/JosKodify 15 Jun 2018 06:42
This is quite contradictory advice. If log files are meant to help non-developers offer program support, logs should not be so verbose that people use it to reconstruct the whole program.
For people on the support desk, logs should be as focused as possible to help aid a quick response. They have no need for thousands of lines, each describing what action a program took.
And for reverse-engineering a program, wouldn't it make more sense to interact with the actual program itself? That would be an easier and quicker way than reading the log files for all kinds of situations.
0 u/roznak [OP] 15 Jun 2018 19:57
This was just a quick example.