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
9716ff69
Commit
9716ff69
authored
Apr 05, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added inline statemetns
parent
4dd1a24d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
32 deletions
+32
-32
pattern_formatter.cpp
src/pattern_formatter.cpp
+8
-8
registry.cpp
src/registry.cpp
+24
-24
No files found.
src/pattern_formatter.cpp
View file @
9716ff69
...
@@ -960,7 +960,7 @@ private:
...
@@ -960,7 +960,7 @@ private:
}
// namespace details
}
// namespace details
pattern_formatter
::
pattern_formatter
(
SPDLOG_INLINE
pattern_formatter
::
pattern_formatter
(
std
::
string
pattern
,
pattern_time_type
time_type
,
std
::
string
eol
)
std
::
string
pattern
,
pattern_time_type
time_type
,
std
::
string
eol
)
:
pattern_
(
std
::
move
(
pattern
))
:
pattern_
(
std
::
move
(
pattern
))
,
eol_
(
std
::
move
(
eol
))
,
eol_
(
std
::
move
(
eol
))
...
@@ -972,7 +972,7 @@ private:
...
@@ -972,7 +972,7 @@ private:
}
}
// use by default full formatter for if pattern is not given
// use by default full formatter for if pattern is not given
pattern_formatter
::
pattern_formatter
(
pattern_time_type
time_type
,
std
::
string
eol
)
SPDLOG_INLINE
pattern_formatter
::
pattern_formatter
(
pattern_time_type
time_type
,
std
::
string
eol
)
:
pattern_
(
"%+"
)
:
pattern_
(
"%+"
)
,
eol_
(
std
::
move
(
eol
))
,
eol_
(
std
::
move
(
eol
))
,
pattern_time_type_
(
time_type
)
,
pattern_time_type_
(
time_type
)
...
@@ -983,12 +983,12 @@ private:
...
@@ -983,12 +983,12 @@ private:
}
}
std
::
unique_ptr
<
formatter
>
pattern_formatter
::
clone
()
const
SPDLOG_INLINE
std
::
unique_ptr
<
formatter
>
pattern_formatter
::
clone
()
const
{
{
return
details
::
make_unique
<
pattern_formatter
>
(
pattern_
,
pattern_time_type_
,
eol_
);
return
details
::
make_unique
<
pattern_formatter
>
(
pattern_
,
pattern_time_type_
,
eol_
);
}
}
void
pattern_formatter
::
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
SPDLOG_INLINE
void
pattern_formatter
::
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
{
{
#ifndef SPDLOG_NO_DATETIME
#ifndef SPDLOG_NO_DATETIME
auto
secs
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
msg
.
time
.
time_since_epoch
());
auto
secs
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
msg
.
time
.
time_since_epoch
());
...
@@ -1006,7 +1006,7 @@ private:
...
@@ -1006,7 +1006,7 @@ private:
details
::
fmt_helper
::
append_string_view
(
eol_
,
dest
);
details
::
fmt_helper
::
append_string_view
(
eol_
,
dest
);
}
}
std
::
tm
pattern_formatter
::
get_time_
(
const
details
::
log_msg
&
msg
)
SPDLOG_INLINE
std
::
tm
pattern_formatter
::
get_time_
(
const
details
::
log_msg
&
msg
)
{
{
if
(
pattern_time_type_
==
pattern_time_type
::
local
)
if
(
pattern_time_type_
==
pattern_time_type
::
local
)
{
{
...
@@ -1015,7 +1015,7 @@ private:
...
@@ -1015,7 +1015,7 @@ private:
return
details
::
os
::
gmtime
(
log_clock
::
to_time_t
(
msg
.
time
));
return
details
::
os
::
gmtime
(
log_clock
::
to_time_t
(
msg
.
time
));
}
}
void
pattern_formatter
::
handle_flag_
(
char
flag
,
details
::
padding_info
padding
)
SPDLOG_INLINE
void
pattern_formatter
::
handle_flag_
(
char
flag
,
details
::
padding_info
padding
)
{
{
switch
(
flag
)
switch
(
flag
)
{
{
...
@@ -1183,7 +1183,7 @@ private:
...
@@ -1183,7 +1183,7 @@ private:
// Extract given pad spec (e.g. %8X)
// Extract given pad spec (e.g. %8X)
// Advance the given it pass the end of the padding spec found (if any)
// Advance the given it pass the end of the padding spec found (if any)
// Return padding.
// Return padding.
details
::
padding_info
pattern_formatter
::
handle_padspec_
(
std
::
string
::
const_iterator
&
it
,
std
::
string
::
const_iterator
end
)
SPDLOG_INLINE
details
::
padding_info
pattern_formatter
::
handle_padspec_
(
std
::
string
::
const_iterator
&
it
,
std
::
string
::
const_iterator
end
)
{
{
using
details
::
padding_info
;
using
details
::
padding_info
;
using
details
::
scoped_pad
;
using
details
::
scoped_pad
;
...
@@ -1223,7 +1223,7 @@ private:
...
@@ -1223,7 +1223,7 @@ private:
return
details
::
padding_info
{
std
::
min
<
size_t
>
(
width
,
max_width
),
side
};
return
details
::
padding_info
{
std
::
min
<
size_t
>
(
width
,
max_width
),
side
};
}
}
void
pattern_formatter
::
compile_pattern_
(
const
std
::
string
&
pattern
)
SPDLOG_INLINE
void
pattern_formatter
::
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
;
...
...
src/registry.cpp
View file @
9716ff69
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
namespace
spdlog
{
namespace
spdlog
{
namespace
details
{
namespace
details
{
registry
::
registry
()
SPDLOG_INLINE
registry
::
registry
()
:
formatter_
(
new
pattern_formatter
())
:
formatter_
(
new
pattern_formatter
())
,
level_
(
spdlog
::
logger
::
default_level
())
,
level_
(
spdlog
::
logger
::
default_level
())
{
{
...
@@ -49,13 +49,13 @@ registry::registry()
...
@@ -49,13 +49,13 @@ registry::registry()
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
}
}
void
registry
::
register_logger
(
std
::
shared_ptr
<
logger
>
new_logger
)
SPDLOG_INLINE
void
registry
::
register_logger
(
std
::
shared_ptr
<
logger
>
new_logger
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
register_logger_
(
std
::
move
(
new_logger
));
register_logger_
(
std
::
move
(
new_logger
));
}
}
void
registry
::
initialize_logger
(
std
::
shared_ptr
<
logger
>
new_logger
)
SPDLOG_INLINE
void
registry
::
initialize_logger
(
std
::
shared_ptr
<
logger
>
new_logger
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
new_logger
->
set_formatter
(
formatter_
->
clone
());
new_logger
->
set_formatter
(
formatter_
->
clone
());
...
@@ -74,14 +74,14 @@ void registry::initialize_logger(std::shared_ptr<logger> new_logger)
...
@@ -74,14 +74,14 @@ void registry::initialize_logger(std::shared_ptr<logger> new_logger)
}
}
}
}
std
::
shared_ptr
<
logger
>
registry
::
get
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
registry
::
get
(
const
std
::
string
&
logger_name
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
auto
found
=
loggers_
.
find
(
logger_name
);
auto
found
=
loggers_
.
find
(
logger_name
);
return
found
==
loggers_
.
end
()
?
nullptr
:
found
->
second
;
return
found
==
loggers_
.
end
()
?
nullptr
:
found
->
second
;
}
}
std
::
shared_ptr
<
logger
>
registry
::
default_logger
()
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
registry
::
default_logger
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
return
default_logger_
;
return
default_logger_
;
...
@@ -91,14 +91,14 @@ std::shared_ptr<logger> registry::default_logger()
...
@@ -91,14 +91,14 @@ std::shared_ptr<logger> registry::default_logger()
// To be used directly by the spdlog default api (e.g. spdlog::info)
// To be used directly by the spdlog default api (e.g. spdlog::info)
// This make the default API faster, but cannot be used concurrently with set_default_logger().
// This make the default API faster, but cannot be used concurrently with set_default_logger().
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
logger
*
registry
::
get_default_raw
()
SPDLOG_INLINE
logger
*
registry
::
get_default_raw
()
{
{
return
default_logger_
.
get
();
return
default_logger_
.
get
();
}
}
// set default logger.
// set default logger.
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
void
registry
::
set_default_logger
(
std
::
shared_ptr
<
logger
>
new_default_logger
)
SPDLOG_INLINE
void
registry
::
set_default_logger
(
std
::
shared_ptr
<
logger
>
new_default_logger
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
// remove previous default logger from the map
// remove previous default logger from the map
...
@@ -113,20 +113,20 @@ void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
...
@@ -113,20 +113,20 @@ void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
default_logger_
=
std
::
move
(
new_default_logger
);
default_logger_
=
std
::
move
(
new_default_logger
);
}
}
void
registry
::
set_tp
(
std
::
shared_ptr
<
thread_pool
>
tp
)
SPDLOG_INLINE
void
registry
::
set_tp
(
std
::
shared_ptr
<
thread_pool
>
tp
)
{
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
tp_mutex_
);
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
tp_mutex_
);
tp_
=
std
::
move
(
tp
);
tp_
=
std
::
move
(
tp
);
}
}
std
::
shared_ptr
<
thread_pool
>
registry
::
get_tp
()
SPDLOG_INLINE
std
::
shared_ptr
<
thread_pool
>
registry
::
get_tp
()
{
{
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
tp_mutex_
);
std
::
lock_guard
<
std
::
recursive_mutex
>
lock
(
tp_mutex_
);
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
registry
::
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
)
SPDLOG_INLINE
void
registry
::
set_formatter
(
std
::
unique_ptr
<
formatter
>
formatter
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
formatter_
=
std
::
move
(
formatter
);
formatter_
=
std
::
move
(
formatter
);
...
@@ -136,7 +136,7 @@ void registry::set_formatter(std::unique_ptr<formatter> formatter)
...
@@ -136,7 +136,7 @@ void registry::set_formatter(std::unique_ptr<formatter> formatter)
}
}
}
}
void
registry
::
set_level
(
level
::
level_enum
log_level
)
SPDLOG_INLINE
void
registry
::
set_level
(
level
::
level_enum
log_level
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
...
@@ -146,7 +146,7 @@ void registry::set_level(level::level_enum log_level)
...
@@ -146,7 +146,7 @@ void registry::set_level(level::level_enum log_level)
level_
=
log_level
;
level_
=
log_level
;
}
}
void
registry
::
flush_on
(
level
::
level_enum
log_level
)
SPDLOG_INLINE
void
registry
::
flush_on
(
level
::
level_enum
log_level
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
...
@@ -156,14 +156,14 @@ void registry::flush_on(level::level_enum log_level)
...
@@ -156,14 +156,14 @@ void registry::flush_on(level::level_enum log_level)
flush_level_
=
log_level
;
flush_level_
=
log_level
;
}
}
void
registry
::
flush_every
(
std
::
chrono
::
seconds
interval
)
SPDLOG_INLINE
void
registry
::
flush_every
(
std
::
chrono
::
seconds
interval
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
flusher_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
flusher_mutex_
);
std
::
function
<
void
()
>
clbk
=
std
::
bind
(
&
registry
::
flush_all
,
this
);
std
::
function
<
void
()
>
clbk
=
std
::
bind
(
&
registry
::
flush_all
,
this
);
periodic_flusher_
=
details
::
make_unique
<
periodic_worker
>
(
clbk
,
interval
);
periodic_flusher_
=
details
::
make_unique
<
periodic_worker
>
(
clbk
,
interval
);
}
}
void
registry
::
set_error_handler
(
void
(
*
handler
)(
const
std
::
string
&
msg
))
SPDLOG_INLINE
void
registry
::
set_error_handler
(
void
(
*
handler
)(
const
std
::
string
&
msg
))
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
...
@@ -173,7 +173,7 @@ void registry::set_error_handler(void (*handler)(const std::string &msg))
...
@@ -173,7 +173,7 @@ void registry::set_error_handler(void (*handler)(const std::string &msg))
err_handler_
=
handler
;
err_handler_
=
handler
;
}
}
void
registry
::
apply_all
(
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
logger
>
)
>
&
fun
)
SPDLOG_INLINE
void
registry
::
apply_all
(
const
std
::
function
<
void
(
const
std
::
shared_ptr
<
logger
>
)
>
&
fun
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
...
@@ -182,7 +182,7 @@ void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)
...
@@ -182,7 +182,7 @@ void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)
}
}
}
}
void
registry
::
flush_all
()
SPDLOG_INLINE
void
registry
::
flush_all
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
for
(
auto
&
l
:
loggers_
)
for
(
auto
&
l
:
loggers_
)
...
@@ -191,7 +191,7 @@ void registry::flush_all()
...
@@ -191,7 +191,7 @@ void registry::flush_all()
}
}
}
}
void
registry
::
drop
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
void
registry
::
drop
(
const
std
::
string
&
logger_name
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
loggers_
.
erase
(
logger_name
);
loggers_
.
erase
(
logger_name
);
...
@@ -201,7 +201,7 @@ void registry::drop(const std::string &logger_name)
...
@@ -201,7 +201,7 @@ void registry::drop(const std::string &logger_name)
}
}
}
}
void
registry
::
drop_all
()
SPDLOG_INLINE
void
registry
::
drop_all
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
loggers_
.
clear
();
loggers_
.
clear
();
...
@@ -209,7 +209,7 @@ void registry::drop_all()
...
@@ -209,7 +209,7 @@ void registry::drop_all()
}
}
// clean all resources and threads started by the registry
// clean all resources and threads started by the registry
void
registry
::
shutdown
()
SPDLOG_INLINE
void
registry
::
shutdown
()
{
{
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
flusher_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
flusher_mutex_
);
...
@@ -224,24 +224,24 @@ void registry::shutdown()
...
@@ -224,24 +224,24 @@ void registry::shutdown()
}
}
}
}
std
::
recursive_mutex
&
registry
::
tp_mutex
()
SPDLOG_INLINE
std
::
recursive_mutex
&
registry
::
tp_mutex
()
{
{
return
tp_mutex_
;
return
tp_mutex_
;
}
}
void
registry
::
set_automatic_registration
(
bool
automatic_regsistration
)
SPDLOG_INLINE
void
registry
::
set_automatic_registration
(
bool
automatic_regsistration
)
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
logger_map_mutex_
);
automatic_registration_
=
automatic_regsistration
;
automatic_registration_
=
automatic_regsistration
;
}
}
registry
&
registry
::
instance
()
SPDLOG_INLINE
registry
&
registry
::
instance
()
{
{
static
registry
s_instance
;
static
registry
s_instance
;
return
s_instance
;
return
s_instance
;
}
}
void
registry
::
throw_if_exists_
(
const
std
::
string
&
logger_name
)
SPDLOG_INLINE
void
registry
::
throw_if_exists_
(
const
std
::
string
&
logger_name
)
{
{
if
(
loggers_
.
find
(
logger_name
)
!=
loggers_
.
end
())
if
(
loggers_
.
find
(
logger_name
)
!=
loggers_
.
end
())
{
{
...
@@ -249,7 +249,7 @@ void registry::throw_if_exists_(const std::string &logger_name)
...
@@ -249,7 +249,7 @@ void registry::throw_if_exists_(const std::string &logger_name)
}
}
}
}
void
registry
::
register_logger_
(
std
::
shared_ptr
<
logger
>
new_logger
)
SPDLOG_INLINE
void
registry
::
register_logger_
(
std
::
shared_ptr
<
logger
>
new_logger
)
{
{
auto
logger_name
=
new_logger
->
name
();
auto
logger_name
=
new_logger
->
name
();
throw_if_exists_
(
logger_name
);
throw_if_exists_
(
logger_name
);
...
...
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