Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
别团等shy哥发育
redis
提交
09eadf5c
R
redis
项目概览
别团等shy哥发育
/
redis
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
redis
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
09eadf5c
编写于
11月 12, 2015
作者:
E
Enrico Giordani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Code cleanup] Event log code refactoring. Code formatting.
Rollbacked setLogFile method name.
上级
d9369130
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
97 addition
and
35 deletion
+97
-35
src/Win32_Interop/Win32_EventLog.cpp
src/Win32_Interop/Win32_EventLog.cpp
+71
-11
src/Win32_Interop/Win32_EventLog.h
src/Win32_Interop/Win32_EventLog.h
+12
-3
src/Win32_Interop/Win32_QFork.cpp
src/Win32_Interop/Win32_QFork.cpp
+4
-3
src/Win32_Interop/Win32_RedisLog.c
src/Win32_Interop/Win32_RedisLog.c
+7
-14
src/Win32_Interop/Win32_RedisLog.h
src/Win32_Interop/Win32_RedisLog.h
+1
-3
src/config.c
src/config.c
+2
-1
未找到文件。
src/Win32_Interop/Win32_EventLog.cpp
浏览文件 @
09eadf5c
...
...
@@ -32,6 +32,13 @@ using namespace std;
#include "Win32_SmartHandle.h"
#include "EventLog.h"
static
bool
eventLogEnabled
=
true
;
static
string
eventLogIdentity
=
"redis"
;
void
RedisEventLog
::
SetEventLogIdentity
(
const
char
*
identity
)
{
eventLogIdentity
=
string
(
identity
);
}
void
RedisEventLog
::
UninstallEventLogSource
()
{
SmartRegistryHandle
appKey
;
if
(
ERROR_SUCCESS
==
RegOpenKeyA
(
HKEY_LOCAL_MACHINE
,
cEventLogApplicitonPath
.
c_str
(),
appKey
))
{
...
...
@@ -82,20 +89,20 @@ void RedisEventLog::InstallEventLogSource(string appPath) {
DWORD
type
=
REG_DWORD
;
DWORD
size
=
sizeof
(
DWORD
);
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
type
=
REG_SZ
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redisserver
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
SmartRegistryHandle
application
;
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cApplication
.
c_str
()
,
application
))
{
if
(
ERROR_SUCCESS
!=
RegOpenKeyA
(
eventLogKey
,
cApplication
.
c_str
(),
application
))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegCreateKeyA failed"
);
}
SmartRegistryHandle
redis2
;
...
...
@@ -107,18 +114,18 @@ void RedisEventLog::InstallEventLogSource(string appPath) {
type
=
REG_DWORD
;
size
=
0
;
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cTypesSupported
.
c_str
(),
0
,
REG_DWORD
,
(
const
BYTE
*
)
&
value
,
sizeof
(
DWORD
)))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
if
(
ERROR_SUCCESS
!=
RegQueryValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
&
type
,
NULL
,
&
size
))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
if
(
ERROR_SUCCESS
!=
RegSetValueExA
(
redis2
,
cEventMessageFile
.
c_str
(),
0
,
REG_SZ
,
(
BYTE
*
)
appPath
.
c_str
(),
(
DWORD
)
appPath
.
length
()))
{
throw
std
::
system_error
(
GetLastError
(),
system_category
(),
"RegSetValueExA failed"
);
}
}
}
void
RedisEventLog
::
LogMessage
ToEventLog
(
LPCSTR
msg
,
const
WORD
type
)
{
void
RedisEventLog
::
LogMessage
(
LPCSTR
msg
,
const
WORD
type
)
{
DWORD
eventID
;
switch
(
type
)
{
case
EVENTLOG_ERROR_TYPE
:
...
...
@@ -141,7 +148,7 @@ void RedisEventLog::LogMessageToEventLog(LPCSTR msg, const WORD type) {
if
(
0
==
hEventLog
)
{
std
::
cerr
<<
"Failed open source '"
<<
this
->
eventLogName
<<
"': "
<<
GetLastError
()
<<
endl
;
}
else
{
if
(
FALSE
==
ReportEventA
(
hEventLog
,
type
,
0
,
eventID
,
0
,
1
,
0
,
&
msg
,
0
))
{
if
(
FALSE
==
ReportEventA
(
hEventLog
,
type
,
0
,
eventID
,
0
,
1
,
0
,
&
msg
,
0
))
{
std
::
cerr
<<
"Failed to write message: "
<<
GetLastError
()
<<
endl
;
}
...
...
@@ -149,12 +156,65 @@ void RedisEventLog::LogMessageToEventLog(LPCSTR msg, const WORD type) {
}
}
extern
"C"
void
WriteEventLog
(
const
char
*
sysLogInstance
,
const
char
*
msg
)
{
void
RedisEventLog
::
LogError
(
string
msg
)
{
try
{
if
(
eventLogEnabled
==
true
)
{
stringstream
ss
;
ss
<<
"syslog-ident = "
<<
eventLogIdentity
<<
endl
;
ss
<<
msg
;
RedisEventLog
().
LogMessage
(
ss
.
str
().
c_str
(),
EVENTLOG_ERROR_TYPE
);
}
}
catch
(...)
{
}
}
string
RedisEventLog
::
GetEventLogIdentity
()
{
return
eventLogIdentity
;
}
void
RedisEventLog
::
EnableEventLog
(
bool
enabled
)
{
eventLogEnabled
=
enabled
;
}
bool
RedisEventLog
::
IsEventLogEnabled
()
{
return
eventLogEnabled
;
}
extern
"C"
void
setSyslogEnabled
(
int
enabled
)
{
try
{
if
(
enabled
==
1
)
{
RedisEventLog
().
EnableEventLog
(
true
);
}
else
{
RedisEventLog
().
EnableEventLog
(
false
);
}
}
catch
(...)
{}
}
extern
"C"
void
setSyslogIdent
(
char
*
identity
)
{
try
{
RedisEventLog
().
SetEventLogIdentity
(
identity
);
}
catch
(...)
{}
}
extern
"C"
void
WriteEventLog
(
const
char
*
msg
)
{
try
{
stringstream
ss
;
ss
<<
"syslog-ident = "
<<
sysLogInstance
<<
endl
;
ss
<<
"syslog-ident = "
<<
RedisEventLog
().
GetEventLogIdentity
()
<<
endl
;
ss
<<
msg
;
RedisEventLog
().
LogMessageToEventLog
(
ss
.
str
().
c_str
(),
EVENTLOG_INFORMATION_TYPE
);
}
catch
(...)
{
RedisEventLog
().
LogMessage
(
ss
.
str
().
c_str
(),
EVENTLOG_INFORMATION_TYPE
);
}
catch
(...)
{}
}
extern
"C"
int
IsEventLogEnabled
()
{
try
{
if
(
RedisEventLog
().
IsEventLogEnabled
()
==
true
)
{
return
1
;
}
}
catch
(...)
{}
return
0
;
}
src/Win32_Interop/Win32_EventLog.h
浏览文件 @
09eadf5c
...
...
@@ -33,10 +33,16 @@ public:
void
InstallEventLogSource
(
string
appPath
);
void
UninstallEventLogSource
();
void
LogMessageToEventLog
(
LPCSTR
msg
,
const
WORD
type
);
void
SetEventLogIdentity
(
const
char
*
identity
);
private:
void
LogMessage
(
LPCSTR
msg
,
const
WORD
type
);
void
LogError
(
string
msg
);
string
GetEventLogIdentity
();
void
EnableEventLog
(
bool
enabled
);
bool
IsEventLogEnabled
();
private:
const
string
eventLogName
=
"redis"
;
const
string
cEventLogPath
=
"SYSTEM
\\
CurrentControlSet
\\
Services
\\
EventLog
\\
"
;
const
string
cEventLogApplicitonPath
=
cEventLogPath
+
"Application
\\
"
;
...
...
@@ -50,7 +56,10 @@ private:
extern
"C"
{
#endif
void
WriteEventLog
(
const
char
*
sysLogInstance
,
const
char
*
msg
);
void
setSyslogEnabled
(
int
enabled
);
void
setSyslogIdent
(
char
*
identity
);
int
IsEventLogEnabled
();
void
WriteEventLog
(
const
char
*
msg
);
#ifdef __cplusplus
}
...
...
src/Win32_Interop/Win32_QFork.cpp
浏览文件 @
09eadf5c
...
...
@@ -105,6 +105,7 @@ allocate a system paging file that will expand up to about (3.5 * physical).
#include "Win32_RedisLog.h"
#include "Win32_StackTrace.h"
#include "Win32_ThreadControl.h"
#include "Win32_EventLog.h"
#ifdef USE_DLMALLOC
#include "Win32_dlmalloc.h"
...
...
@@ -1110,11 +1111,11 @@ void SetupLogging() {
string
syslogIdent
=
(
g_argMap
.
find
(
cSyslogIdent
)
!=
g_argMap
.
end
()
?
g_argMap
[
cSyslogIdent
].
at
(
0
).
at
(
0
)
:
cDefaultSyslogIdent
);
string
logFileName
=
(
g_argMap
.
find
(
cLogfile
)
!=
g_argMap
.
end
()
?
g_argMap
[
cLogfile
].
at
(
0
).
at
(
0
)
:
cDefaultLogfile
);
setSyslogEnabled
(
syslogEnabled
);
RedisEventLog
().
EnableEventLog
(
syslogEnabled
);
if
(
syslogEnabled
)
{
setSyslogIdent
(
syslogIdent
.
c_str
());
RedisEventLog
().
SetEventLogIdentity
(
syslogIdent
.
c_str
());
}
else
{
setLogFile
name
(
logFileName
.
c_str
());
setLogFile
(
logFileName
.
c_str
());
}
}
...
...
src/Win32_Interop/Win32_RedisLog.c
浏览文件 @
09eadf5c
...
...
@@ -36,20 +36,10 @@
static
const
char
ellipsis
[]
=
"[...]"
;
static
const
char
ellipsisWithNewLine
[]
=
"[...]
\n
"
;
static
int
verbosity
=
REDIS_WARNING
;
static
int
syslogEnabled
=
0
;
static
char
syslogIdent
[
MAX_PATH
];
static
HANDLE
hLogFile
=
INVALID_HANDLE_VALUE
;
static
int
isStdout
=
0
;
static
char
*
logFilename
=
NULL
;
void
setSyslogEnabled
(
int
flag
)
{
syslogEnabled
=
flag
;
}
void
setSyslogIdent
(
const
char
*
ident
)
{
strcpy_s
(
syslogIdent
,
MAX_PATH
,
ident
);
}
void
setLogVerbosityLevel
(
int
level
)
{
verbosity
=
level
;
...
...
@@ -64,9 +54,10 @@ const char* getLogFilename() {
}
/* We keep the file handle open to improve performance.
* This assumes that calls to redisLog and setLogFile will not happen concurrently.
*/
void
setLogFilename
(
const
char
*
filename
)
* This assumes that calls to redisLog and setLogFile will not happen
* concurrently.
*/
void
setLogFile
(
const
char
*
filename
)
{
if
(
logFilename
!=
NULL
)
{
free
((
void
*
)
logFilename
);
...
...
@@ -187,7 +178,9 @@ void redisLogRaw(int level, const char *msg) {
FlushFileBuffers
(
hLogFile
);
#endif
if
(
syslogEnabled
)
WriteEventLog
(
syslogIdent
,
msg
);
if
(
IsEventLogEnabled
()
==
1
)
{
WriteEventLog
(
msg
);
}
}
/* Like redisLogRaw() but with printf-alike support. This is the function that
...
...
src/Win32_Interop/Win32_RedisLog.h
浏览文件 @
09eadf5c
...
...
@@ -39,10 +39,8 @@
extern
"C"
{
#endif
void
setSyslogEnabled
(
int
flag
);
void
setSyslogIdent
(
const
char
*
ident
);
void
setLogVerbosityLevel
(
int
level
);
void
setLogFile
name
(
const
char
*
filename
);
void
setLogFile
(
const
char
*
filename
);
const
char
*
getLogFilename
();
void
redisLogRaw
(
int
level
,
const
char
*
msg
);
void
redisLog
(
int
level
,
const
char
*
fmt
,
...);
...
...
src/config.c
浏览文件 @
09eadf5c
...
...
@@ -30,6 +30,7 @@
#ifdef _WIN32
#include "Win32_Interop/win32_types.h"
#include "Win32_Interop/Win32_EventLog.h"
#include <direct.h>
#endif
...
...
@@ -217,7 +218,7 @@ void loadServerConfigFromString(char *config) {
goto
loaderr
;
#ifdef _WIN32
}
else
{
setLogFile
name
(
server
.
logfile
);
setLogFile
(
server
.
logfile
);
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录