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
9e6f5b6b
Commit
9e6f5b6b
authored
Apr 18, 2020
by
Ron Rechenmacher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add single logger method and log_msg constructor and tests/test_time_point.cpp
parent
d28465bf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
59 additions
and
4 deletions
+59
-4
include/spdlog/details/log_msg-inl.h
include/spdlog/details/log_msg-inl.h
+8
-3
include/spdlog/details/log_msg.h
include/spdlog/details/log_msg.h
+1
-0
include/spdlog/logger.h
include/spdlog/logger.h
+13
-0
tests/CMakeLists.txt
tests/CMakeLists.txt
+2
-1
tests/test_time_point.cpp
tests/test_time_point.cpp
+35
-0
No files found.
include/spdlog/details/log_msg-inl.h
View file @
9e6f5b6b
...
...
@@ -13,10 +13,10 @@ namespace spdlog {
namespace
details
{
SPDLOG_INLINE
log_msg
::
log_msg
(
spdlog
::
source_loc
loc
,
string_view_t
a_logger_name
,
spdlog
::
level
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
spdlog
::
log_clock
::
time_point
log_time
,
spdlog
::
source_loc
loc
,
string_view_t
a_logger_name
,
spdlog
::
level
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
:
logger_name
(
a_logger_name
)
,
level
(
lvl
)
,
time
(
os
::
now
()
)
,
time
(
log_time
)
#ifndef SPDLOG_NO_THREAD_ID
,
thread_id
(
os
::
thread_id
())
#endif
...
...
@@ -24,8 +24,13 @@ SPDLOG_INLINE log_msg::log_msg(
,
payload
(
msg
)
{}
SPDLOG_INLINE
log_msg
::
log_msg
(
spdlog
::
source_loc
loc
,
string_view_t
a_logger_name
,
spdlog
::
level
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
:
log_msg
(
os
::
now
(),
loc
,
a_logger_name
,
lvl
,
msg
)
{}
SPDLOG_INLINE
log_msg
::
log_msg
(
string_view_t
a_logger_name
,
spdlog
::
level
::
level_enum
lvl
,
spdlog
::
string_view_t
msg
)
:
log_msg
(
source_loc
{},
a_logger_name
,
lvl
,
msg
)
:
log_msg
(
os
::
now
(),
source_loc
{},
a_logger_name
,
lvl
,
msg
)
{}
}
// namespace details
...
...
include/spdlog/details/log_msg.h
View file @
9e6f5b6b
...
...
@@ -11,6 +11,7 @@ namespace details {
struct
SPDLOG_API
log_msg
{
log_msg
()
=
default
;
log_msg
(
log_clock
::
time_point
log_time
,
source_loc
loc
,
string_view_t
logger_name
,
level
::
level_enum
lvl
,
string_view_t
msg
);
log_msg
(
source_loc
loc
,
string_view_t
logger_name
,
level
::
level_enum
lvl
,
string_view_t
msg
);
log_msg
(
string_view_t
logger_name
,
level
::
level_enum
lvl
,
string_view_t
msg
);
log_msg
(
const
log_msg
&
other
)
=
default
;
...
...
include/spdlog/logger.h
View file @
9e6f5b6b
...
...
@@ -147,6 +147,19 @@ public:
log
(
loc
,
lvl
,
string_view_t
{
msg
});
}
void
log
(
log_clock
::
time_point
&
log_time
,
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
msg
)
{
bool
log_enabled
=
should_log
(
lvl
);
bool
traceback_enabled
=
tracer_
.
enabled
();
if
(
!
log_enabled
&&
!
traceback_enabled
)
{
return
;
}
details
::
log_msg
log_msg
(
log_time
,
loc
,
name_
,
lvl
,
msg
);
log_it_
(
log_msg
,
log_enabled
,
traceback_enabled
);
}
void
log
(
source_loc
loc
,
level
::
level_enum
lvl
,
string_view_t
msg
)
{
bool
log_enabled
=
should_log
(
lvl
);
...
...
tests/CMakeLists.txt
View file @
9e6f5b6b
...
...
@@ -32,7 +32,8 @@ set(SPDLOG_UTESTS_SOURCES
test_stdout_api.cpp
test_backtrace.cpp
test_create_dir.cpp
test_cfg.cpp
)
test_cfg.cpp
test_time_point.cpp
)
if
(
NOT SPDLOG_NO_EXCEPTIONS
)
list
(
APPEND SPDLOG_UTESTS_SOURCES test_errors.cpp
)
...
...
tests/test_time_point.cpp
0 → 100644
View file @
9e6f5b6b
#include "includes.h"
#include "test_sink.h"
#include "spdlog/async.h"
TEST_CASE
(
"time_point1"
,
"[time_point log_msg]"
)
{
std
::
shared_ptr
<
spdlog
::
sinks
::
test_sink_st
>
test_sink
(
new
spdlog
::
sinks
::
test_sink_st
);
spdlog
::
logger
logger
(
"test-time_point"
,
test_sink
);
spdlog
::
source_loc
source
{};
std
::
chrono
::
system_clock
::
time_point
tp
{
std
::
chrono
::
system_clock
::
now
()};
test_sink
->
set_pattern
(
"%T.%F"
);
// interested in the time_point
// all the following should have the same time
test_sink
->
set_delay
(
std
::
chrono
::
milliseconds
(
10
));
for
(
int
i
=
0
;
i
<
5
;
i
++
)
{
spdlog
::
details
::
log_msg
msg
{
tp
,
source
,
"test_logger"
,
spdlog
::
level
::
info
,
"message"
};
test_sink
->
log
(
msg
);
}
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
tp
,
source
,
spdlog
::
level
::
info
,
"formatted message"
);
logger
.
log
(
source
,
spdlog
::
level
::
info
,
"formatted message"
);
// last line has different time_point
// now the real test... that the times are the same.
std
::
vector
<
std
::
string
>
lines
=
test_sink
->
lines
();
REQUIRE
(
lines
[
0
]
==
lines
[
1
]);
REQUIRE
(
lines
[
2
]
==
lines
[
3
]);
REQUIRE
(
lines
[
4
]
==
lines
[
5
]);
REQUIRE
(
lines
[
6
]
==
lines
[
7
]);
REQUIRE
(
lines
[
8
]
!=
lines
[
9
]);
spdlog
::
drop_all
();
}
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