Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/dicom.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ static DcmError *dcm_error_newf(DcmErrorCode code,
}


static bool should_log(DcmLogLevel level);

void dcm_error_set(DcmError **error, DcmErrorCode code,
const char *summary, const char *format, ...)
{
Expand All @@ -233,7 +235,7 @@ void dcm_error_set(DcmError **error, DcmErrorCode code,
va_start(ap, format);
*error = dcm_error_newf(code, summary, format, ap);
va_end(ap);
} else {
} else if (should_log(DCM_LOG_DEBUG)) {
/* Log to DEBUG so messages don't get completely lost.
*/
va_list(ap);
Expand Down Expand Up @@ -377,11 +379,18 @@ static void dcm_logf(const char *level, const char *format, va_list args)
}


static bool should_log(DcmLogLevel level)
{
return dcm_log_level <= level &&
(level == DCM_LOG_CRITICAL || dcm_log_level > DCM_LOG_NOTSET);
}


void dcm_log_critical(const char *format, ...)
{
dcm_init();

if (dcm_log_level <= DCM_LOG_CRITICAL) {
if (should_log(DCM_LOG_CRITICAL)) {
va_list(args);
va_start(args, format);
dcm_logf("CRITICAL", format, args);
Expand All @@ -394,7 +403,7 @@ void dcm_log_error(const char *format, ...)
{
dcm_init();

if ((dcm_log_level > DCM_LOG_NOTSET) & (dcm_log_level <= DCM_LOG_ERROR)) {
if (should_log(DCM_LOG_ERROR)) {
va_list(args);
va_start(args, format);
dcm_logf("ERROR ", format, args);
Expand All @@ -407,7 +416,7 @@ void dcm_log_warning(const char *format, ...)
{
dcm_init();

if ((dcm_log_level > DCM_LOG_NOTSET) & (dcm_log_level <= DCM_LOG_WARNING)) {
if (should_log(DCM_LOG_WARNING)) {
va_list(args);
va_start(args, format);
dcm_logf("WARNING ", format, args);
Expand All @@ -420,7 +429,7 @@ void dcm_log_info(const char *format, ...)
{
dcm_init();

if ((dcm_log_level > DCM_LOG_NOTSET) & (dcm_log_level <= DCM_LOG_INFO)) {
if (should_log(DCM_LOG_INFO)) {
va_list(args);
va_start(args, format);
dcm_logf("INFO ", format, args);
Expand All @@ -433,7 +442,7 @@ void dcm_log_debug(const char *format, ...)
{
dcm_init();

if ((dcm_log_level > DCM_LOG_NOTSET) & (dcm_log_level <= DCM_LOG_DEBUG)) {
if (should_log(DCM_LOG_DEBUG)) {
va_list(args);
va_start(args, format);
dcm_logf("DEBUG ", format, args);
Expand Down
Loading