Skip to content

Commit a314bcd

Browse files
committed
Add specific log functions
1 parent b2c6af8 commit a314bcd

File tree

2 files changed

+85
-26
lines changed

2 files changed

+85
-26
lines changed

include/zone.h

+76-21
Original file line numberDiff line numberDiff line change
@@ -284,27 +284,6 @@ typedef void(*zone_log_t)(
284284
const char *, // message
285285
void *); // user data
286286

287-
/**
288-
* @brief Write error message to active log handler.
289-
*
290-
* The zone parser operates on a per-record base and therefore cannot detect
291-
* errors that span records. e.g. SOA records being specified more than once.
292-
* The user may print a message using the active log handler, keeping the
293-
* error message format consistent.
294-
*
295-
* @param[in] parser Zone parser
296-
* @param[in] category Log category
297-
* @param[in] format Format string compatible with printf
298-
* @param[in] ... Variadic arguments corresponding to #format
299-
*/
300-
ZONE_EXPORT void zone_log(
301-
zone_parser_t *parser,
302-
uint32_t category,
303-
const char *format,
304-
...)
305-
zone_nonnull((1,3))
306-
zone_format_printf(3,4);
307-
308287
typedef struct zone_name zone_name_t;
309288
struct zone_name {
310289
uint8_t length;
@@ -440,6 +419,82 @@ zone_parse_string(
440419
void *user_data)
441420
zone_nonnull((1,2,3,4));
442421

422+
/**
423+
* @brief Write error message to active log handler.
424+
*
425+
* The zone parser operates on a per-record base and therefore cannot detect
426+
* errors that span records. e.g. SOA records being specified more than once.
427+
* The user may print a message using the active log handler, keeping the
428+
* error message format consistent.
429+
*
430+
* @param[in] parser Zone parser
431+
* @param[in] category Log category
432+
* @param[in] format Format string compatible with printf
433+
* @param[in] ... Variadic arguments corresponding to #format
434+
*/
435+
ZONE_EXPORT void zone_log(
436+
zone_parser_t *parser,
437+
uint32_t category,
438+
const char *format,
439+
...)
440+
zone_nonnull((1,3))
441+
zone_format_printf(3,4);
442+
443+
/**
444+
* @brief Write error message to active log handler.
445+
*
446+
* @param[in] parser Zone parser
447+
* @param[in] category Log category
448+
* @param[in] format Format string compatible with printf
449+
* @param[in] arguments Argument list
450+
*/
451+
ZONE_EXPORT void zone_vlog(
452+
zone_parser_t *parser,
453+
uint32_t category,
454+
const char *format,
455+
va_list arguments)
456+
zone_nonnull((1,3));
457+
458+
ZONE_EXPORT inline void
459+
zone_nonnull((1,2))
460+
zone_format_printf(2,3)
461+
zone_error(zone_parser_t *parser, const char *format, ...)
462+
{
463+
if (!(parser->options.log.categories & ZONE_ERROR))
464+
return;
465+
va_list arguments;
466+
va_start(arguments, format);
467+
zone_vlog(parser, ZONE_ERROR, format, arguments);
468+
va_end(arguments);
469+
}
470+
471+
ZONE_EXPORT inline void
472+
zone_nonnull((1,2))
473+
zone_format_printf(2,3)
474+
zone_warning(zone_parser_t *parser, const char *format, ...)
475+
{
476+
if (!(parser->options.log.categories & ZONE_WARNING))
477+
return;
478+
va_list arguments;
479+
va_start(arguments, format);
480+
zone_vlog(parser, ZONE_WARNING, format, arguments);
481+
va_end(arguments);
482+
}
483+
484+
ZONE_EXPORT inline void
485+
zone_nonnull((1,2))
486+
zone_format_printf(2,3)
487+
zone_info(zone_parser_t *parser, const char *format, ...)
488+
{
489+
if (!(parser->options.log.categories & ZONE_INFO))
490+
return;
491+
va_list arguments;
492+
va_start(arguments, format);
493+
zone_vlog(parser, ZONE_INFO, format, arguments);
494+
va_end(arguments);
495+
}
496+
497+
443498
#if defined(__cplusplus)
444499
}
445500
#endif

src/zone.c

+9-5
Original file line numberDiff line numberDiff line change
@@ -421,9 +421,6 @@ static void print_message(
421421
fprintf(output, format, parser->file->name, parser->file->line, message);
422422
}
423423

424-
diagnostic_push()
425-
clang_diagnostic_ignored(missing-prototypes)
426-
427424
void zone_vlog(
428425
zone_parser_t *parser,
429426
uint32_t category,
@@ -444,8 +441,6 @@ void zone_vlog(
444441
callback(parser, category, message, parser->user_data);
445442
}
446443

447-
diagnostic_pop()
448-
449444
void zone_log(
450445
zone_parser_t *parser,
451446
uint32_t category,
@@ -461,3 +456,12 @@ void zone_log(
461456
zone_vlog(parser, category, format, arguments);
462457
va_end(arguments);
463458
}
459+
460+
extern inline void
461+
zone_error(zone_parser_t *parser, const char *format, ...);
462+
463+
extern inline void
464+
zone_warning(zone_parser_t *parser, const char *format, ...);
465+
466+
extern inline void
467+
zone_info(zone_parser_t *parser, const char *format, ...);

0 commit comments

Comments
 (0)