X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Flog.h;h=f2ba0daa6f973ed5cfcd8f915dad132a67184886;hb=HEAD;hp=34ff835b81ba9cae19929a6de9341d39fc44dc0e;hpb=49820b8afd150af8df3c02c717d86b8d2cdf7cad;p=openocd.git diff --git a/src/helper/log.h b/src/helper/log.h index 34ff835b81..d52c05f99d 100644 --- a/src/helper/log.h +++ b/src/helper/log.h @@ -1,3 +1,5 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + /*************************************************************************** * Copyright (C) 2005 by Dominic Rath * * Dominic.Rath@gmx.de * @@ -7,19 +9,6 @@ * * * Copyright (C) 2008 by Spencer Oliver * * spen@spen-soft.co.uk * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * ***************************************************************************/ #ifndef OPENOCD_HELPER_LOG_H @@ -30,7 +19,7 @@ /* To achieve C99 printf compatibility in MinGW, gnu_printf should be * used for __attribute__((format( ... ))), with GCC v4.4 or later */ -#if (defined(IS_MINGW) && (((__GNUC__ << 16) + __GNUC_MINOR__) >= 0x00040004)) +#if (defined(IS_MINGW) && (((__GNUC__ << 16) + __GNUC_MINOR__) >= 0x00040004)) && !defined(__clang__) #define PRINTF_ATTRIBUTE_FORMAT gnu_printf #else #define PRINTF_ATTRIBUTE_FORMAT printf @@ -72,7 +61,7 @@ __attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 5, 6))); * Initialize logging module. Call during program startup. */ void log_init(void); -int set_log_output(struct command_context *cmd_ctx, FILE *output); +void log_exit(void); int log_register_commands(struct command_context *cmd_ctx); @@ -125,6 +114,15 @@ extern int debug_level; expr); \ } while (0) +#define LOG_CUSTOM_LEVEL(level, expr ...) \ + do { \ + enum log_levels _level = level; \ + if (debug_level >= _level) \ + log_printf_lf(_level, \ + __FILE__, __LINE__, __func__, \ + expr); \ + } while (0) + #define LOG_INFO(expr ...) \ log_printf_lf(LOG_LVL_INFO, __FILE__, __LINE__, __func__, expr) @@ -143,6 +141,23 @@ extern int debug_level; #define LOG_OUTPUT(expr ...) \ log_printf(LOG_LVL_OUTPUT, __FILE__, __LINE__, __func__, expr) +/* Output a log entry that is related to a given target */ + +#define LOG_TARGET_DEBUG_IO(target, fmt_str, ...) \ + LOG_DEBUG_IO("[%s] " fmt_str, target_name(target), ##__VA_ARGS__) + +#define LOG_TARGET_DEBUG(target, fmt_str, ...) \ + LOG_DEBUG("[%s] " fmt_str, target_name(target), ##__VA_ARGS__) + +#define LOG_TARGET_INFO(target, fmt_str, ...) \ + LOG_INFO("[%s] " fmt_str, target_name(target), ##__VA_ARGS__) + +#define LOG_TARGET_WARNING(target, fmt_str, ...) \ + LOG_WARNING("[%s] " fmt_str, target_name(target), ##__VA_ARGS__) + +#define LOG_TARGET_ERROR(target, fmt_str, ...) \ + LOG_ERROR("[%s] " fmt_str, target_name(target), ##__VA_ARGS__) + /* general failures * error codes < 100 */