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
33329c80
Commit
33329c80
authored
Jul 23, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
code formatting
parent
fe732554
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
56 additions
and
55 deletions
+56
-55
include/spdlog/details/logger_impl.h
include/spdlog/details/logger_impl.h
+4
-5
include/spdlog/details/pattern_formatter.h
include/spdlog/details/pattern_formatter.h
+25
-25
include/spdlog/details/registry.h
include/spdlog/details/registry.h
+15
-13
include/spdlog/formatter.h
include/spdlog/formatter.h
+1
-1
include/spdlog/logger.h
include/spdlog/logger.h
+7
-7
include/spdlog/spdlog.h
include/spdlog/spdlog.h
+3
-3
tests/test_pattern_formatter.cpp
tests/test_pattern_formatter.cpp
+1
-1
No files found.
include/spdlog/details/logger_impl.h
View file @
33329c80
...
@@ -37,13 +37,12 @@ inline spdlog::logger::logger(std::string logger_name, spdlog::sink_ptr single_s
...
@@ -37,13 +37,12 @@ inline spdlog::logger::logger(std::string logger_name, spdlog::sink_ptr single_s
inline
spdlog
::
logger
::~
logger
()
=
default
;
inline
spdlog
::
logger
::~
logger
()
=
default
;
inline
void
spdlog
::
logger
::
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
f
)
inline
void
spdlog
::
logger
::
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
f
)
{
{
for
(
auto
&
sink
:
sinks_
)
for
(
auto
&
sink
:
sinks_
)
{
{
sink
->
set_formatter
(
f
->
clone
());
sink
->
set_formatter
(
f
->
clone
());
}
}
}
}
inline
void
spdlog
::
logger
::
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
)
inline
void
spdlog
::
logger
::
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
)
...
...
include/spdlog/details/pattern_formatter.h
View file @
33329c80
...
@@ -75,7 +75,7 @@ static int to12h(const tm &t)
...
@@ -75,7 +75,7 @@ static int to12h(const tm &t)
}
}
// Abbreviated weekday name
// Abbreviated weekday name
static
const
char
*
days
[]{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
static
const
char
*
days
[]{
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
};
class
a_formatter
:
public
flag_formatter
class
a_formatter
:
public
flag_formatter
{
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
...
@@ -85,7 +85,7 @@ class a_formatter : public flag_formatter
...
@@ -85,7 +85,7 @@ class a_formatter : public flag_formatter
};
};
// Full weekday name
// Full weekday name
static
const
char
*
full_days
[]{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
static
const
char
*
full_days
[]{
"Sunday"
,
"Monday"
,
"Tuesday"
,
"Wednesday"
,
"Thursday"
,
"Friday"
,
"Saturday"
};
class
A_formatter
:
public
flag_formatter
class
A_formatter
:
public
flag_formatter
{
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
...
@@ -95,7 +95,7 @@ class A_formatter : public flag_formatter
...
@@ -95,7 +95,7 @@ class A_formatter : public flag_formatter
};
};
// Abbreviated month
// Abbreviated month
static
const
char
*
months
[]{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sept"
,
"Oct"
,
"Nov"
,
"Dec"
};
static
const
char
*
months
[]{
"Jan"
,
"Feb"
,
"Mar"
,
"Apr"
,
"May"
,
"Jun"
,
"Jul"
,
"Aug"
,
"Sept"
,
"Oct"
,
"Nov"
,
"Dec"
};
class
b_formatter
:
public
flag_formatter
class
b_formatter
:
public
flag_formatter
{
{
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
void
format
(
const
details
::
log_msg
&
,
const
std
::
tm
&
tm_time
,
fmt
::
memory_buffer
&
dest
)
override
...
@@ -105,7 +105,7 @@ class b_formatter : public flag_formatter
...
@@ -105,7 +105,7 @@ class b_formatter : public flag_formatter
};
};
// Full month name
// Full month name
static
const
char
*
full_months
[]{
static
const
char
*
full_months
[]{
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
class
B_formatter
:
public
flag_formatter
class
B_formatter
:
public
flag_formatter
{
{
...
@@ -541,24 +541,24 @@ private:
...
@@ -541,24 +541,24 @@ private:
class
pattern_formatter
SPDLOG_FINAL
:
public
formatter
class
pattern_formatter
SPDLOG_FINAL
:
public
formatter
{
{
public:
public:
explicit
pattern_formatter
(
explicit
pattern_formatter
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
,
std
::
string
eol
=
spdlog
::
details
::
os
::
default_eol
)
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
,
std
::
string
eol
=
spdlog
::
details
::
os
::
default_eol
)
:
pattern_
(
std
::
move
(
pattern
))
:
pattern_
(
std
::
move
(
pattern
))
,
eol_
(
std
::
move
(
eol
))
,
eol_
(
std
::
move
(
eol
))
,
pattern_time_type_
(
time_type
)
,
pattern_time_type_
(
time_type
)
,
last_log_secs_
(
0
)
,
last_log_secs_
(
0
)
{
{
std
::
memset
(
&
cached_tm_
,
0
,
sizeof
(
cached_tm_
));
std
::
memset
(
&
cached_tm_
,
0
,
sizeof
(
cached_tm_
));
compile_pattern_
(
pattern_
);
compile_pattern_
(
pattern_
);
}
}
pattern_formatter
(
const
pattern_formatter
&
other
)
=
delete
;
pattern_formatter
(
const
pattern_formatter
&
other
)
=
delete
;
pattern_formatter
&
operator
=
(
const
pattern_formatter
&
other
)
=
delete
;
pattern_formatter
&
operator
=
(
const
pattern_formatter
&
other
)
=
delete
;
virtual
std
::
unique_ptr
<
formatter
>
clone
()
const
override
virtual
std
::
unique_ptr
<
formatter
>
clone
()
const
override
{
{
return
std
::
unique_ptr
<
formatter
>
(
new
pattern_formatter
(
pattern_
,
pattern_time_type_
,
eol_
));
return
std
::
unique_ptr
<
formatter
>
(
new
pattern_formatter
(
pattern_
,
pattern_time_type_
,
eol_
));
}
}
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
override
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
override
{
{
...
@@ -579,7 +579,7 @@ public:
...
@@ -579,7 +579,7 @@ public:
}
}
private:
private:
std
::
string
pattern_
;
std
::
string
pattern_
;
std
::
string
eol_
;
std
::
string
eol_
;
pattern_time_type
pattern_time_type_
;
pattern_time_type
pattern_time_type_
;
std
::
tm
cached_tm_
;
std
::
tm
cached_tm_
;
...
@@ -742,10 +742,10 @@ private:
...
@@ -742,10 +742,10 @@ private:
}
}
void
compile_pattern_
(
const
std
::
string
&
pattern
)
void
compile_pattern_
(
const
std
::
string
&
pattern
)
{
{
auto
end
=
pattern
.
end
();
auto
end
=
pattern
.
end
();
std
::
unique_ptr
<
details
::
aggregate_formatter
>
user_chars
;
std
::
unique_ptr
<
details
::
aggregate_formatter
>
user_chars
;
formatters_
.
clear
();
formatters_
.
clear
();
for
(
auto
it
=
pattern
.
begin
();
it
!=
end
;
++
it
)
for
(
auto
it
=
pattern
.
begin
();
it
!=
end
;
++
it
)
{
{
if
(
*
it
==
'%'
)
if
(
*
it
==
'%'
)
...
...
include/spdlog/details/registry.h
View file @
33329c80
...
@@ -81,17 +81,16 @@ public:
...
@@ -81,17 +81,16 @@ public:
return
tp_
;
return
tp_
;
}
}
// Set global formatter. Each sink in each logger will get a clone of this object
// Set global formatter. Each sink in each logger will get a clone of this object
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
)
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
)
{
{
std
::
lock_guard
<
Mutex
>
lock
(
loggers_mutex_
);
std
::
lock_guard
<
Mutex
>
lock
(
loggers_mutex_
);
formatter_
=
std
::
move
(
formatter
);
formatter_
=
std
::
move
(
formatter
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
{
{
l
.
second
->
set_formatter
(
formatter_
->
clone
());
l
.
second
->
set_formatter
(
formatter_
->
clone
());
}
}
}
}
void
set_level
(
level
::
level_enum
log_level
)
void
set_level
(
level
::
level_enum
log_level
)
{
{
...
@@ -169,7 +168,10 @@ public:
...
@@ -169,7 +168,10 @@ public:
}
}
private:
private:
registry_t
<
Mutex
>
()
:
formatter_
(
new
pattern_formatter
(
"%+"
)){}
registry_t
<
Mutex
>
()
:
formatter_
(
new
pattern_formatter
(
"%+"
))
{
}
~
registry_t
<
Mutex
>
()
~
registry_t
<
Mutex
>
()
{
{
...
@@ -196,7 +198,7 @@ private:
...
@@ -196,7 +198,7 @@ private:
Mutex
loggers_mutex_
;
Mutex
loggers_mutex_
;
std
::
recursive_mutex
tp_mutex_
;
std
::
recursive_mutex
tp_mutex_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
loggers_
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
loggers_
;
//
std::unique_ptr<formatter> formatter_{ new pattern_formatter("%+") };
//
std::unique_ptr<formatter> formatter_{ new pattern_formatter("%+") };
std
::
unique_ptr
<
formatter
>
formatter_
;
std
::
unique_ptr
<
formatter
>
formatter_
;
level
::
level_enum
level_
=
level
::
info
;
level
::
level_enum
level_
=
level
::
info
;
level
::
level_enum
flush_level_
=
level
::
off
;
level
::
level_enum
flush_level_
=
level
::
off
;
...
...
include/spdlog/formatter.h
View file @
33329c80
...
@@ -15,6 +15,6 @@ class formatter
...
@@ -15,6 +15,6 @@ class formatter
public:
public:
virtual
~
formatter
()
=
default
;
virtual
~
formatter
()
=
default
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
=
0
;
virtual
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
=
0
;
virtual
std
::
unique_ptr
<
formatter
>
clone
()
const
=
0
;
virtual
std
::
unique_ptr
<
formatter
>
clone
()
const
=
0
;
};
};
}
// namespace spdlog
}
// namespace spdlog
include/spdlog/logger.h
View file @
33329c80
...
@@ -114,19 +114,19 @@ public:
...
@@ -114,19 +114,19 @@ public:
void
set_level
(
level
::
level_enum
log_level
);
void
set_level
(
level
::
level_enum
log_level
);
level
::
level_enum
level
()
const
;
level
::
level_enum
level
()
const
;
const
std
::
string
&
name
()
const
;
const
std
::
string
&
name
()
const
;
// set formatting for the sinks in this logger.
// set formatting for the sinks in this logger.
// each sink will get a seperate instance of the formatter object.
// each sink will get a seperate instance of the formatter object.
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
);
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
);
void
flush
();
void
flush
();
void
flush_on
(
level
::
level_enum
log_level
);
void
flush_on
(
level
::
level_enum
log_level
);
const
std
::
vector
<
sink_ptr
>
&
sinks
()
const
;
const
std
::
vector
<
sink_ptr
>
&
sinks
()
const
;
std
::
vector
<
sink_ptr
>
&
sinks
();
std
::
vector
<
sink_ptr
>
&
sinks
();
void
set_error_handler
(
log_err_handler
err_handler
);
void
set_error_handler
(
log_err_handler
err_handler
);
log_err_handler
error_handler
();
log_err_handler
error_handler
();
...
...
include/spdlog/spdlog.h
View file @
33329c80
...
@@ -56,14 +56,14 @@ inline std::shared_ptr<logger> get(const std::string &name)
...
@@ -56,14 +56,14 @@ inline std::shared_ptr<logger> get(const std::string &name)
// Set global formatter. Each sink in each logger will get a clone of this object
// Set global formatter. Each sink in each logger will get a clone of this object
inline
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter
)
inline
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
formatter
)
{
{
details
::
registry
::
instance
().
set_formatter
(
std
::
move
(
formatter
));
details
::
registry
::
instance
().
set_formatter
(
std
::
move
(
formatter
));
}
}
// Set global format string.
// Set global format string.
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v");
inline
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
)
inline
void
set_pattern
(
std
::
string
pattern
,
pattern_time_type
time_type
=
pattern_time_type
::
local
)
{
{
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
,
time_type
)));
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
,
time_type
)));
}
}
// Set global logging level
// Set global logging level
...
...
tests/test_pattern_formatter.cpp
View file @
33329c80
...
@@ -10,7 +10,7 @@ static std::string log_to_str(const std::string &msg, const Args &... args)
...
@@ -10,7 +10,7 @@ static std::string log_to_str(const std::string &msg, const Args &... args)
spdlog
::
logger
oss_logger
(
"pattern_tester"
,
oss_sink
);
spdlog
::
logger
oss_logger
(
"pattern_tester"
,
oss_sink
);
oss_logger
.
set_level
(
spdlog
::
level
::
info
);
oss_logger
.
set_level
(
spdlog
::
level
::
info
);
oss_logger
.
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
spdlog
::
pattern_formatter
(
args
...)));
oss_logger
.
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
spdlog
::
pattern_formatter
(
args
...)));
oss_logger
.
info
(
msg
);
oss_logger
.
info
(
msg
);
return
oss
.
str
();
return
oss
.
str
();
...
...
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