Skip to content

Commit 69bc752

Browse files
committed
Add ff_log mod, that encapsulates some interfaces of the rte_log module.
1 parent d4f987e commit 69bc752

File tree

2 files changed

+173
-0
lines changed

2 files changed

+173
-0
lines changed

lib/ff_log.c

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*
25+
*/
26+
27+
#include <string.h>
28+
#include <stdio.h>
29+
#include <stdlib.h>
30+
#include <stdint.h>
31+
#include <getopt.h>
32+
#include <ctype.h>
33+
#include <arpa/inet.h>
34+
#include <rte_log.h>
35+
#include <rte_config.h>
36+
#include <rte_string_fns.h>
37+
38+
#include "ff_config.h"
39+
#include "ff_log.h"
40+
41+
int ff_openlog_stream(FILE *f)
42+
{
43+
return rte_openlog_stream(f);
44+
}
45+
46+
void ff_log_set_global_level(uint32_t level)
47+
{
48+
rte_log_set_global_level(level);
49+
}
50+
51+
int ff_log_set_level(uint32_t logtype, uint32_t level)
52+
{
53+
return rte_log_set_level(logtype, level);
54+
}
55+
56+
int ff_log(uint32_t level, uint32_t logtype, const char *format, ...)
57+
{
58+
va_list ap;
59+
int ret;
60+
61+
va_start(ap, format);
62+
ret = rte_vlog(level, logtype, format, ap);
63+
va_end(ap);
64+
65+
return ret;
66+
}

lib/ff_log.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* Copyright (C) 2017-2021 THL A29 Limited, a Tencent company.
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
*
8+
* 1. Redistributions of source code must retain the above copyright notice, this
9+
* list of conditions and the following disclaimer.
10+
* 2. Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
18+
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
19+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
20+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
21+
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*
25+
*/
26+
27+
#ifndef _FSTACK_LOG_H
28+
#define _FSTACK_LOG_H
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#include <stdint.h>
35+
#include <stdio.h>
36+
#include <stdarg.h>
37+
#include <stdbool.h>
38+
39+
/* FF log type, see rte_log.h */
40+
#define FF_LOGTYPE_EAL 0 /**< Log related to eal. */
41+
#define FF_LOGTYPE_MALLOC 1 /**< Log related to malloc. */
42+
#define FF_LOGTYPE_RING 2 /**< Log related to ring. */
43+
#define FF_LOGTYPE_MEMPOOL 3 /**< Log related to mempool. */
44+
#define FF_LOGTYPE_TIMER 4 /**< Log related to timers. */
45+
#define FF_LOGTYPE_PMD 5 /**< Log related to poll mode driver. */
46+
#define FF_LOGTYPE_HASH 6 /**< Log related to hash table. */
47+
#define FF_LOGTYPE_LPM 7 /**< Log related to LPM. */
48+
#define RTE_LOGTYPE_KNI 8 /**< Log related to KNI. */
49+
#define FF_LOGTYPE_ACL 9 /**< Log related to ACL. */
50+
#define FF_LOGTYPE_POWER 10 /**< Log related to power. */
51+
#define FF_LOGTYPE_METER 11 /**< Log related to QoS meter. */
52+
#define FF_LOGTYPE_SCHED 12 /**< Log related to QoS port scheduler. */
53+
#define FF_LOGTYPE_PORT 13 /**< Log related to port. */
54+
#define FF_LOGTYPE_TABLE 14 /**< Log related to table. */
55+
#define FF_LOGTYPE_PIPELINE 15 /**< Log related to pipeline. */
56+
#define FF_LOGTYPE_MBUF 16 /**< Log related to mbuf. */
57+
#define FF_LOGTYPE_CRYPTODEV 17 /**< Log related to cryptodev. */
58+
#define FF_LOGTYPE_EFD 18 /**< Log related to EFD. */
59+
#define FF_LOGTYPE_EVENTDEV 19 /**< Log related to eventdev. */
60+
#define FF_LOGTYPE_GSO 20 /**< Log related to GSO. */
61+
62+
/* these log types can be used in an application */
63+
#define FF_LOGTYPE_USER1 24 /**< User-defined log type 1. */
64+
#define FF_LOGTYPE_USER2 25 /**< User-defined log type 2. */
65+
#define FF_LOGTYPE_USER3 26 /**< User-defined log type 3. */
66+
#define FF_LOGTYPE_USER4 27 /**< User-defined log type 4. */
67+
#define FF_LOGTYPE_USER5 28 /**< User-defined log type 5. */
68+
#define FF_LOGTYPE_USER6 29 /**< User-defined log type 6. */
69+
70+
/* Used by f-stack lib and freebsd, APP shouldn't use. */
71+
#define FF_LOGTYPE_USER7 30 /**< User-defined log type 7. */
72+
#define FF_LOGTYPE_USER8 31 /**< User-defined log type 8. */
73+
74+
/** First identifier for extended logs */
75+
#define FF_LOGTYPE_FIRST_EXT_ID 32
76+
77+
/* Can't use 0, as it gives compiler warnings */
78+
#define FF_LOG_EMERG 1U /**< System is unusable. */
79+
#define FF_LOG_ALERT 2U /**< Action must be taken immediately. */
80+
#define FF_LOG_CRIT 3U /**< Critical conditions. */
81+
#define FF_LOG_ERR 4U /**< Error conditions. */
82+
#define FF_LOG_WARNING 5U /**< Warning conditions. */
83+
#define FF_LOG_NOTICE 6U /**< Normal but significant condition. */
84+
#define FF_LOG_INFO 7U /**< Informational. */
85+
#define FF_LOG_DEBUG 8U /**< Debug-level messages. */
86+
#define FF_LOG_MAX FF_LOG_DEBUG /**< Most detailed log level. */
87+
88+
#define FF_LOGTYPE_FSTACK_LIB FF_LOGTYPE_USER7
89+
#define FF_LOGTYPE_FSTACK_FREEBSD FF_LOGTYPE_USER8
90+
91+
/* See rte_openlog_stream */
92+
int ff_openlog_stream(FILE *f);
93+
94+
/* See rte_log_set_global_level */
95+
void ff_log_set_global_level(uint32_t level);
96+
97+
/* See rte_log_set_level */
98+
int ff_log_set_level(uint32_t logtype, uint32_t level);
99+
100+
/* See rte_log */
101+
int ff_log(uint32_t level, uint32_t logtype, const char *format, ...);
102+
103+
#ifdef __cplusplus
104+
}
105+
#endif
106+
#endif
107+

0 commit comments

Comments
 (0)