• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-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 #define erofs_dbg(fmt, ...) do {			\
45 	if (cfg.c_dbg_lvl >= EROFS_DBG) {		\
46 		fprintf(stdout,				\
47 			"<D> " PR_FMT_FUNC_LINE(fmt),	\
48 			##__VA_ARGS__);			\
49 	}						\
50 } while (0)
51 
52 #define erofs_info(fmt, ...) do {			\
53 	if (cfg.c_dbg_lvl >= EROFS_INFO) {		\
54 		fprintf(stdout,				\
55 			"<I> " PR_FMT_FUNC_LINE(fmt),	\
56 			##__VA_ARGS__);			\
57 		fflush(stdout);				\
58 	}						\
59 } while (0)
60 
61 #define erofs_warn(fmt, ...) do {			\
62 	if (cfg.c_dbg_lvl >= EROFS_WARN) {		\
63 		fprintf(stdout,				\
64 			"<W> " PR_FMT_FUNC_LINE(fmt),	\
65 			##__VA_ARGS__);			\
66 		fflush(stdout);				\
67 	}						\
68 } while (0)
69 
70 #define erofs_err(fmt, ...) do {			\
71 	if (cfg.c_dbg_lvl >= EROFS_ERR) {		\
72 		fprintf(stderr,				\
73 			"<E> " PR_FMT_FUNC_LINE(fmt),	\
74 			##__VA_ARGS__);			\
75 	}						\
76 } while (0)
77 
78 #define erofs_dump(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
79 
80 #ifdef __cplusplus
81 }
82 #endif
83 
84 #endif
85