2019-03-06 19:04:23 +05:30
|
|
|
/*-
|
2020-04-24 15:14:19 +05:30
|
|
|
* Licensed under the SPDX BSD-2-Clause identifier.
|
|
|
|
* Use is subject to license terms, as specified in the LICENSE file.
|
2019-03-06 19:04:23 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
|
|
|
|
#include "xbps_api_impl.h"
|
|
|
|
|
|
|
|
#ifdef __clang__
|
|
|
|
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file lib/log.c
|
|
|
|
* @brief Logging functions
|
|
|
|
* @defgroup log Logging functions
|
|
|
|
*
|
|
|
|
* Use these functions to log errors, warnings and debug messages.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
common_printf(FILE *f, const char *msg, const char *fmt, va_list ap)
|
|
|
|
{
|
|
|
|
if (msg != NULL)
|
|
|
|
fprintf(f, "%s", msg);
|
|
|
|
|
|
|
|
vfprintf(f, fmt, ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_dbg_printf_append(struct xbps_handle *xhp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2020-01-11 14:18:38 +05:30
|
|
|
if (!xhp)
|
|
|
|
return;
|
2020-01-06 16:40:47 +05:30
|
|
|
|
2019-03-06 19:04:23 +05:30
|
|
|
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
common_printf(stderr, NULL, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_dbg_printf(struct xbps_handle *xhp, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
2020-01-11 14:18:38 +05:30
|
|
|
if (!xhp)
|
|
|
|
return;
|
2020-01-06 16:40:47 +05:30
|
|
|
|
2019-03-06 19:04:23 +05:30
|
|
|
if ((xhp->flags & XBPS_FLAG_DEBUG) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
common_printf(stderr, "[DEBUG] ", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_error_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
common_printf(stderr, "ERROR: ", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
xbps_warn_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
common_printf(stderr, "WARNING: ", fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
}
|