Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
0e1891e5
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0e1891e5
编写于
5月 17, 2018
作者:
L
liuruilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format files
上级
f1426f03
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
118 addition
and
115 deletion
+118
-115
src/common/log.h
src/common/log.h
+109
-106
test/unit-test/test_log.cpp
test/unit-test/test_log.cpp
+9
-9
未找到文件。
src/common/log.h
浏览文件 @
0e1891e5
...
...
@@ -27,125 +27,128 @@ SOFTWARE.
namespace
paddle_mobile
{
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
// log level
static
LogLevel
log_level
=
kLOG_DEBUG4
;
static
std
::
vector
<
std
::
string
>
logs
{
"NO"
,
"ERROR "
,
"WARNING"
,
"INFO "
,
"DEBUG "
,
"DEBUG1 "
,
"DEBUG2 "
,
"DEBUG3 "
,
"DEBUG4 "
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{
buffer_
<<
value
;
return
*
this
;
}
private:
void
print
(
LogLevel
level
)
{
buffer_
<<
std
::
endl
;
if
(
level
==
kLOG_ERROR
)
{
std
::
cerr
<<
buffer_
.
str
();
}
else
{
std
::
cout
<<
buffer_
.
str
();
}
}
std
::
ostringstream
buffer_
;
};
struct
ToLog
{
ToLog
(
LogLevel
level
=
kLOG_DEBUG
,
const
std
::
string
&
info
=
""
)
:
level_
(
level
)
{
unsigned
blanks
=
(
unsigned
)(
level
>
kLOG_DEBUG
?
(
level
-
kLOG_DEBUG
)
*
4
:
1
);
printer_
<<
logs
[
level
]
<<
" "
<<
info
<<
":"
<<
std
::
string
(
blanks
,
' '
);
}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
printer_
<<
value
;
return
*
this
;
}
~
ToLog
()
{
printer_
.
print
(
level_
);
}
private:
LogLevel
level_
;
Print
printer_
;
};
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
// log level
static
LogLevel
log_level
=
kLOG_DEBUG4
;
static
std
::
vector
<
std
::
string
>
logs
{
"NO"
,
"ERROR "
,
"WARNING"
,
"INFO "
,
"DEBUG "
,
"DEBUG1 "
,
"DEBUG2 "
,
"DEBUG3 "
,
"DEBUG4 "
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{
buffer_
<<
value
;
return
*
this
;
}
private:
void
print
(
LogLevel
level
)
{
buffer_
<<
std
::
endl
;
if
(
level
==
kLOG_ERROR
)
{
std
::
cerr
<<
buffer_
.
str
();
}
else
{
std
::
cout
<<
buffer_
.
str
();
}
}
std
::
ostringstream
buffer_
;
};
struct
ToLog
{
ToLog
(
LogLevel
level
=
kLOG_DEBUG
,
const
std
::
string
&
info
=
""
)
:
level_
(
level
)
{
unsigned
blanks
=
(
unsigned
)(
level
>
kLOG_DEBUG
?
(
level
-
kLOG_DEBUG
)
*
4
:
1
);
printer_
<<
logs
[
level
]
<<
" "
<<
info
<<
":"
<<
std
::
string
(
blanks
,
' '
);
}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
printer_
<<
value
;
return
*
this
;
}
~
ToLog
()
{
printer_
.
print
(
level_
);
}
private:
LogLevel
level_
;
Print
printer_
;
};
#define LOG(level) \
if (level > paddle_mobile::log_level) {
\
} else
\
paddle_mobile::ToLog(level,
\
(std::stringstream()
\
<< "[file: " << (strrchr(__FILE__, '/')
\
? (strrchr(__FILE__, '/') + 1)
\
: __FILE__)
\
<< "] [line: " << __LINE__ << "] ")
\
.str())
if (level > paddle_mobile::log_level) {
\
} else
\
paddle_mobile::ToLog(
\
level,
\
(std::stringstream()
\
<< "[file: "
\
<< (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__)
\
<< "] [line: " << __LINE__ << "] ")
\
.str())
#define DLOG \
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG,
\
(std::stringstream()
\
<< "[file: " << (strrchr(__FILE__, '/')
\
? (strrchr(__FILE__, '/') + 1)
\
: __FILE__)
\
<< "] [line: " << __LINE__ << "] ")
\
.str())
paddle_mobile::ToLog(
\
paddle_mobile::kLOG_DEBUG,
\
(std::stringstream()
\
<< "[file: "
\
<< (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__)
\
<< "] [line: " << __LINE__ << "] ")
\
.str())
}
#else
namespace
paddle_mobile
{
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{}
private:
};
struct
ToLog
{
ToLog
(
LogLevel
level
)
{}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
return
*
this
;
}
};
enum
LogLevel
{
kNO_LOG
,
kLOG_ERROR
,
kLOG_WARNING
,
kLOG_INFO
,
kLOG_DEBUG
,
kLOG_DEBUG1
,
kLOG_DEBUG2
,
kLOG_DEBUG3
,
kLOG_DEBUG4
};
struct
ToLog
;
struct
Print
{
friend
struct
ToLog
;
template
<
typename
T
>
Print
&
operator
<<
(
T
const
&
value
)
{}
private:
};
struct
ToLog
{
ToLog
(
LogLevel
level
)
{}
template
<
typename
T
>
ToLog
&
operator
<<
(
T
const
&
value
)
{
return
*
this
;
}
};
#define LOG(level) \
if (true) {
\
} else
\
paddle_mobile::ToLog(level)
if (true) {
\
} else
\
paddle_mobile::ToLog(level)
#define DLOG \
if (true) {
\
} else
\
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG)
if (true) {
\
} else
\
paddle_mobile::ToLog(paddle_mobile::kLOG_DEBUG)
}
#endif
test/unit-test/test_log.cpp
浏览文件 @
0e1891e5
...
...
@@ -19,13 +19,13 @@ SOFTWARE.
#include "common/log.h"
int
main
()
{
LOG
(
paddle_mobile
::
kLOG_DEBUG
)
<<
"test debug"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
"test debug1"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG2
)
<<
"test debug2"
<<
" next log"
;
DLOG
<<
"test DLOG"
;
LOG
(
paddle_mobile
::
kLOG_ERROR
)
<<
" error occur !"
;
return
0
;
LOG
(
paddle_mobile
::
kLOG_DEBUG
)
<<
"test debug"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG1
)
<<
"test debug1"
<<
" next log"
;
LOG
(
paddle_mobile
::
kLOG_DEBUG2
)
<<
"test debug2"
<<
" next log"
;
DLOG
<<
"test DLOG"
;
LOG
(
paddle_mobile
::
kLOG_ERROR
)
<<
" error occur !"
;
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录