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
4b5364d3
Commit
4b5364d3
authored
Mar 04, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vs2013 support
parent
8b27eb0f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
41 deletions
+62
-41
os.h
include/c11log/details/os.h
+14
-18
formatter.h
include/c11log/formatter.h
+23
-8
file_sinks.h
include/c11log/sinks/file_sinks.h
+7
-4
stdout_sinks.h
include/c11log/sinks/stdout_sinks.h
+18
-11
No files found.
include/c11log/details/os.h
View file @
4b5364d3
...
...
@@ -6,15 +6,8 @@
namespace
c11log
{
namespace
details
{
namespace
os
{
std
::
tm
localtime
(
const
std
::
time_t
&
time_tt
);
std
::
tm
localtime
();
}
}
}
inline
std
::
tm
c11log
::
details
::
os
::
localtime
(
const
std
::
time_t
&
time_tt
)
inline
std
::
tm
localtime
(
const
std
::
time_t
&
time_tt
)
{
std
::
tm
tm
;
...
...
@@ -26,7 +19,7 @@ inline std::tm c11log::details::os::localtime(const std::time_t &time_tt)
return
tm
;
}
inline
std
::
tm
c11log
::
details
::
os
::
localtime
()
inline
std
::
tm
localtime
()
{
std
::
time_t
now_t
=
time
(
0
);
return
localtime
(
now_t
);
...
...
@@ -35,17 +28,20 @@ inline std::tm c11log::details::os::localtime()
inline
bool
operator
==
(
const
std
::
tm
&
tm1
,
const
std
::
tm
&
tm2
)
{
return
(
tm1
.
tm_sec
==
tm2
.
tm_sec
&&
tm1
.
tm_min
==
tm2
.
tm_min
&&
tm1
.
tm_hour
==
tm2
.
tm_hour
&&
tm1
.
tm_mday
==
tm2
.
tm_mday
&&
tm1
.
tm_mon
==
tm2
.
tm_mon
&&
tm1
.
tm_year
==
tm2
.
tm_year
&&
tm1
.
tm_isdst
==
tm2
.
tm_isdst
&&
tm1
.
tm_gmtoff
==
tm2
.
tm_gmtoff
);
return
(
tm1
.
tm_sec
==
tm2
.
tm_sec
&&
tm1
.
tm_min
==
tm2
.
tm_min
&&
tm1
.
tm_hour
==
tm2
.
tm_hour
&&
tm1
.
tm_mday
==
tm2
.
tm_mday
&&
tm1
.
tm_mon
==
tm2
.
tm_mon
&&
tm1
.
tm_year
==
tm2
.
tm_year
&&
tm1
.
tm_isdst
==
tm2
.
tm_isdst
);
}
inline
bool
operator
!=
(
const
std
::
tm
&
tm1
,
const
std
::
tm
&
tm2
)
{
return
!
(
tm1
==
tm2
);
return
!
(
tm1
==
tm2
);
}
}
}
}
include/c11log/formatter.h
View file @
4b5364d3
...
...
@@ -5,6 +5,7 @@
#include <functional>
#include <sstream>
#include <iomanip>
#include <thread>
#include "common_types.h"
#include "details/os.h"
...
...
@@ -43,20 +44,34 @@ private:
inline
void
c11log
::
formatters
::
default_formatter
::
_format_time
(
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
{
static
thread_local
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
static
thread_local
char
last_time_str
[
64
];
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
#ifdef _MSC_VER
__declspec
(
thread
)
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
char
last_time_str
[
64
];
#else
thread_local
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
thread_local
static
char
last_time_str
[
64
];
#endif
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
using
namespace
c11log
::
details
::
os
;
if
(
last_tm
!=
tm_now
)
{
sprintf
(
last_time_str
,
"[%d-%02d-%02d %02d:%02d:%02d]"
,
{
#ifdef _MSC_VER
::
sprintf_s
#else
::
snprintf
#endif
(
last_time_str
,
sizeof
(
last_time_str
),
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm_now
.
tm_year
+
1900
,
tm_now
.
tm_mon
+
1
,
tm_now
.
tm_mday
,
tm_now
.
tm_hour
,
tm_now
.
tm_min
,
tm_now
.
tm_sec
);
last_tm
=
tm_now
;
}
dest
<<
last_time_str
;
last_tm
=
tm_now
;
}
dest
<<
last_time_str
;
}
include/c11log/sinks/file_sinks.h
View file @
4b5364d3
...
...
@@ -140,11 +140,14 @@ private:
return
system_clock
::
time_point
(
midnight
+
hours
(
24
));
}
//Create filename for the form basename.YYYY-MM-DD.extension
static
std
::
string
_calc_filename
(
const
std
::
string
&
basename
,
const
std
::
string
&
extension
)
{
std
::
tm
tm
=
c11log
::
details
::
os
::
localtime
();
char
buf
[
32
];
sprintf
(
buf
,
".%d-%02d-%02d."
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
);
return
basename
+
buf
+
extension
;
std
::
tm
tm
=
c11log
::
details
::
os
::
localtime
();
std
::
ostringstream
oss
;
oss
<<
basename
<<
'.'
;
oss
<<
tm
.
tm_year
+
1900
<<
'-'
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tm
.
tm_mon
+
1
<<
'-'
<<
tm
.
tm_mday
;
oss
<<
'.'
<<
extension
;
return
oss
.
str
();
}
std
::
string
_base_filename
;
...
...
include/c11log/sinks/stdout_sinks.h
View file @
4b5364d3
#pragma once
#include <iostream>
#include <mutex>
#include <memory>
#include "base_sink.h"
namespace
c11log
{
namespace
sinks
{
class
ostream_sink
:
public
base_sink
{
public
:
ostream_sink
(
std
::
ostream
&
os
)
:
_ostream
(
os
)
{}
explicit
ostream_sink
(
std
::
ostream
&
os
)
:
_ostream
(
os
)
{}
ostream_sink
(
const
ostream_sink
&
)
=
delete
;
ostream_sink
&
operator
=
(
const
ostream_sink
&
)
=
delete
;
virtual
~
ostream_sink
()
=
default
;
protected
:
virtual
void
_sink_it
(
const
std
::
string
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_ostream
<<
msg
;
}
std
::
ostream
&
_ostream
;
std
::
mutex
_mutex
;
};
class
stdout_sink
:
public
ostream_sink
{
public
:
stdout_sink
()
:
ostream_sink
(
std
::
cout
)
{}
}
;
inline
std
::
shared_ptr
<
ostream_sink
>
cout_sink
()
{
static
const
ostream_sink
&
instance
{
std
::
cout
};
return
std
::
shared_ptr
<
ostream_sink
>
(
&
instance
,
[
=
](
ostream_sink
*
)
{});
}
class
stderr_sink
:
public
ostream_sink
{
public
:
stderr_sink
()
:
ostream_sink
(
std
::
cerr
)
{}
inline
std
::
shared_ptr
<
ostream_sink
>
cerr_sink
()
{
static
const
ostream_sink
&
instance
=
ostream_sink
(
std
::
cerr
);
return
std
::
shared_ptr
<
ostream_sink
>
(
&
instance
,
[
=
](
ostream_sink
*
)
{});
}
};
}
}
}
\ No newline at end of file
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