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
752d5685
Commit
752d5685
authored
Mar 21, 2020
by
Gabi Melman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved pattern formatter from spdlog/details to spdlog/
parent
c6c51743
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
46 additions
and
15 deletions
+46
-15
example/example.cpp
example/example.cpp
+32
-1
include/spdlog/details/registry-inl.h
include/spdlog/details/registry-inl.h
+1
-1
include/spdlog/logger-inl.h
include/spdlog/logger-inl.h
+1
-1
include/spdlog/pattern_formatter-inl.h
include/spdlog/pattern_formatter-inl.h
+1
-1
include/spdlog/pattern_formatter.h
include/spdlog/pattern_formatter.h
+2
-2
include/spdlog/sinks/base_sink-inl.h
include/spdlog/sinks/base_sink-inl.h
+1
-1
include/spdlog/sinks/dist_sink.h
include/spdlog/sinks/dist_sink.h
+1
-1
include/spdlog/sinks/stdout_sinks-inl.h
include/spdlog/sinks/stdout_sinks-inl.h
+1
-1
include/spdlog/sinks/wincolor_sink-inl.h
include/spdlog/sinks/wincolor_sink-inl.h
+1
-1
include/spdlog/spdlog-inl.h
include/spdlog/spdlog-inl.h
+1
-1
src/spdlog.cpp
src/spdlog.cpp
+1
-1
tests/includes.h
tests/includes.h
+1
-1
tests/test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+2
-2
No files found.
example/example.cpp
View file @
752d5685
...
@@ -18,6 +18,7 @@ void multi_sink_example();
...
@@ -18,6 +18,7 @@ void multi_sink_example();
void
user_defined_example
();
void
user_defined_example
();
void
err_handler_example
();
void
err_handler_example
();
void
syslog_example
();
void
syslog_example
();
void
custom_flags_example
();
#include "spdlog/spdlog.h"
#include "spdlog/spdlog.h"
#include "spdlog/cfg/env.h" // for loading levels from the environment variable
#include "spdlog/cfg/env.h" // for loading levels from the environment variable
...
@@ -70,6 +71,7 @@ int main(int, char *[])
...
@@ -70,6 +71,7 @@ int main(int, char *[])
user_defined_example
();
user_defined_example
();
err_handler_example
();
err_handler_example
();
trace_example
();
trace_example
();
custom_flags_example
();
// Flush all *registered* loggers using a worker thread every 3 seconds.
// Flush all *registered* loggers using a worker thread every 3 seconds.
// note: registered loggers *must* be thread safe for this to work correctly!
// note: registered loggers *must* be thread safe for this to work correctly!
...
@@ -250,5 +252,34 @@ void android_example()
...
@@ -250,5 +252,34 @@ void android_example()
auto
android_logger
=
spdlog
::
android_logger_mt
(
"android"
,
tag
);
auto
android_logger
=
spdlog
::
android_logger_mt
(
"android"
,
tag
);
android_logger
->
critical
(
"Use
\"
adb shell logcat
\"
to view this message."
);
android_logger
->
critical
(
"Use
\"
adb shell logcat
\"
to view this message."
);
}
}
#endif
#endif
// log patterns can now contain custom flags!
// add custom flag '%*' which will be cound to a <my_formatter_flag> instance
#include "spdlog/pattern_formatter.h"
class
my_formatter_flag
:
public
spdlog
::
custom_flag_formatter
{
public:
void
format
(
const
spdlog
::
details
::
log_msg
&
,
const
std
::
tm
&
,
spdlog
::
memory_buf_t
&
dest
)
override
{
std
::
string
some_txt
=
"custom-flag"
;
dest
.
append
(
some_txt
.
data
(),
some_txt
.
data
()
+
some_txt
.
size
());
}
std
::
unique_ptr
<
custom_flag_formatter
>
clone
()
const
override
{
return
spdlog
::
details
::
make_unique
<
my_formatter_flag
>
();
}
};
void
custom_flags_example
()
{
using
spdlog
::
details
::
make_unique
;
//for pre c++14
auto
formatter
=
make_unique
<
spdlog
::
pattern_formatter
>
(
"[%+] [%*]"
);
formatter
->
add_flag
<
my_formatter_flag
>
(
'*'
).
recompile
();
spdlog
::
set_formatter
(
std
::
move
(
formatter
));
}
include/spdlog/details/registry-inl.h
View file @
752d5685
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include <spdlog/common.h>
#include <spdlog/common.h>
#include <spdlog/details/periodic_worker.h>
#include <spdlog/details/periodic_worker.h>
#include <spdlog/logger.h>
#include <spdlog/logger.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
#ifndef SPDLOG_DISABLE_DEFAULT_LOGGER
// support for the default stdout color logger
// support for the default stdout color logger
...
...
include/spdlog/logger-inl.h
View file @
752d5685
...
@@ -9,7 +9,7 @@
...
@@ -9,7 +9,7 @@
#include <spdlog/sinks/sink.h>
#include <spdlog/sinks/sink.h>
#include <spdlog/details/backtracer.h>
#include <spdlog/details/backtracer.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#include <cstdio>
#include <cstdio>
...
...
include/spdlog/
details/
pattern_formatter-inl.h
→
include/spdlog/pattern_formatter-inl.h
View file @
752d5685
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
#pragma once
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#ifndef SPDLOG_HEADER_ONLY
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#endif
#endif
#include <spdlog/details/fmt_helper.h>
#include <spdlog/details/fmt_helper.h>
...
...
include/spdlog/
details/
pattern_formatter.h
→
include/spdlog/pattern_formatter.h
View file @
752d5685
...
@@ -87,10 +87,10 @@ public:
...
@@ -87,10 +87,10 @@ public:
void
format
(
const
details
::
log_msg
&
msg
,
memory_buf_t
&
dest
)
override
;
void
format
(
const
details
::
log_msg
&
msg
,
memory_buf_t
&
dest
)
override
;
template
<
typename
T
,
typename
...
Args
>
template
<
typename
T
,
typename
...
Args
>
pattern_formatter
&
add_flag
_handler
(
char
flag
,
const
Args
&
...
args
)
pattern_formatter
&
add_flag
(
char
flag
,
const
Args
&
...
args
)
{
{
custom_handlers_
[
flag
]
=
details
::
make_unique
<
T
>
(
args
...);
custom_handlers_
[
flag
]
=
details
::
make_unique
<
T
>
(
args
...);
return
*
this
;
return
*
this
;
}
}
void
recompile
();
void
recompile
();
...
...
include/spdlog/sinks/base_sink-inl.h
View file @
752d5685
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#endif
#endif
#include <spdlog/common.h>
#include <spdlog/common.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#include <memory>
#include <memory>
...
...
include/spdlog/sinks/dist_sink.h
View file @
752d5685
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#include "base_sink.h"
#include "base_sink.h"
#include <spdlog/details/log_msg.h>
#include <spdlog/details/log_msg.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/details/null_mutex.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#include <algorithm>
#include <algorithm>
#include <memory>
#include <memory>
...
...
include/spdlog/sinks/stdout_sinks-inl.h
View file @
752d5685
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#endif
#endif
#include <spdlog/details/console_globals.h>
#include <spdlog/details/console_globals.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
#include <memory>
#include <memory>
namespace
spdlog
{
namespace
spdlog
{
...
...
include/spdlog/sinks/wincolor_sink-inl.h
View file @
752d5685
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#endif
#endif
#include <spdlog/common.h>
#include <spdlog/common.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
namespace
spdlog
{
namespace
spdlog
{
namespace
sinks
{
namespace
sinks
{
...
...
include/spdlog/spdlog-inl.h
View file @
752d5685
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
#endif
#endif
#include <spdlog/common.h>
#include <spdlog/common.h>
#include <spdlog/
details/
pattern_formatter.h>
#include <spdlog/pattern_formatter.h>
namespace
spdlog
{
namespace
spdlog
{
...
...
src/spdlog.cpp
View file @
752d5685
...
@@ -10,7 +10,7 @@
...
@@ -10,7 +10,7 @@
#include <spdlog/details/backtracer-inl.h>
#include <spdlog/details/backtracer-inl.h>
#include <spdlog/details/registry-inl.h>
#include <spdlog/details/registry-inl.h>
#include <spdlog/details/os-inl.h>
#include <spdlog/details/os-inl.h>
#include <spdlog/
details/
pattern_formatter-inl.h>
#include <spdlog/pattern_formatter-inl.h>
#include <spdlog/details/log_msg-inl.h>
#include <spdlog/details/log_msg-inl.h>
#include <spdlog/details/log_msg_buffer-inl.h>
#include <spdlog/details/log_msg_buffer-inl.h>
#include <spdlog/logger-inl.h>
#include <spdlog/logger-inl.h>
...
...
tests/includes.h
View file @
752d5685
...
@@ -23,4 +23,4 @@
...
@@ -23,4 +23,4 @@
#include "spdlog/sinks/ostream_sink.h"
#include "spdlog/sinks/ostream_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/rotating_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/details/pattern_formatter.h"
#include "spdlog/pattern_formatter.h"
\ No newline at end of file
\ No newline at end of file
tests/test_pattern_formatter.cpp
View file @
752d5685
...
@@ -330,7 +330,7 @@ public:
...
@@ -330,7 +330,7 @@ public:
TEST_CASE
(
"clone-custom_formatter"
,
"[pattern_formatter]"
)
TEST_CASE
(
"clone-custom_formatter"
,
"[pattern_formatter]"
)
{
{
auto
formatter_1
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%n] [%t] %v"
,
spdlog
::
pattern_time_type
::
utc
,
""
);
auto
formatter_1
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%n] [%t] %v"
,
spdlog
::
pattern_time_type
::
utc
,
""
);
formatter_1
->
add_flag
_handler
<
custom_test_flag
>
(
't'
,
"custom_output"
).
recompile
();
formatter_1
->
add_flag
<
custom_test_flag
>
(
't'
,
"custom_output"
).
recompile
();
auto
formatter_2
=
formatter_1
->
clone
();
auto
formatter_2
=
formatter_1
->
clone
();
std
::
string
logger_name
=
"logger-name"
;
std
::
string
logger_name
=
"logger-name"
;
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
spdlog
::
details
::
log_msg
msg
(
logger_name
,
spdlog
::
level
::
info
,
"some message"
);
...
@@ -402,7 +402,7 @@ TEST_CASE("full filename formatter", "[pattern_formatter]")
...
@@ -402,7 +402,7 @@ TEST_CASE("full filename formatter", "[pattern_formatter]")
TEST_CASE
(
"custom flags"
,
"[pattern_formatter]"
)
TEST_CASE
(
"custom flags"
,
"[pattern_formatter]"
)
{
{
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%n] [%t] [%u] %v"
,
spdlog
::
pattern_time_type
::
utc
,
""
);
auto
formatter
=
std
::
make_shared
<
spdlog
::
pattern_formatter
>
(
"[%n] [%t] [%u] %v"
,
spdlog
::
pattern_time_type
::
utc
,
""
);
formatter
->
add_flag
_handler
<
custom_test_flag
>
(
't'
,
"custom1"
).
add_flag_handler
<
custom_test_flag
>
(
'u'
,
"custom2"
).
recompile
();
formatter
->
add_flag
<
custom_test_flag
>
(
't'
,
"custom1"
).
add_flag
<
custom_test_flag
>
(
'u'
,
"custom2"
).
recompile
();
memory_buf_t
formatted
;
memory_buf_t
formatted
;
...
...
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