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
1ab63ffd
Commit
1ab63ffd
authored
May 18, 2017
by
Gabi Melman
Committed by
GitHub
May 18, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #445 from alzix/message_counter
implement message counter feature
parents
bf3a415b
ef6eb376
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
55 additions
and
15 deletions
+55
-15
async_log_helper.h
include/spdlog/details/async_log_helper.h
+15
-9
log_msg.h
include/spdlog/details/log_msg.h
+2
-0
logger_impl.h
include/spdlog/details/logger_impl.h
+16
-5
pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+14
-1
logger.h
include/spdlog/logger.h
+1
-0
tweakme.h
include/spdlog/tweakme.h
+7
-0
No files found.
include/spdlog/details/async_log_helper.h
View file @
1ab63ffd
...
...
@@ -51,24 +51,27 @@ class async_log_helper
size_t
thread_id
;
std
::
string
txt
;
async_msg_type
msg_type
;
size_t
msg_id
;
async_msg
()
=
default
;
~
async_msg
()
=
default
;
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
logger_name
(
std
::
move
(
other
.
logger_name
)),
level
(
std
::
move
(
other
.
level
)),
time
(
std
::
move
(
other
.
time
)),
thread_id
(
other
.
thread_id
),
txt
(
std
::
move
(
other
.
txt
)),
msg_type
(
std
::
move
(
other
.
msg_type
))
async_msg
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
:
logger_name
(
std
::
move
(
other
.
logger_name
)),
level
(
std
::
move
(
other
.
level
)),
time
(
std
::
move
(
other
.
time
)),
thread_id
(
other
.
thread_id
),
txt
(
std
::
move
(
other
.
txt
)),
msg_type
(
std
::
move
(
other
.
msg_type
)),
msg_id
(
other
.
msg_id
)
{}
async_msg
(
async_msg_type
m_type
)
:
level
(
level
::
info
),
thread_id
(
0
),
msg_type
(
m_type
)
msg_type
(
m_type
),
msg_id
(
0
)
{}
async_msg
&
operator
=
(
async_msg
&&
other
)
SPDLOG_NOEXCEPT
...
...
@@ -79,6 +82,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
thread_id
=
other
.
thread_id
;
txt
=
std
::
move
(
other
.
txt
);
msg_type
=
other
.
msg_type
;
msg_id
=
other
.
msg_id
;
return
*
this
;
}
...
...
@@ -92,7 +96,8 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
time
(
m
.
time
),
thread_id
(
m
.
thread_id
),
txt
(
m
.
raw
.
data
(),
m
.
raw
.
size
()),
msg_type
(
async_msg_type
::
log
)
msg_type
(
async_msg_type
::
log
),
msg_id
(
m
.
msg_id
)
{
#ifndef SPDLOG_NO_NAME
logger_name
=
*
m
.
logger_name
;
...
...
@@ -108,6 +113,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
msg
.
time
=
time
;
msg
.
thread_id
=
thread_id
;
msg
.
raw
<<
txt
;
msg
.
msg_id
=
msg_id
;
}
};
...
...
include/spdlog/details/log_msg.h
View file @
1ab63ffd
...
...
@@ -41,6 +41,8 @@ struct log_msg
size_t
thread_id
;
fmt
::
MemoryWriter
raw
;
fmt
::
MemoryWriter
formatted
;
size_t
msg_id
;
};
}
}
include/spdlog/details/logger_impl.h
View file @
1ab63ffd
...
...
@@ -21,7 +21,8 @@ inline spdlog::logger::logger(const std::string& logger_name, const It& begin, c
_formatter
(
std
::
make_shared
<
pattern_formatter
>
(
"%+"
)),
_level
(
level
::
info
),
_flush_level
(
level
::
off
),
_last_err_time
(
0
)
_last_err_time
(
0
),
_msg_counter
(
1
)
// message counter will start from 1. 0-message id will be reserved for controll messages
{
_err_handler
=
[
this
](
const
std
::
string
&
msg
)
{
...
...
@@ -37,10 +38,7 @@ inline spdlog::logger::logger(const std::string& logger_name, sinks_init_list si
// ctor with single sink
inline
spdlog
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
spdlog
::
sink_ptr
single_sink
)
:
logger
(
logger_name
,
{
single_sink
})
logger
(
logger_name
,
{
single_sink
})
{}
...
...
@@ -67,6 +65,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* fmt, const Ar
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
.
write
(
fmt
,
args
...);
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg
.
msg_id
=
_msg_counter
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
#endif
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
...
...
@@ -87,6 +90,11 @@ inline void spdlog::logger::log(level::level_enum lvl, const char* msg)
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
<<
msg
;
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg
.
msg_id
=
_msg_counter
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
#endif
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
...
...
@@ -108,6 +116,9 @@ inline void spdlog::logger::log(level::level_enum lvl, const T& msg)
{
details
::
log_msg
log_msg
(
&
_name
,
lvl
);
log_msg
.
raw
<<
msg
;
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
log_msg
.
msg_id
=
_msg_counter
.
fetch_add
(
1
,
std
::
memory_order_relaxed
);
#endif
_sink_it
(
log_msg
);
}
catch
(
const
std
::
exception
&
ex
)
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
1ab63ffd
...
...
@@ -92,7 +92,14 @@ class a_formatter:public flag_formatter
msg
.
formatted
<<
days
()[
tm_time
.
tm_wday
];
}
};
// message counter formatter
class
i_formatter
SPDLOG_FINAL
:
public
flag_formatter
{
void
format
(
details
::
log_msg
&
msg
,
const
std
::
tm
&
tm_time
)
override
{
msg
.
formatted
<<
'#'
<<
msg
.
msg_id
;
}
};
//Full weekday name
static
const
days_array
&
full_days
()
{
...
...
@@ -645,6 +652,12 @@ inline void spdlog::pattern_formatter::handle_flag(char flag)
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
pid_formatter
()));
break
;
#if defined(SPDLOG_ENABLE_MESSAGE_COUNTER)
case
(
'i'
):
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
i_formatter
()));
break
;
#endif
default
:
//Unknown flag appears as is
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
ch_formatter
(
'%'
)));
_formatters
.
push_back
(
std
::
unique_ptr
<
details
::
flag_formatter
>
(
new
details
::
ch_formatter
(
flag
)));
...
...
include/spdlog/logger.h
View file @
1ab63ffd
...
...
@@ -98,6 +98,7 @@ protected:
spdlog
::
level_t
_flush_level
;
log_err_handler
_err_handler
;
std
::
atomic
<
time_t
>
_last_err_time
;
std
::
atomic
<
size_t
>
_msg_counter
;
};
}
...
...
include/spdlog/tweakme.h
View file @
1ab63ffd
...
...
@@ -120,3 +120,10 @@
//
// #define SPDLOG_FINAL final
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable message counting feature. Adds %i logger pattern that
// prints log message sequence id.
//
// #define SPDLOG_ENABLE_MESSAGE_COUNTER
///////////////////////////////////////////////////////////////////////////////
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