Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / log.h
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _LOG_H_
18 #define _LOG_H_
19
20 #define PROX_LOG_PANIC  -1
21 #define PROX_LOG_ERR  0
22 #define PROX_LOG_WARN 1
23 #define PROX_LOG_INFO 2
24 #define PROX_LOG_DBG  3
25
26 #if PROX_MAX_LOG_LVL > PROX_LOG_DBG
27 #error Highest supported log level is 3
28 #endif
29
30 int get_n_warnings(void);
31 /* Return previous warnings, only stores last 5 warnings and invalid i return NULL*/
32 const char* get_warning(int i);
33
34 struct rte_mbuf;
35
36 #if PROX_MAX_LOG_LVL >= PROX_LOG_ERR
37 int plog_err_or_panic(int do_panic, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
38 int plog_err(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
39 int plogx_err(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
40 int plogd_err(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
41 int plogdx_err(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
42 #else
43 __attribute__((format(printf, 2, 3))) static inline int plog_err_or_panic(__attribute__((unused)) int do_panic, __attribute__((unused)) const char *fmt, ...) {return 0;}
44 __attribute__((format(printf, 1, 2))) static inline int plog_err(__attribute__((unused)) const char *fmt, ...) {return 0;}
45 __attribute__((format(printf, 1, 2))) static inline int plogx_err(__attribute__((unused)) const char *fmt, ...) {return 0;}
46 __attribute__((format(printf, 2, 3))) static inline int plogd_err(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
47 __attribute__((format(printf, 2, 3))) static inline int plogdx_err(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
48 #endif
49
50 #if PROX_MAX_LOG_LVL >= PROX_LOG_WARN
51 int plog_warn(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
52 int plogx_warn(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
53 int plogd_warn(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
54 int plogdx_warn(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
55 #else
56 __attribute__((format(printf, 1, 2))) static inline int plog_warn(__attribute__((unused)) const char *fmt, ...) {return 0;}
57 __attribute__((format(printf, 1, 2))) static inline int plogx_warn(__attribute__((unused)) const char *fmt, ...) {return 0;}
58 __attribute__((format(printf, 2, 3))) static inline int plogd_warn(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
59 __attribute__((format(printf, 2, 3))) static inline int plogdx_warn(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
60 #endif
61
62 #if PROX_MAX_LOG_LVL >= PROX_LOG_INFO
63 int plog_info(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
64 int plogx_info(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
65 int plogd_info(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
66 int plogdx_info(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
67 #else
68 __attribute__((format(printf, 1, 2))) static inline int plog_info(__attribute__((unused)) const char *fmt, ...) {return 0;}
69 __attribute__((format(printf, 1, 2))) static inline int plogx_info(__attribute__((unused)) const char *fmt, ...) {return 0;}
70 __attribute__((format(printf, 2, 3))) static inline int plogd_info(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
71 __attribute__((format(printf, 2, 3))) static inline int plogdx_info(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
72 #endif
73
74 #if PROX_MAX_LOG_LVL >= PROX_LOG_DBG
75 int plog_dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
76 int plogx_dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
77 int plogd_dbg(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
78 int plogdx_dbg(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
79 #else
80 __attribute__((format(printf, 1, 2))) static inline int plog_dbg(__attribute__((unused)) const char *fmt, ...) {return 0;}
81 __attribute__((format(printf, 1, 2))) static inline int plogx_dbg(__attribute__((unused)) const char *fmt, ...) {return 0;}
82 __attribute__((format(printf, 2, 3))) static inline int plogd_dbg(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
83 __attribute__((format(printf, 2, 3))) static inline int plogdx_dbg(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
84 #endif
85
86 void plog_init(const char *log_name, int log_name_pid);
87 void plog_end(void);
88 void file_print(const char *str);
89
90 int plog_set_lvl(int lvl);
91
92 #endif /* _LOG_H_ */