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
d8a77c30
Commit
d8a77c30
authored
Feb 11, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
be78e51f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
12 additions
and
19 deletions
+12
-19
makefile
build/gcc/makefile
+1
-1
formatters.h
include/c11log/formatters/formatters.h
+5
-3
formatters.cpp
src/formatters.cpp
+4
-13
test.cpp
src/test.cpp
+2
-2
No files found.
build/gcc/makefile
View file @
d8a77c30
...
...
@@ -9,7 +9,7 @@ OBJS_DEBUG = $(patsubst %.cpp,debug/%.o,$(_SOURCES))
CXX
=
g++
CXXFLAGS
=
-march
=
native
-Wall
-Wextra
-Wshadow
-pedantic
-std
=
c++11
-pthread
-I
../../include
CXX_RELEASE_FLAGS
=
-O
2
-flto
-g
CXX_RELEASE_FLAGS
=
-O
3
-flto
CXX_DEBUG_FLAGS
=
-g
OUTLIB_RELEASE
=
libc11log.a
...
...
include/c11log/formatters/formatters.h
View file @
d8a77c30
...
...
@@ -13,8 +13,8 @@ namespace formatters {
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
);
class
formatter
{
...
...
@@ -30,9 +30,11 @@ 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
time_point
&
tp
,
std
::
ostream
&
dest
)
override
{
format_time
(
tp
,
dest
);
_
format_time
(
tp
,
dest
);
dest
<<
" ["
<<
logger_name
<<
":"
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
}
private
:
void
_format_time
(
const
time_point
&
tp
,
std
::
ostream
&
dest
);
};
}
//namespace formatter
...
...
src/formatters.cpp
View file @
d8a77c30
...
...
@@ -4,18 +4,15 @@
#include "c11log/formatters/formatters.h"
#include "c11log/level.h"
thread_local
c11log
::
formatters
::
time_point
last_tp
;
thread_local
char
timestamp_cache
[
64
];
static
thread_local
c11log
::
formatters
::
time_point
last_tp
;
static
thread_local
char
timestamp_cache
[
64
];
void
c11log
::
formatters
::
format_time
(
const
time_point
&
tp
,
std
::
ostream
&
dest
)
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
time_point
&
tp
,
std
::
ostream
&
dest
)
{
// Cache timestamp string of last second
using
namespace
std
::
chrono
;
if
(
duration_cast
<
seconds
>
(
tp
-
last_tp
).
count
()
>=
1
)
if
(
duration_cast
<
milliseconds
>
(
tp
-
last_tp
).
count
()
>=
950
)
{
auto
tm
=
details
::
os
::
localtime
(
clock
::
to_time_t
(
tp
));
sprintf
(
timestamp_cache
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm
.
tm_year
+
1900
,
...
...
@@ -26,15 +23,9 @@ void c11log::formatters::format_time(const time_point& tp, std::ostream &dest)
tm
.
tm_sec
);
last_tp
=
tp
;
}
dest
<<
timestamp_cache
;
}
void
c11log
::
formatters
::
format_time
(
std
::
ostream
&
dest
)
{
return
format_time
(
c11log
::
formatters
::
clock
::
now
(),
dest
);
}
static
const
char
_hex_chars
[
17
]
=
"0123456789ABCDEF"
;
...
...
src/test.cpp
View file @
d8a77c30
...
...
@@ -84,10 +84,10 @@ int main(int argc, char* argv[])
auto
null_sink
=
std
::
make_shared
<
c11log
::
sinks
::
null_sink
>
();
auto
stdout_sink
=
std
::
make_shared
<
c11log
::
sinks
::
stdout_sink
>
();
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
::
rotating_file_sink
>
(
"newlog"
,
"txt"
,
1024
*
1024
*
50
,
5
);
//auto fsink = std::make_shared<c11log::sinks::daily_file_sink>("daily", "txt");
async
->
add_sink
(
null_
sink
);
async
->
add_sink
(
f
sink
);
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