/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (c) 2016 wonder-mice
+ *
* This is zf_log.c, modified with Babeltrace prefixes.
* See <https://github.com/wonder-mice/zf_log/>.
- * See LICENSE.
*/
#include "common/macros.h"
* level variable. In that case it must be defined elsewhere using
* BT_LOG_DEFINE_GLOBAL_OUTPUT_LEVEL macro, for example:
*
- * BT_LOG_DEFINE_GLOBAL_OUTPUT_LEVEL = BT_LOG_WARN;
+ * BT_LOG_DEFINE_GLOBAL_OUTPUT_LEVEL = BT_LOG_WARNING;
*
* This allows to specify custom value for static initialization and avoid
* overhead of setting this value in runtime.
#include <sys/time.h>
#if defined(__linux__)
#include <linux/limits.h>
- #elif (defined(__sun__) || defined(__CYGWIN__))
- /* Solaris and Cygwin have no sys/syslimits.h */
+ #elif (defined(__sun__) || defined(__CYGWIN__) || defined(__GNU__))
+ /* Solaris, Cygwin and Hurd have no sys/syslimits.h */
#else
#include <sys/syslimits.h>
#endif
#if defined(__MACH__)
#include <pthread.h>
#endif
+#if defined(__GNU__)
+ #include <mach.h>
+#endif
#define INLINE _BT_LOG_INLINE
#define VAR_UNUSED(var) (void)var
{
switch (lvl)
{
- case BT_LOG_VERBOSE:
+ case BT_LOG_TRACE:
return ANDROID_LOG_VERBOSE;
case BT_LOG_DEBUG:
return ANDROID_LOG_DEBUG;
case BT_LOG_INFO:
return ANDROID_LOG_INFO;
- case BT_LOG_WARN:
+ case BT_LOG_WARNING:
return ANDROID_LOG_WARN;
case BT_LOG_ERROR:
return ANDROID_LOG_ERROR;
{
switch (lvl)
{
- case BT_LOG_VERBOSE:
+ case BT_LOG_TRACE:
return 7; /* ASL_LEVEL_DEBUG / kCFLogLevelDebug */;
case BT_LOG_DEBUG:
return 7; /* ASL_LEVEL_DEBUG / kCFLogLevelDebug */;
case BT_LOG_INFO:
return 6; /* ASL_LEVEL_INFO / kCFLogLevelInfo */;
- case BT_LOG_WARN:
+ case BT_LOG_WARNING:
return 4; /* ASL_LEVEL_WARNING / kCFLogLevelWarning */;
case BT_LOG_ERROR:
return 3; /* ASL_LEVEL_ERR / kCFLogLevelError */;
{
switch (lvl)
{
- case BT_LOG_VERBOSE:
- return 'V';
+ case BT_LOG_TRACE:
+ return 'T';
case BT_LOG_DEBUG:
return 'D';
case BT_LOG_INFO:
return 'I';
- case BT_LOG_WARN:
+ case BT_LOG_WARNING:
return 'W';
case BT_LOG_ERROR:
return 'E';
*tid = gettid();
#elif defined(__linux__)
*tid = syscall(SYS_gettid);
- #elif defined(__MACH__)
+ #elif defined(__APPLE__) && defined(__MACH__)
*tid = (int)pthread_mach_thread_np(pthread_self());
+ #elif defined(__GNU__)
+ mach_port_t mach_port = mach_thread_self();
+ mach_port_deallocate(mach_task_self(), mach_port);
+ *tid = (int)mach_port;
#else
#define Platform not supported
#endif
static void put_tag(bt_log_message *const msg, const char *const tag)
{
_PP_MAP(_BT_LOG_MESSAGE_FORMAT_INIT, BT_LOG_MESSAGE_TAG_FORMAT)
+
+/*
+ * This generates a -Wundef warning. The issue was reported upstream:
+ *
+ * https://github.com/wonder-mice/zf_log/issues/40
+ *
+ * but there's not much we can do here, so just silence it.
+ */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wundef"
#if !_BT_LOG_MESSAGE_FORMAT_CONTAINS(TAG, BT_LOG_MESSAGE_TAG_FORMAT)
VAR_UNUSED(tag);
#endif
+#pragma GCC diagnostic pop
+
#if !_BT_LOG_MESSAGE_FORMAT_FIELDS(BT_LOG_MESSAGE_TAG_FORMAT)
VAR_UNUSED(msg);
#else
#endif
}
-static void put_msg(bt_log_message *const msg,
+static _BT_LOG_PRINTFLIKE(2, 0)
+void put_msg(bt_log_message *const msg,
const char *const fmt, va_list va)
{
int n;
_bt_log_global_output.callback = callback;
}
-static void _bt_log_write_imp(
+static _BT_LOG_PRINTFLIKE(6, 0)
+void _bt_log_write_imp(
const bt_log_spec *log,
const src_location *const src, const mem_block *const mem,
const int lvl, const char *const tag, const char *const fmt, va_list va)
color_p = bt_common_color_fg_blue();
color_e = color_p + strlen(color_p);
break;
- case BT_LOG_WARN:
+ case BT_LOG_WARNING:
color_p = bt_common_color_fg_yellow();
color_e = color_p + strlen(color_p);
break;