Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
spdlog
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
spdlog
Commits
de0154c5
Commit
de0154c5
authored
Jun 17, 2017
by
Asit Kumar Dhal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test Case for conditional logging
parent
380233b7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
1 deletion
+153
-1
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+1
-1
tests/cond_logging.cpp
tests/cond_logging.cpp
+148
-0
tests/tests.vcxproj
tests/tests.vcxproj
+1
-0
tests/tests.vcxproj.filters
tests/tests.vcxproj.filters
+3
-0
No files found.
include/spdlog/details/logger_impl.h
View file @
de0154c5
...
...
@@ -310,7 +310,7 @@ inline void spdlog::logger::error_if(const bool flag, const T& msg)
{
if
(
flag
)
{
log
(
level
::
err
or
,
msg
);
log
(
level
::
err
,
msg
);
}
}
...
...
tests/cond_logging.cpp
0 → 100644
View file @
de0154c5
#include "includes.h"
template
<
class
T
>
std
::
string
conditional_log
(
const
bool
flag
,
const
T
&
what
,
spdlog
::
level
::
level_enum
logger_level
)
{
std
::
ostringstream
oss
;
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
oss_logger
.
set_level
(
logger_level
);
oss_logger
.
set_pattern
(
"%v"
);
switch
(
logger_level
)
{
case
spdlog
:
:
level
::
trace
:
oss_logger
.
trace_if
(
flag
,
what
);
break
;
case
spdlog
:
:
level
::
debug
:
oss_logger
.
debug_if
(
flag
,
what
);
break
;
case
spdlog
:
:
level
::
info
:
oss_logger
.
info_if
(
flag
,
what
);
break
;
case
spdlog
:
:
level
::
warn
:
oss_logger
.
warn_if
(
flag
,
what
);
break
;
case
spdlog
:
:
level
::
err
:
oss_logger
.
error_if
(
flag
,
what
);
break
;
case
spdlog
:
:
level
::
critical
:
oss_logger
.
critical_if
(
flag
,
what
);
break
;
}
return
oss
.
str
().
substr
(
0
,
oss
.
str
().
length
()
-
spdlog
::
details
::
os
::
eol_size
);
}
template
<
typename
Arg1
,
typename
...
Args
>
std
::
string
conditional_log_varags
(
spdlog
::
level
::
level_enum
logger_level
,
const
bool
flag
,
const
char
*
fmt
,
const
Arg1
&
arg1
,
const
Args
&
...
args
)
{
std
::
ostringstream
oss
;
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
oss_logger
.
set_level
(
logger_level
);
oss_logger
.
set_pattern
(
"%v"
);
switch
(
logger_level
)
{
case
spdlog
:
:
level
::
trace
:
oss_logger
.
trace_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
debug
:
oss_logger
.
debug_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
info
:
oss_logger
.
info_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
warn
:
oss_logger
.
warn_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
err
:
oss_logger
.
error_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
critical
:
oss_logger
.
critical_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
}
return
oss
.
str
().
substr
(
0
,
oss
.
str
().
length
()
-
spdlog
::
details
::
os
::
eol_size
);
}
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
template
<
typename
Arg1
,
typename
...
Args
>
std
::
wstring
conditional_log_varags
(
spdlog
::
level
::
level_enum
logger_level
,
const
bool
flag
,
const
wchar_t
*
fmt
,
const
Arg1
&
arg1
,
const
Args
&
...
args
)
{
std
::
wstringstream
oss
;
auto
oss_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
ostream_sink_mt
>
(
oss
);
spdlog
::
logger
oss_logger
(
"oss"
,
oss_sink
);
oss_logger
.
set_level
(
logger_level
);
oss_logger
.
set_pattern
(
"%v"
);
switch
(
logger_level
)
{
case
spdlog
:
:
level
::
trace
:
oss_logger
.
trace_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
debug
:
oss_logger
.
debug_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
info
:
oss_logger
.
info_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
warn
:
oss_logger
.
warn_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
err
:
oss_logger
.
error_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
case
spdlog
:
:
level
::
critical
:
oss_logger
.
critical_if
(
flag
,
fmt
,
arg1
,
args
...);
break
;
}
return
oss
.
str
().
substr
(
0
,
oss
.
str
().
length
()
-
spdlog
::
details
::
os
::
eol_size
);
}
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
TEST_CASE
(
"conditional_trace_simple"
,
"[conditional_trace_simple]"
)
{
//const char
for
(
auto
i
=
0
;
i
<
2
;
i
++
)
{
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
trace
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
debug
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
info
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
warn
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
err
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
REQUIRE
(
conditional_log
((
i
%
2
==
0
),
"Hello"
,
spdlog
::
level
::
critical
)
==
(
i
%
2
==
0
?
"Hello"
:
""
));
}
}
TEST_CASE
(
"conditional_trace_varargs"
,
"[conditional_trace_varargs]"
)
{
//const char
for
(
auto
i
=
0
;
i
<
2
;
i
++
)
{
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
trace
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
debug
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
info
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
warn
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
err
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
critical
,
(
i
%
2
==
0
),
"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
"Hello "
+
std
::
to_string
(
i
)
:
""
));
#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
trace
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
debug
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
info
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
warn
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
err
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
REQUIRE
(
conditional_log_varags
(
spdlog
::
level
::
critical
,
(
i
%
2
==
0
),
L"Hello {}"
,
i
)
==
(
i
%
2
==
0
?
L"Hello "
+
std
::
to_wstring
(
i
)
:
L""
));
#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT
}
}
\ No newline at end of file
tests/tests.vcxproj
View file @
de0154c5
...
...
@@ -125,6 +125,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile
Include=
"cond_logging.cpp"
/>
<ClCompile
Include=
"errors.cpp"
/>
<ClCompile
Include=
"file_helper.cpp"
/>
<ClCompile
Include=
"file_log.cpp"
/>
...
...
tests/tests.vcxproj.filters
View file @
de0154c5
...
...
@@ -36,6 +36,9 @@
<ClCompile
Include=
"errors.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"cond_logging.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"includes.h"
>
...
...
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