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