1 /* SPDX-License-Identifier: GPL-2.0+ OR Apache-2.0 */ 2 /* 3 * Copyright (C) 2018-2019 HUAWEI, Inc. 4 * http://www.huawei.com/ 5 * Created by Li Guifu <bluce.liguifu@huawei.com> 6 */ 7 #ifndef __EROFS_PRINT_H 8 #define __EROFS_PRINT_H 9 10 #ifdef __cplusplus 11 extern "C" 12 { 13 #endif 14 15 #include "config.h" 16 #include <stdio.h> 17 18 enum { 19 EROFS_MSG_MIN = 0, 20 EROFS_ERR = 0, 21 EROFS_WARN = 2, 22 EROFS_INFO = 3, 23 EROFS_DBG = 7, 24 EROFS_MSG_MAX = 9 25 }; 26 27 #ifndef EROFS_MODNAME 28 #define EROFS_MODNAME "erofs" 29 #endif 30 #define FUNC_LINE_FMT "%s() Line[%d] " 31 32 #ifdef NDEBUG 33 #ifndef pr_fmt 34 #define pr_fmt(fmt) EROFS_MODNAME ": " fmt "\n" 35 #endif 36 #define PR_FMT_FUNC_LINE(fmt) pr_fmt(fmt) 37 #else 38 #ifndef pr_fmt 39 #define pr_fmt(fmt) EROFS_MODNAME ": " FUNC_LINE_FMT fmt "\n" 40 #endif 41 #define PR_FMT_FUNC_LINE(fmt) pr_fmt(fmt), __func__, __LINE__ 42 #endif 43 44 void erofs_msg(int dbglv, const char *fmt, ...); 45 46 #define erofs_dbg(fmt, ...) do { \ 47 if (cfg.c_dbg_lvl >= EROFS_DBG) { \ 48 erofs_msg(EROFS_DBG, \ 49 "<D> " PR_FMT_FUNC_LINE(fmt), \ 50 ##__VA_ARGS__); \ 51 } \ 52 } while (0) 53 54 #define erofs_info(fmt, ...) do { \ 55 if (cfg.c_dbg_lvl >= EROFS_INFO) { \ 56 erofs_msg(EROFS_INFO, \ 57 "<I> " PR_FMT_FUNC_LINE(fmt), \ 58 ##__VA_ARGS__); \ 59 fflush(stdout); \ 60 } \ 61 } while (0) 62 63 #define erofs_warn(fmt, ...) do { \ 64 if (cfg.c_dbg_lvl >= EROFS_WARN) { \ 65 erofs_msg(EROFS_WARN, \ 66 "<W> " PR_FMT_FUNC_LINE(fmt), \ 67 ##__VA_ARGS__); \ 68 fflush(stdout); \ 69 } \ 70 } while (0) 71 72 #define erofs_err(fmt, ...) do { \ 73 if (cfg.c_dbg_lvl >= EROFS_ERR) { \ 74 erofs_msg(EROFS_ERR, \ 75 "<E> " PR_FMT_FUNC_LINE(fmt), \ 76 ##__VA_ARGS__); \ 77 } \ 78 } while (0) 79 80 #define erofs_dump(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__) 81 82 #ifdef __cplusplus 83 } 84 #endif 85 86 #endif 87