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
1579b24e
Commit
1579b24e
authored
Feb 06, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
timepoint
parent
6400b188
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
42 deletions
+23
-42
include/c11log/formatters/formatters.h
include/c11log/formatters/formatters.h
+6
-5
src/formatters.cpp
src/formatters.cpp
+10
-7
src/line_logger.cpp
src/line_logger.cpp
+2
-2
src/test.cpp
src/test.cpp
+5
-28
No files found.
include/c11log/formatters/formatters.h
View file @
1579b24e
...
...
@@ -10,9 +10,10 @@
namespace
c11log
{
namespace
formatters
{
typedef
std
::
chrono
::
system_clock
::
time_point
timepoint
;
typedef
std
::
function
<
std
::
string
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
,
level
::
level_enum
,
const
timepoint
&
)
>
format_fn
;
void
format_time
(
const
timepoint
&
tp
,
std
::
ostream
&
dest
);
typedef
std
::
chrono
::
system_clock
clock
;
typedef
clock
::
time_point
time_point
;
typedef
std
::
function
<
std
::
string
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
,
level
::
level_enum
,
const
time_point
&
)
>
format_fn
;
void
format_time
(
const
time_point
&
tp
,
std
::
ostream
&
dest
);
void
format_time
(
std
::
ostream
&
dest
);
std
::
string
to_hex
(
const
unsigned
char
*
buf
,
std
::
size_t
size
);
...
...
@@ -20,14 +21,14 @@ class formatter {
public:
formatter
()
{}
virtual
~
formatter
()
{}
virtual
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
timepoint
&
tp
,
std
::
ostream
&
dest
)
=
0
;
virtual
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
time
_
point
&
tp
,
std
::
ostream
&
dest
)
=
0
;
};
class
default_formatter
:
public
formatter
{
public:
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
timepoint
&
tp
,
std
::
ostream
&
dest
)
override
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
time
_
point
&
tp
,
std
::
ostream
&
dest
)
override
{
format_time
(
tp
,
dest
);
dest
<<
" ["
<<
logger_name
<<
":"
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
...
...
src/formatters.cpp
View file @
1579b24e
...
...
@@ -6,31 +6,34 @@
static
thread_local
std
::
tm
last_tm
;
static
thread_local
c11log
::
formatters
::
time_point
last_tp
;
static
thread_local
char
timestamp_cache
[
64
];
void
c11log
::
formatters
::
format_time
(
const
c11log
::
formatters
::
time
point
&
tp
,
std
::
ostream
&
dest
)
void
c11log
::
formatters
::
format_time
(
const
time_
point
&
tp
,
std
::
ostream
&
dest
)
{
auto
tm
=
details
::
os
::
localtime
(
std
::
chrono
::
system_clock
::
to_time_t
(
tp
));
using
namespace
std
::
chrono
;
// Cache timestamp string of last second
if
(
memcmp
(
&
tm
,
&
last_tm
,
sizeof
(
tm
))
)
if
(
duration_cast
<
seconds
>
(
tp
-
last_tp
).
count
()
>=
1
)
{
auto
tm
=
details
::
os
::
localtime
(
std
::
chrono
::
system_clock
::
to_time_t
(
tp
));
sprintf
(
timestamp_cache
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
tm
.
tm_sec
);
last_t
m
=
tm
;
last_t
p
=
tp
;
}
dest
<<
timestamp_cache
;
}
void
c11log
::
formatters
::
format_time
(
std
::
ostream
&
dest
)
{
return
format_time
(
std
::
chrono
::
system_
clock
::
now
(),
dest
);
return
format_time
(
c11log
::
formatters
::
clock
::
now
(),
dest
);
}
...
...
src/line_logger.cpp
View file @
1579b24e
...
...
@@ -7,7 +7,7 @@ c11log::details::line_logger::line_logger(logger* callback_logger, level::level_
if
(
callback_logger
)
{
callback_logger
->
formatter_
->
format_header
(
callback_logger
->
logger_name_
,
msg_level
,
c11log
::
formatters
::
timepoint
::
clock
::
now
(),
c11log
::
formatters
::
clock
::
now
(),
_oss
);
}
}
...
...
@@ -18,4 +18,4 @@ c11log::details::line_logger::~line_logger()
_oss
<<
'\n'
;
_callback_logger
->
log_it_
(
_oss
.
str_ref
());
}
}
\ No newline at end of file
}
src/test.cpp
View file @
1579b24e
// test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <functional>
...
...
@@ -27,32 +26,13 @@ void pusher(Q* q)
while
(
active
)
{
logger
.
info
()
<<
"Hello logger!"
;
++
push_count
;
++
push_count
;
}
/*
string a = "Hello";
while(active)
{
q->push(a);
++push_count;
}
*/
}
void
popper
(
Q
*
q
)
{
string
output
;
while
(
active
)
{
q
->
pop
(
output
);
++
pop_count
;
}
}
void
testq
(
int
size
,
int
pushers
,
int
poppers
)
{
...
...
@@ -107,11 +87,8 @@ int main(int argc, char* argv[])
auto
async
=
std
::
make_shared
<
c11log
::
sinks
::
async_sink
>
(
1000
);
auto
fsink
=
std
::
make_shared
<
c11log
::
sinks
::
rotating_file_sink
>
(
"newlog"
,
"txt"
,
1024
*
1024
*
10
,
2
);
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
//Async logger
async
->
add_sink
(
null_sink
);
async
->
add_sink
(
fsink
);
auto
&
logger
=
c11log
::
get_logger
(
"async"
);
logger
.
add_sink
(
async
);
...
...
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