Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
8beb268a
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8beb268a
编写于
3月 04, 2022
作者:
S
Shengliang Guan
提交者:
GitHub
3月 04, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10555 from taosdata/feature/config
record log for monitoring
上级
f2292421
09f27bdc
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
61 addition
and
79 deletion
+61
-79
source/libs/monitor/src/monitor.c
source/libs/monitor/src/monitor.c
+3
-4
source/util/src/tlog.c
source/util/src/tlog.c
+58
-75
未找到文件。
source/libs/monitor/src/monitor.c
浏览文件 @
8beb268a
...
...
@@ -25,13 +25,11 @@ static SMonitor tsMonitor = {0};
void
monRecordLog
(
int64_t
ts
,
ELogLevel
level
,
const
char
*
content
)
{
pthread_mutex_lock
(
&
tsMonitor
.
lock
);
int32_t
size
=
taosArrayGetSize
(
tsMonitor
.
logs
);
if
(
size
>=
tsMonitor
.
maxLogs
)
{
uInfo
(
"too many logs for monitor"
);
}
else
{
if
(
size
<
tsMonitor
.
maxLogs
)
{
SMonLogItem
item
=
{.
ts
=
ts
,
.
level
=
level
};
SMonLogItem
*
pItem
=
taosArrayPush
(
tsMonitor
.
logs
,
&
item
);
if
(
pItem
!=
NULL
)
{
tstrncpy
(
pItem
->
content
,
content
,
sizeof
(
item
.
content
)
);
tstrncpy
(
pItem
->
content
,
content
,
MON_LOG_LEN
);
}
}
pthread_mutex_unlock
(
&
tsMonitor
.
lock
);
...
...
@@ -53,6 +51,7 @@ int32_t monInit(const SMonCfg *pCfg) {
}
void
monCleanup
()
{
tsLogFp
=
NULL
;
taosArrayDestroy
(
tsMonitor
.
logs
);
tsMonitor
.
logs
=
NULL
;
pthread_mutex_destroy
(
&
tsMonitor
.
lock
);
...
...
source/util/src/tlog.c
浏览文件 @
8beb268a
...
...
@@ -100,7 +100,7 @@ int64_t dbgBigWN = 0;
int64_t
dbgWSize
=
0
;
static
void
*
taosAsyncOutputLog
(
void
*
param
);
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuff
,
char
*
msg
,
int32_t
msgLen
);
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuff
,
c
onst
c
har
*
msg
,
int32_t
msgLen
);
static
SLogBuff
*
taosLogBuffNew
(
int32_t
bufSize
);
static
void
taosCloseLogByFd
(
TdFilePtr
pFile
);
static
int32_t
taosOpenLogFile
(
char
*
fn
,
int32_t
maxLines
,
int32_t
maxFileNum
);
...
...
@@ -395,33 +395,19 @@ static void taosUpdateLogNums(ELogLevel level) {
}
}
void
taosPrintLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
const
char
*
format
,
...)
{
if
(
!
osLogSpaceAvailable
())
return
;
va_list
argpointer
;
char
buffer
[
LOG_MAX_LINE_BUFFER_SIZE
];
int32_t
len
;
static
inline
int32_t
taosBuildLogHead
(
char
*
buffer
,
const
char
*
flags
)
{
struct
tm
Tm
,
*
ptm
;
struct
timeval
timeSecs
;
time_t
curTime
;
taosGetTimeOfDay
(
&
timeSecs
);
curTime
=
timeSecs
.
tv_sec
;
time_t
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d %08"
PRId64
" "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int32_t
)
timeSecs
.
tv_usec
,
taosGetSelfPthreadId
());
len
+=
sprintf
(
buffer
+
len
,
"%s"
,
flags
);
va_start
(
argpointer
,
format
);
len
+=
vsnprintf
(
buffer
+
len
,
LOG_MAX_LINE_BUFFER_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
if
(
len
>
LOG_MAX_LINE_SIZE
)
len
=
LOG_MAX_LINE_SIZE
;
buffer
[
len
++
]
=
'\n'
;
buffer
[
len
]
=
0
;
return
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d %08"
PRId64
" %s"
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int32_t
)
timeSecs
.
tv_usec
,
taosGetSelfPthreadId
(),
flags
);
}
static
inline
void
taosPrintLogImp
(
ELogLevel
level
,
int32_t
dflag
,
const
char
*
buffer
,
int32_t
len
)
{
if
((
dflag
&
DEBUG_FILE
)
&&
tsLogObj
.
logHandle
&&
tsLogObj
.
logHandle
->
pFile
!=
NULL
)
{
taosUpdateLogNums
(
level
);
if
(
tsAsyncLog
)
{
...
...
@@ -432,8 +418,9 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char
if
(
tsLogObj
.
maxLines
>
0
)
{
atomic_add_fetch_32
(
&
tsLogObj
.
lines
,
1
);
if
((
tsLogObj
.
lines
>
tsLogObj
.
maxLines
)
&&
(
tsLogObj
.
openInProgress
==
0
))
taosOpenNewLogFile
();
if
((
tsLogObj
.
lines
>
tsLogObj
.
maxLines
)
&&
(
tsLogObj
.
openInProgress
==
0
))
{
taosOpenNewLogFile
();
}
}
}
...
...
@@ -442,75 +429,71 @@ void taosPrintLog(const char *flags, ELogLevel level, int32_t dflag, const char
}
}
void
taos
DumpData
(
unsigned
char
*
msg
,
int32_t
len
)
{
void
taos
PrintLog
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
const
char
*
format
,
...
)
{
if
(
!
osLogSpaceAvailable
())
return
;
taosUpdateLogNums
(
DEBUG_DUMP
)
;
if
(
!
(
dflag
&
DEBUG_FILE
)
&&
!
(
dflag
&
DEBUG_SCREEN
))
return
;
char
temp
[
256
];
int32_t
i
,
pos
=
0
,
c
=
0
;
char
buffer
[
LOG_MAX_LINE_BUFFER_SIZE
];
int32_t
len
=
taosBuildLogHead
(
buffer
,
flags
)
;
for
(
i
=
0
;
i
<
len
;
++
i
)
{
sprintf
(
temp
+
pos
,
"%02x "
,
msg
[
i
]);
c
++
;
pos
+=
3
;
if
(
c
>=
16
)
{
temp
[
pos
++
]
=
'\n'
;
taosWriteFile
(
tsLogObj
.
logHandle
->
pFile
,
temp
,
(
uint32_t
)
pos
);
c
=
0
;
pos
=
0
;
}
}
va_list
argpointer
;
va_start
(
argpointer
,
format
);
int32_t
writeLen
=
len
+
vsnprintf
(
buffer
+
len
,
LOG_MAX_LINE_BUFFER_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
temp
[
pos
++
]
=
'\n'
;
if
(
writeLen
>
LOG_MAX_LINE_SIZE
)
writeLen
=
LOG_MAX_LINE_SIZE
;
buffer
[
writeLen
++
]
=
'\n'
;
buffer
[
writeLen
]
=
0
;
taosWriteFile
(
tsLogObj
.
logHandle
->
pFile
,
temp
,
(
uint32_t
)
pos
);
taosPrintLogImp
(
level
,
dflag
,
buffer
,
writeLen
);
if
(
tsLogFp
&&
level
<=
DEBUG_INFO
)
{
buffer
[
writeLen
-
1
]
=
0
;
(
*
tsLogFp
)(
taosGetTimestampMs
(),
level
,
buffer
+
len
);
}
}
void
taosPrintLongString
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
const
char
*
format
,
...)
{
if
(
!
osLogSpaceAvailable
())
return
;
if
(
!
(
dflag
&
DEBUG_FILE
)
&&
!
(
dflag
&
DEBUG_SCREEN
))
return
;
va_list
argpointer
;
char
buffer
[
LOG_MAX_LINE_DUMP_BUFFER_SIZE
];
int32_t
len
;
struct
tm
Tm
,
*
ptm
;
struct
timeval
timeSecs
;
time_t
curTime
;
taosGetTimeOfDay
(
&
timeSecs
);
curTime
=
timeSecs
.
tv_sec
;
ptm
=
localtime_r
(
&
curTime
,
&
Tm
);
len
=
sprintf
(
buffer
,
"%02d/%02d %02d:%02d:%02d.%06d %08"
PRId64
" "
,
ptm
->
tm_mon
+
1
,
ptm
->
tm_mday
,
ptm
->
tm_hour
,
ptm
->
tm_min
,
ptm
->
tm_sec
,
(
int32_t
)
timeSecs
.
tv_usec
,
taosGetSelfPthreadId
());
len
+=
sprintf
(
buffer
+
len
,
"%s"
,
flags
);
int32_t
len
=
taosBuildLogHead
(
buffer
,
flags
);
va_list
argpointer
;
va_start
(
argpointer
,
format
);
len
+=
vsnprintf
(
buffer
+
len
,
LOG_MAX_LINE_DUMP_BUFFER_SIZE
,
format
,
argpointer
);
len
+=
vsnprintf
(
buffer
+
len
,
LOG_MAX_LINE_DUMP_BUFFER_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
if
(
len
>
LOG_MAX_LINE_DUMP_SIZE
)
len
=
LOG_MAX_LINE_DUMP_SIZE
;
buffer
[
len
++
]
=
'\n'
;
buffer
[
len
]
=
0
;
if
((
dflag
&
DEBUG_FILE
)
&&
tsLogObj
.
logHandle
&&
tsLogObj
.
logHandle
->
pFile
!=
NULL
)
{
taosUpdateLogNums
(
level
);
if
(
tsAsyncLog
)
{
taosPushLogBuffer
(
tsLogObj
.
logHandle
,
buffer
,
len
);
}
else
{
taosWriteFile
(
tsLogObj
.
logHandle
->
pFile
,
buffer
,
len
);
}
taosPrintLogImp
(
level
,
dflag
,
buffer
,
len
);
}
if
(
tsLogObj
.
maxLines
>
0
)
{
atomic_add_fetch_32
(
&
tsLogObj
.
lines
,
1
);
void
taosDumpData
(
unsigned
char
*
msg
,
int32_t
len
)
{
if
(
!
osLogSpaceAvailable
())
return
;
taosUpdateLogNums
(
DEBUG_DUMP
);
char
temp
[
256
];
int32_t
i
,
pos
=
0
,
c
=
0
;
if
((
tsLogObj
.
lines
>
tsLogObj
.
maxLines
)
&&
(
tsLogObj
.
openInProgress
==
0
))
taosOpenNewLogFile
();
for
(
i
=
0
;
i
<
len
;
++
i
)
{
sprintf
(
temp
+
pos
,
"%02x "
,
msg
[
i
]);
c
++
;
pos
+=
3
;
if
(
c
>=
16
)
{
temp
[
pos
++
]
=
'\n'
;
taosWriteFile
(
tsLogObj
.
logHandle
->
pFile
,
temp
,
(
uint32_t
)
pos
);
c
=
0
;
pos
=
0
;
}
}
if
(
dflag
&
DEBUG_SCREEN
)
{
write
(
1
,
buffer
,
(
uint32_t
)
len
);
}
temp
[
pos
++
]
=
'\n'
;
taosWriteFile
(
tsLogObj
.
logHandle
->
pFile
,
temp
,
(
uint32_t
)
pos
);
}
static
void
taosCloseLogByFd
(
TdFilePtr
pFile
)
{
...
...
@@ -545,7 +528,7 @@ _err:
return
NULL
;
}
static
void
taosCopyLogBuffer
(
SLogBuff
*
tLogBuff
,
int32_t
start
,
int32_t
end
,
char
*
msg
,
int32_t
msgLen
)
{
static
void
taosCopyLogBuffer
(
SLogBuff
*
tLogBuff
,
int32_t
start
,
int32_t
end
,
c
onst
c
har
*
msg
,
int32_t
msgLen
)
{
if
(
start
>
end
)
{
memcpy
(
LOG_BUF_BUFFER
(
tLogBuff
)
+
end
,
msg
,
msgLen
);
}
else
{
...
...
@@ -559,7 +542,7 @@ static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, ch
LOG_BUF_END
(
tLogBuff
)
=
(
LOG_BUF_END
(
tLogBuff
)
+
msgLen
)
%
LOG_BUF_SIZE
(
tLogBuff
);
}
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuff
,
char
*
msg
,
int32_t
msgLen
)
{
static
int32_t
taosPushLogBuffer
(
SLogBuff
*
tLogBuff
,
c
onst
c
har
*
msg
,
int32_t
msgLen
)
{
int32_t
start
=
0
;
int32_t
end
=
0
;
int32_t
remainSize
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录