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
d0f3b05f
Commit
d0f3b05f
authored
Mar 18, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
formatter msvc support
parent
da82d8e2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
38 deletions
+46
-38
makefile.clang
example/makefile.clang
+1
-1
fast_oss.h
include/c11log/details/fast_oss.h
+9
-4
formatter.h
include/c11log/formatter.h
+36
-33
No files found.
example/makefile.clang
View file @
d0f3b05f
CXX
=
clang++
CXXFLAGS
=
-march
=
native
-Wall
-Wextra
-Wshadow
-pedantic
-std
=
c++11
-pthread
-I
../include
-B
/usr/lib/gold-ld/
CXX_RELEASE_FLAGS
=
-O3
-flto
CXX_RELEASE_FLAGS
=
-O3
CXX_DEBUG_FLAGS
=
-g
OUTBIN
=
example-clang
...
...
include/c11log/details/fast_oss.h
View file @
d0f3b05f
#pragma once
// Fast
ostringstream like supprt which return its string by ref and nothing more
// Fast
er than ostringstream--returns its string by ref
#include<streambuf>
#include<string>
...
...
@@ -52,9 +52,14 @@ protected:
int_type
overflow
(
int_type
ch
)
override
{
if
(
ch
!=
traits_type
::
eof
())
xsputn
((
char
*
)
&
ch
,
1
);
return
1
;
bool
not_eofile
=
traits_type
::
not_eof
(
ch
);
if
(
not_eofile
)
{
char
c
=
traits_type
::
to_char_type
(
ch
);
xsputn
(
&
c
,
1
);
}
return
not_eofile
;
}
private
:
std
::
string
_str
;
...
...
include/c11log/formatter.h
View file @
d0f3b05f
...
...
@@ -7,6 +7,7 @@
#include <iomanip>
#include <thread>
#include <cstdlib>
#include <cstring>
#include "common_types.h"
#include "details/os.h"
...
...
@@ -46,48 +47,50 @@ private:
void
_format_time
(
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
);
};
}
//namespace formatter
}
//namespace c11log
// Format datetime like this: [2014-03-14 17:15:22]
inline
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
{
using
namespace
c11log
::
details
::
os
;
using
namespace
std
::
chrono
;
using
namespace
c11log
::
details
::
os
;
using
namespace
std
::
chrono
;
#ifdef _MSC_VER
__declspec
(
thread
)
static
std
::
tm
s_last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
details
::
fast_oss
s_time_oss
;
#ifdef _WIN32 //VS2013 doesn't support yet thread_local keyword
__declspec
(
thread
)
static
char
s_cache_str
[
64
];
__declspec
(
thread
)
static
size_t
s_cache_size
;
__declspec
(
thread
)
static
std
::
time_t
s_cache_time_t
=
0
;
#else
thread_local
static
details
::
fast_oss
s_time_oss
;
thread_local
static
std
::
time_t
s_cache_time_t
=
0
;
thread_local
static
char
s_cache_str
[
64
];
thread_local
static
size_t
s_cache_size
;
thread_local
static
std
::
time_t
s_cache_time_t
=
0
;
#endif
std
::
time_t
tp_time_t
=
log_clock
::
to_time_t
(
tp
);
//Cache every second
if
(
tp_time_t
!=
s_cache_time_t
)
{
auto
tm_now
=
details
::
os
::
localtime
(
tp_time_t
);
s_time_oss
.
reset_str
();
s_time_oss
.
fill
(
'0'
);
s_time_oss
<<
'['
<<
tm_now
.
tm_year
+
1900
<<
'-'
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_mon
+
1
<<
'-'
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_mday
<<
' '
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_hour
<<
':'
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_min
<<
':'
;
s_time_oss
.
width
(
2
);
s_time_oss
<<
tm_now
.
tm_sec
<<
']'
;
s_cache_time_t
=
tp_time_t
;
//Cache every second
std
::
time_t
tp_time_t
=
log_clock
::
to_time_t
(
tp
);
if
(
tp_time_t
!=
s_cache_time_t
)
{
auto
tm_now
=
details
::
os
::
localtime
(
tp_time_t
);
details
::
fast_oss
time_oss
;
time_oss
.
fill
(
'0'
);
time_oss
<<
'['
<<
tm_now
.
tm_year
+
1900
<<
'-'
;
time_oss
.
width
(
2
);
time_oss
<<
tm_now
.
tm_mon
+
1
<<
'-'
;
time_oss
.
width
(
2
);
time_oss
<<
tm_now
.
tm_mday
<<
' '
;
time_oss
.
width
(
2
);
time_oss
<<
tm_now
.
tm_hour
<<
':'
;
time_oss
.
width
(
2
);
time_oss
<<
tm_now
.
tm_min
<<
':'
;
time_oss
.
width
(
2
);
time_oss
<<
tm_now
.
tm_sec
<<
']'
;
//Cache the resulted string and its size
s_cache_time_t
=
tp_time_t
;
const
std
::
string
&
s
=
time_oss
.
str_ref
();
std
::
memcpy
(
s_cache_str
,
s
.
c_str
(),
s
.
size
());
s_cache_size
=
s
.
size
();
}
const
std
::
string
&
s
=
s_time_oss
.
str_ref
();
dest
.
write
(
s
.
c_str
(),
s
.
size
());
dest
.
write
(
s_cache_str
,
s_cache_size
);
}
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