Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
17b71c1d
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1187
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
17b71c1d
编写于
3月 04, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refact log
上级
d4141672
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
51 addition
and
75 deletion
+51
-75
source/util/src/tlog.c
source/util/src/tlog.c
+51
-75
未找到文件。
source/util/src/tlog.c
浏览文件 @
17b71c1d
...
...
@@ -17,10 +17,10 @@
#include "tlog.h"
#include "tutil.h"
#define LOG_MAX_LINE_SIZE
(1024)
#define LOG_MAX_LINE_BUFFER_SIZE
(LOG_MAX_LINE_SIZE + 3)
#define LOG_MAX_LINE_DUMP_SIZE
(65 * 1024)
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE
(LOG_MAX_LINE_DUMP_SIZE + 3)
#define LOG_MAX_LINE_SIZE (1024)
#define LOG_MAX_LINE_BUFFER_SIZE (LOG_MAX_LINE_SIZE + 3)
#define LOG_MAX_LINE_DUMP_SIZE (65 * 1024)
#define LOG_MAX_LINE_DUMP_BUFFER_SIZE (LOG_MAX_LINE_DUMP_SIZE + 3)
#define LOG_FILE_NAME_LEN 300
#define LOG_DEFAULT_BUF_SIZE (20 * 1024 * 1024) // 20MB
...
...
@@ -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,64 @@ 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
);
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
);
len
+=
vsnprintf
(
buffer
+
len
,
LOG_MAX_LINE_BUFFER_SIZE
-
len
,
format
,
argpointer
);
va_end
(
argpointer
);
temp
[
pos
++
]
=
'\n'
;
if
(
len
>
LOG_MAX_LINE_SIZE
)
len
=
LOG_MAX_LINE_SIZE
;
buffer
[
len
++
]
=
'\n'
;
buffer
[
len
]
=
0
;
taos
WriteFile
(
tsLogObj
.
logHandle
->
pFile
,
temp
,
(
uint32_t
)
pos
);
taos
PrintLogImp
(
level
,
dflag
,
buffer
,
len
);
}
void
taosPrintLongString
(
const
char
*
flags
,
ELogLevel
level
,
int32_t
dflag
,
const
char
*
format
,
...)
{
if
(
!
osLogSpaceAvailable
())
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
);
char
buffer
[
LOG_MAX_LINE_DUMP_BUFFER_SIZE
];
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
);
if
((
tsLogObj
.
lines
>
tsLogObj
.
maxLines
)
&&
(
tsLogObj
.
openInProgress
==
0
))
taosOpenNewLogFile
();
char
temp
[
256
];
int32_t
i
,
pos
=
0
,
c
=
0
;
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 +521,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 +535,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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录