Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
a7a2e3de
Commit
a7a2e3de
authored
Jun 29, 2017
by
Sergey Lyubka
Committed by
Cesanta Bot
Jun 29, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce log filter
PUBLISHED_FROM=b8f538f87e034452032284d45b78090338e87f72
parent
cae0a1cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
17 deletions
+41
-17
mongoose.c
mongoose.c
+41
-17
No files found.
mongoose.c
View file @
a7a2e3de
...
...
@@ -223,36 +223,34 @@ enum cs_log_level {
_LL_MAX
=
5
,
};
/* Set log level. */
void
cs_log_set_level
(
enum
cs_log_level
level
);
/* Set log filter. NULL (a default) logs everything. */
void
cs_log_set_filter
(
char
*
source_file_name
);
int
cs_log_print_prefix
(
enum
cs_log_level
level
,
const
char
*
func
,
const
char
*
filename
);
extern
enum
cs_log_level
cs_log_threshold
;
#if CS_ENABLE_STDIO
void
cs_log_set_file
(
FILE
*
file
);
extern
enum
cs_log_level
cs_log_threshold
;
void
cs_log_print_prefix
(
enum
cs_log_level
level
,
const
char
*
func
);
void
cs_log_printf
(
const
char
*
fmt
,
...)
#ifdef __GNUC__
__attribute__
((
format
(
printf
,
1
,
2
)))
#endif
;
#define LOG(l, x) \
do { \
if (cs_log_threshold >= l) { \
cs_log_print_prefix(l, __func__); \
cs_log_printf x; \
} \
#define LOG(l, x) \
do { \
if (cs_log_print_prefix(l, __func__, __FILE__)) cs_log_printf x; \
} while (0)
#ifndef CS_NDEBUG
#define DBG(x) \
do { \
if (cs_log_threshold >= LL_VERBOSE_DEBUG) { \
cs_log_print_prefix(LL_VERBOSE_DEBUG, __func__); \
cs_log_printf x; \
} \
} while (0)
#define DBG(x) LOG(LL_VERBOSE_DEBUG, x)
#else
/* NDEBUG */
...
...
@@ -287,6 +285,7 @@ void cs_log_printf(const char *fmt, ...)
#include <string.h>
/* Amalgamated: #include "common/cs_time.h" */
/* Amalgamated: #include "common/str_util.h" */
enum
cs_log_level
cs_log_threshold
WEAK
=
#if CS_ENABLE_DEBUG
...
...
@@ -295,6 +294,9 @@ enum cs_log_level cs_log_threshold WEAK =
LL_ERROR
;
#endif
static
char
*
s_filter_pattern
=
NULL
;
static
size_t
s_filter_pattern_len
;
#if CS_ENABLE_STDIO
FILE
*
cs_log_file
WEAK
=
NULL
;
...
...
@@ -305,9 +307,30 @@ double cs_log_ts WEAK;
enum
cs_log_level
cs_log_cur_msg_level
WEAK
=
LL_NONE
;
void
cs_log_print_prefix
(
enum
cs_log_level
level
,
const
char
*
func
)
WEAK
;
void
cs_log_print_prefix
(
enum
cs_log_level
level
,
const
char
*
func
)
{
void
cs_log_set_filter
(
char
*
str
)
WEAK
;
void
cs_log_set_filter
(
char
*
str
)
{
free
(
s_filter_pattern
);
if
(
str
!=
NULL
)
{
s_filter_pattern
=
strdup
(
str
);
s_filter_pattern_len
=
strlen
(
str
);
}
else
{
s_filter_pattern
=
NULL
;
s_filter_pattern_len
=
0
;
}
};
int
cs_log_print_prefix
(
enum
cs_log_level
,
const
char
*
,
const
char
*
)
WEAK
;
int
cs_log_print_prefix
(
enum
cs_log_level
level
,
const
char
*
func
,
const
char
*
filename
)
{
char
prefix
[
21
];
if
(
level
>
cs_log_threshold
)
return
0
;
if
(
s_filter_pattern
!=
NULL
&&
mg_match_prefix
(
s_filter_pattern
,
s_filter_pattern_len
,
func
)
<
0
&&
mg_match_prefix
(
s_filter_pattern
,
s_filter_pattern_len
,
filename
)
<
0
)
{
return
0
;
}
strncpy
(
prefix
,
func
,
20
);
prefix
[
20
]
=
'\0'
;
if
(
cs_log_file
==
NULL
)
cs_log_file
=
stderr
;
...
...
@@ -320,6 +343,7 @@ void cs_log_print_prefix(enum cs_log_level level, const char *func) {
cs_log_ts
=
now
;
}
#endif
return
1
;
}
void
cs_log_printf
(
const
char
*
fmt
,
...)
WEAK
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment