U
U
Unknown Hero2017-03-05 18:50:19
Programming
Unknown Hero, 2017-03-05 18:50:19

Combine logger and comments. What do you think about this?

Hello!
In order to improve the readability of the code, I often invent all sorts of bicycles. In my practice (and from smart books) I developed a style of writing self-documenting code. Now I want to add not only the readability of the code separately, but also add the readability of the business logic. To do this, I would like to cross comments and logging. Something like that:

...   
   public function executeSomeBusinessProcess() {
       $this->logger('Start executing some business process');
       $this->logger('Create something in database');
       $someData = $this->_buildSomeData();
       $this->someRepository->add($someData);
       $this->logger('Send some events');
       $this->events->sendSomeEvents($someData);
       $this->logger('End of some business process');
   }
...

The example says something obvious, but if the business logic is specific, then such "comments" may become appropriate. In addition, it will be possible to analyze the logs of all processes and understand what is called in what sequence. Something like:
1. Presenter. Started processing http
2. Presenter. Collected user model from http request
3. Business. Started the user registration process
4. Business. Sending a request to the database to create a user
5. Database. Create a new field in the Users table
6. Business. Send email to new user
7. Mail. Sending an email to [email protected]
8. Business. We complete the creation of the user
9. Presenter. We complete the HTTP request.
At the same time, it would be possible to leave only Business in the log filter and analyze how this or that process works.
You can also transfer some data related to the log message to the log itself and conduct testing inside the assert.
As a result, you can get live comments that form business process scenarios, and possibly also a tool for assert testing. Usually, not only comments, but some values ​​get into the logs. I'm also interested in scripting and a way to make the code more readable.
What do you think about this? Strongly bent?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Axian Ltd., 2017-03-05
@UnknownHero

Why reinvent the wheel? If it's java, then https://www.tutorialspoint.com/java/java_documenta... , for php there are some stray things, for other languages ​​there are their own.

S
sim3x, 2017-03-05
@sim3x

The logger must have levels
notify
info
error
warning
critical
If you want to add labels to these levels, then no one
forbids
through which it will be possible to grep

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question