To set this up, I basically made added two functions like this, one for on-screen and one for log files:
int SdsLogSetPrintLevel (int level)
{
print_level = level;
}
and then changed the code so that it prints only the higher priority messages to log file or screen, depending on user settings.
/* If level is greater than specified ,
* then print to stderr. */
if (level >= print_level)
fprintf(stderr, logstatement);
/* If level is greater than specified log level, write to logfile */
if (level >= log_level)
fprintf(logfp, "%s", logstatement);
Of course, I had to set the default values appropriately, so that the log file would get all messages.
int log_level = SDS_LOG_DEBUG, /* File should have debug messages */
print_level = SDS_LOG_INFO; /* Screen should have info messages */
No comments:
Post a Comment