Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
spdlog
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
spdlog
Commits
21ed3184
Commit
21ed3184
authored
Oct 12, 2017
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed bug in SPDLOG_TRACE_IF macro and added some related tests
parent
4a159ad6
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
62 additions
and
2 deletions
+62
-2
spdlog.h
include/spdlog/spdlog.h
+2
-2
includes.h
tests/includes.h
+3
-0
test_macros.cpp
tests/test_macros.cpp
+43
-0
tests.vcxproj
tests/tests.vcxproj
+1
-0
tests.vcxproj.filters
tests/tests.vcxproj.filters
+3
-0
utils.cpp
tests/utils.cpp
+8
-0
utils.h
tests/utils.h
+2
-0
No files found.
include/spdlog/spdlog.h
View file @
21ed3184
...
...
@@ -170,10 +170,10 @@ void drop_all();
#define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
#ifdef _MSC_VER
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger
.
trace_if(flag, "[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger
->
trace_if(flag, "[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#else
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger
.
trace_if(flag, "[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger
->
trace_if(flag, "[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#endif
#else
#define SPDLOG_TRACE(logger, ...)
...
...
tests/includes.h
View file @
21ed3184
...
...
@@ -10,6 +10,9 @@
#include "catch.hpp"
#include "utils.h"
#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON
#include "../include/spdlog/spdlog.h"
#include "../include/spdlog/sinks/null_sink.h"
#include "../include/spdlog/sinks/ostream_sink.h"
...
...
tests/test_macros.cpp
0 → 100644
View file @
21ed3184
/*
* This content is released under the MIT License as specified in https://raw.githubusercontent.com/gabime/spdlog/master/LICENSE
*/
#include "includes.h"
TEST_CASE
(
"debug and trace w/o format string"
,
"[macros]]"
)
{
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message 2"
);
logger
->
flush
();
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 2
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
}
TEST_CASE
(
"debug and trace with format strings"
,
"[macros]]"
)
{
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message {}"
,
222
);
logger
->
flush
();
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 222
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
}
tests/tests.vcxproj
View file @
21ed3184
...
...
@@ -132,6 +132,7 @@
<ClCompile
Include=
"format.cpp"
/>
<ClCompile
Include=
"main.cpp"
/>
<ClCompile
Include=
"registry.cpp"
/>
<ClCompile
Include=
"test_macros.cpp"
/>
<ClCompile
Include=
"utils.cpp"
/>
</ItemGroup>
<ItemGroup>
...
...
tests/tests.vcxproj.filters
View file @
21ed3184
...
...
@@ -39,6 +39,9 @@
<ClCompile
Include=
"cond_logging.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
<ClCompile
Include=
"test_macros.cpp"
>
<Filter>
Source Files
</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude
Include=
"includes.h"
>
...
...
tests/utils.cpp
View file @
21ed3184
...
...
@@ -46,3 +46,11 @@ std::size_t get_filesize(const std::string& filename)
return
static_cast
<
std
::
size_t
>
(
ifs
.
tellg
());
}
// source: https://stackoverflow.com/a/2072890/192001
bool
ends_with
(
std
::
string
const
&
value
,
std
::
string
const
&
ending
)
{
if
(
ending
.
size
()
>
value
.
size
())
return
false
;
return
std
::
equal
(
ending
.
rbegin
(),
ending
.
rend
(),
value
.
rbegin
());
}
tests/utils.h
View file @
21ed3184
...
...
@@ -13,3 +13,4 @@ std::size_t count_lines(const std::string& filename);
std
::
size_t
get_filesize
(
const
std
::
string
&
filename
);
bool
ends_with
(
std
::
string
const
&
value
,
std
::
string
const
&
ending
);
\ No newline at end of file
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