Jeegar Patel
Jeegar Patel

Reputation: 27230

Is there any standard way for putting debug print in a library?

I have seen lots of library written in C and C++ programming languages in which each library has its own method for debug printing. The most common I have seen is:

User sets 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

One more best example is in Gstremer Library they are providing

debug level mechanism

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

If user passes level 5 then all prints will be there; if he sets 2 then only error and warning will be there.

So now is there any standard or better methods for such debug prints in library/project?

Upvotes: 4

Views: 553

Answers (2)

Jonathan Leffler
Jonathan Leffler

Reputation: 754570

Any system similar to that is reasonable; there isn't a de facto standard that I know of. You can provide functions to send the output to different files. More complex systems might allow you to recognize different subsystems, and to set different debug levels for different subsystems. But that is fairly unusual and depends on whether the library can be sensibly subdivided into subsystems.

Upvotes: 4

Alok Save
Alok Save

Reputation: 206576

There is no standard way, Each library or project employs their own scheme.
The scheme you have mentioned is the most commonly used accross many implementations.

Upvotes: 3

Related Questions