0d2fba18eb05b3bf8b47fa5e6481139594bedf9e
[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_ERR  0
21 #define PROX_LOG_WARN 1
22 #define PROX_LOG_INFO 2
23 #define PROX_LOG_DBG  3
24
25 #if PROX_MAX_LOG_LVL > PROX_LOG_DBG
26 #error Highest supported log level is 3
27 #endif
28
29 int get_n_warnings(void);
30 /* Return previous warnings, only stores last 5 warnings and invalid i return NULL*/
31 const char* get_warning(int i);
32
33 struct rte_mbuf;
34
35 #if PROX_MAX_LOG_LVL >= PROX_LOG_ERR
36 int plog_err(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
37 int plogx_err(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
38 int plogd_err(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
39 int plogdx_err(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
40 #else
41 __attribute__((format(printf, 1, 2))) static inline int plog_err(__attribute__((unused)) const char *fmt, ...) {return 0;}
42 __attribute__((format(printf, 1, 2))) static inline int plogx_err(__attribute__((unused)) const char *fmt, ...) {return 0;}
43 __attribute__((format(printf, 2, 3))) static inline int plogd_err(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
44 __attribute__((format(printf, 2, 3))) static inline int plogdx_err(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
45 #endif
46
47 #if PROX_MAX_LOG_LVL >= PROX_LOG_WARN
48 int plog_warn(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
49 int plogx_warn(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
50 int plogd_warn(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
51 int plogdx_warn(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
52 #else
53 __attribute__((format(printf, 1, 2))) static inline int plog_warn(__attribute__((unused)) const char *fmt, ...) {return 0;}
54 __attribute__((format(printf, 1, 2))) static inline int plogx_warn(__attribute__((unused)) const char *fmt, ...) {return 0;}
55 __attribute__((format(printf, 2, 3))) static inline int plogd_warn(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
56 __attribute__((format(printf, 2, 3))) static inline int plogdx_warn(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
57 #endif
58
59 #if PROX_MAX_LOG_LVL >= PROX_LOG_INFO
60 int plog_info(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
61 int plogx_info(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
62 int plogd_info(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
63 int plogdx_info(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
64 #else
65 __attribute__((format(printf, 1, 2))) static inline int plog_info(__attribute__((unused)) const char *fmt, ...) {return 0;}
66 __attribute__((format(printf, 1, 2))) static inline int plogx_info(__attribute__((unused)) const char *fmt, ...) {return 0;}
67 __attribute__((format(printf, 2, 3))) static inline int plogd_info(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
68 __attribute__((format(printf, 2, 3))) static inline int plogdx_info(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
69 #endif
70
71 #if PROX_MAX_LOG_LVL >= PROX_LOG_DBG
72 int plog_dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
73 int plogx_dbg(const char *fmt, ...) __attribute__((format(printf, 1, 2), cold));
74 int plogd_dbg(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
75 int plogdx_dbg(const struct rte_mbuf *mbuf, const char *fmt, ...) __attribute__((format(printf, 2, 3), cold));
76 #else
77 __attribute__((format(printf, 1, 2))) static inline int plog_dbg(__attribute__((unused)) const char *fmt, ...) {return 0;}
78 __attribute__((format(printf, 1, 2))) static inline int plogx_dbg(__attribute__((unused)) const char *fmt, ...) {return 0;}
79 __attribute__((format(printf, 2, 3))) static inline int plogd_dbg(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
80 __attribute__((format(printf, 2, 3))) static inline int plogdx_dbg(__attribute__((unused)) const struct rte_mbuf *mbuf, __attribute__((unused)) const char *fmt, ...) {return 0;}
81 #endif
82
83 void plog_init(const char *log_name, int log_name_pid);
84 void plog_end(void);
85 void file_print(const char *str);
86
87 int plog_set_lvl(int lvl);
88
89 #endif /* _LOG_H_ */