Is there a standard way to place debug printing in a library?

I have seen many libraries written in the C and C ++ programming languages, in which each library has its own method for debugging printing. The most common I've seen:

The user sets a flag for this.

1> for error prints 2> for warning prints 3> for debug values prints 4> for getting all this print on stdout/stderr 5> for getting all this print on logfile 

Another best example is the Gstremer library they provide

debug level mechanism

 level-1 for error level-2 for warning level-3 for debug level-4 for info level-5 for log 

If the user passes level 5, then all prints will be printed; if it sets 2, then there will only be errors and warnings.

So, are there any standard or best methods for such debugging prints in the library / project?

+4
source share
2 answers

Any system like this is intelligent; there is no de facto standard that I know of. You can provide functions for sending output to different files. More complex systems may allow you to recognize different subsystems and set different debugging levels for different subsystems. But this is rather unusual and depends on whether it is reasonable to subdivide the library into subsystems.

+4
source

There is no standard way. Each library or project uses its own scheme.
The scheme you mentioned is most often used in many implementations.

+3
source

Source: https://habr.com/ru/post/1387986/


All Articles