Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
715794b8
Commit
715794b8
authored
Jun 15, 2016
by
Yossi Gottlieb
Committed by
antirez
Jun 23, 2016
Browse files
Add RedisModule_Log() logging API function.
parent
b5072897
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/module.c
View file @
715794b8
...
...
@@ -2768,6 +2768,30 @@ void RM_EmitAOF(RedisModuleIO *io, const char *cmdname, const char *fmt, ...) {
return
;
}
/* --------------------------------------------------------------------------
* Logging
* -------------------------------------------------------------------------- */
/* Produces a log message to the standard Redis log. */
void
RM_Log
(
RedisModuleCtx
*
ctx
,
int
level
,
const
char
*
fmt
,
...)
{
va_list
ap
;
char
msg
[
LOG_MAX_LEN
];
size_t
name_len
;
if
((
level
&
0xff
)
<
server
.
verbosity
)
return
;
if
(
!
ctx
->
module
)
return
;
/* Can only log if module is initialized */
name_len
=
snprintf
(
msg
,
sizeof
(
msg
),
"%s: "
,
ctx
->
module
->
name
);
va_start
(
ap
,
fmt
);
vsnprintf
(
msg
+
name_len
,
sizeof
(
msg
)
-
name_len
,
fmt
,
ap
);
va_end
(
ap
);
serverLogRaw
(
level
,
msg
);
}
/* --------------------------------------------------------------------------
* Modules API internals
* -------------------------------------------------------------------------- */
...
...
@@ -2886,6 +2910,7 @@ void moduleRegisterCoreAPI(void) {
REGISTER_API
(
SaveDouble
);
REGISTER_API
(
LoadDouble
);
REGISTER_API
(
EmitAOF
);
REGISTER_API
(
Log
);
}
/* Global initialization at Redis startup. */
...
...
src/modules/API.md
View file @
715794b8
...
...
@@ -1115,3 +1115,11 @@ by a module. The command works exactly like `RedisModule_Call()` in the way
the parameters are passed, but it does not return anything as the error
handling is performed by Redis itself.
## `RM_Log`
void RM_Log(RedisModuleCtx *ctx, int level, const char *fmt, ...);
Produce a log message into the standard Redis log. All standard Redis logging
configuration applies here. Messages can only be logged after a module has
initialized, and are prefixed by the name of the module. Log level is
specified using the REDISMODULE_LOG_
*
macros.
src/redismodule.h
View file @
715794b8
...
...
@@ -68,6 +68,13 @@
#define REDISMODULE_POSITIVE_INFINITE (1.0/0.0)
#define REDISMODULE_NEGATIVE_INFINITE (-1.0/0.0)
/* Logging levels */
#define REDISMODULE_LOG_DEBUG 0
#define REDISMODULE_LOG_VERBOSE 1
#define REDISMODULE_LOG_NOTICE 2
#define REDISMODULE_LOG_WARNING 3
/* ------------------------- End of common defines ------------------------ */
#ifndef REDISMODULE_CORE
...
...
@@ -180,6 +187,7 @@ RedisModuleString *REDISMODULE_API_FUNC(RedisModule_LoadString)(RedisModuleIO *i
char
*
REDISMODULE_API_FUNC
(
RedisModule_LoadStringBuffer
)(
RedisModuleIO
*
io
,
size_t
*
lenptr
);
void
REDISMODULE_API_FUNC
(
RedisModule_SaveDouble
)(
RedisModuleIO
*
io
,
double
value
);
double
REDISMODULE_API_FUNC
(
RedisModule_LoadDouble
)(
RedisModuleIO
*
io
);
void
REDISMODULE_API_FUNC
(
RedisModule_Log
)(
RedisModuleCtx
*
ctx
,
int
level
,
const
char
*
fmt
,
...);
/* This is included inline inside each Redis module. */
static
int
RedisModule_Init
(
RedisModuleCtx
*
ctx
,
const
char
*
name
,
int
ver
,
int
apiver
)
__attribute__
((
unused
));
...
...
@@ -270,6 +278,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
REDISMODULE_GET_API
(
SaveDouble
);
REDISMODULE_GET_API
(
LoadDouble
);
REDISMODULE_GET_API
(
EmitAOF
);
REDISMODULE_GET_API
(
Log
);
RedisModule_SetModuleAttribs
(
ctx
,
name
,
ver
,
apiver
);
return
REDISMODULE_OK
;
...
...
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