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
ba2b6aea
Commit
ba2b6aea
authored
Mar 20, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fast_buf\!
parent
d0f3b05f
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
52 additions
and
32 deletions
+52
-32
example.cpp
example/example.cpp
+1
-2
common_types.h
include/c11log/common_types.h
+1
-0
fast_oss.h
include/c11log/details/fast_oss.h
+21
-7
flush_helper.h
include/c11log/details/flush_helper.h
+2
-2
line_logger.h
include/c11log/details/line_logger.h
+1
-1
os.h
include/c11log/details/os.h
+0
-0
formatter.h
include/c11log/formatter.h
+4
-3
logger.h
include/c11log/logger.h
+6
-3
async_sink.h
include/c11log/sinks/async_sink.h
+6
-4
base_sink.h
include/c11log/sinks/base_sink.h
+3
-3
console_sinks.h
include/c11log/sinks/console_sinks.h
+2
-2
file_sinks.h
include/c11log/sinks/file_sinks.h
+5
-5
No files found.
example/example.cpp
View file @
ba2b6aea
...
...
@@ -15,7 +15,6 @@ using namespace std::chrono;
using
namespace
c11log
;
using
namespace
utils
;
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -35,7 +34,7 @@ int main(int argc, char* argv[])
auto
start
=
system_clock
::
now
();
const
unsigned
int
howmany
=
3
000000
;
const
unsigned
int
howmany
=
5
000000
;
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
...
...
include/c11log/common_types.h
View file @
ba2b6aea
...
...
@@ -6,6 +6,7 @@ namespace c11log
{
typedef
std
::
chrono
::
system_clock
log_clock
;
typedef
std
::
pair
<
const
char
*
,
std
::
size_t
>
bufpair_t
;
namespace
level
{
...
...
include/c11log/details/fast_oss.h
View file @
ba2b6aea
...
...
@@ -2,8 +2,7 @@
// Faster than ostringstream--returns its string by ref
#include<streambuf>
#include<string>
#include "c11log/details/fast_buf.h"
namespace
c11log
{
...
...
@@ -21,15 +20,21 @@ public:
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
&
operator
=
(
str_devicebuf
&&
)
=
delete
;
/*
const std::string& str_ref() const
{
return _str;
}
*/
bufpair_t
buf
()
{
return
_fastbuf
.
get
();
}
void
reset_str
()
{
_str
.
clear
();
//_str.clear();
_fastbuf
.
clear
();
}
protected
:
...
...
@@ -42,11 +47,14 @@ protected:
// reserve initially 128 bytes which should be enough for common log lines
std
::
streamsize
xsputn
(
const
char_type
*
s
,
std
::
streamsize
count
)
override
{
/*
if(_str.capacity() < k_initial_reserve)
{
_str.reserve(k_initial_reserve);
}
_str.append(s, static_cast<unsigned int>(count));
*/
_fastbuf
.
append
(
s
,
static_cast
<
unsigned
int
>
(
count
));
return
count
;
}
...
...
@@ -62,8 +70,8 @@ protected:
return
not_eofile
;
}
private
:
std
::
string
_str
;
static
constexpr
std
::
streamsize
k_initial_reserve
=
128
;
//
std::string _str;
fast_buf
<
128
>
_fastbuf
;
};
class
fast_oss
:
public
std
::
ostream
...
...
@@ -75,11 +83,17 @@ public:
fast_oss
(
const
fast_oss
&
other
)
=
delete
;
fast_oss
(
fast_oss
&&
other
)
=
delete
;
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
=
delete
;
/*
const std::string& str_ref() const
{
return _dev.str_ref();
}
*/
bufpair_t
buf
()
{
return
_dev
.
buf
();
}
void
reset_str
()
{
_dev
.
reset_str
();
...
...
include/c11log/details/flush_helper.h
View file @
ba2b6aea
...
...
@@ -13,9 +13,9 @@ public:
_flush_every
(
flush_every
),
_write_counter
(
0
)
{};
void
write
(
std
::
ofstream
&
ofs
,
const
std
::
string
&
msg
)
void
write
(
std
::
ofstream
&
ofs
,
const
bufpair_t
&
msg
)
{
ofs
.
write
(
msg
.
c_str
(),
msg
.
size
()
);
ofs
.
write
(
msg
.
first
,
msg
.
second
);
if
(
++
_write_counter
==
_flush_every
)
{
ofs
.
flush
();
...
...
include/c11log/details/line_logger.h
View file @
ba2b6aea
...
...
@@ -50,7 +50,7 @@ public:
if
(
_enabled
)
{
_oss
<<
os
::
eol
();
_callback_logger
->
_log_it
(
_oss
.
str_re
f
(),
_level
);
_callback_logger
->
_log_it
(
_oss
.
bu
f
(),
_level
);
}
}
...
...
include/c11log/details/os.h
View file @
ba2b6aea
include/c11log/formatter.h
View file @
ba2b6aea
...
...
@@ -88,9 +88,10 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
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 = time_oss.str_ref();
bufpair_t
buf
=
time_oss
.
buf
();
std
::
memcpy
(
s_cache_str
,
buf
.
first
,
buf
.
second
);
s_cache_size
=
buf
.
second
;
}
dest
.
write
(
s_cache_str
,
s_cache_size
);
}
include/c11log/logger.h
View file @
ba2b6aea
...
...
@@ -21,6 +21,7 @@ namespace c11log
namespace
details
{
class
line_logger
;
template
<
std
::
size_t
>
class
fast_buf
;
}
...
...
@@ -67,7 +68,7 @@ private:
sinks_vector_t
_sinks
;
std
::
atomic_int
_atomic_level
;
void
_log_it
(
const
std
::
string
&
msg
,
const
level
::
level_enum
level
);
void
_log_it
(
const
bufpair_t
&
buf
,
const
level
::
level_enum
level
);
};
...
...
@@ -80,6 +81,7 @@ logger& get_logger(const std::string& name);
// Logger inline implementation
//
#include "details/line_logger.h"
#include "details/fast_buf.h"
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
name
,
formatter_ptr
f
,
sinks_init_list
sinks_list
)
:
...
...
@@ -145,10 +147,11 @@ inline bool c11log::logger::should_log(c11log::level::level_enum level) const
{
return
level
>=
_atomic_level
.
load
();
}
inline
void
c11log
::
logger
::
_log_it
(
const
std
::
string
&
msg
,
const
level
::
level_enum
level
)
inline
void
c11log
::
logger
::
_log_it
(
const
bufpair_t
&
buf
,
const
level
::
level_enum
level
)
{
for
(
auto
&
sink
:
_sinks
)
sink
->
log
(
msg
,
level
);
sink
->
log
(
buf
,
level
);
}
// Static factory function
...
...
include/c11log/sinks/async_sink.h
View file @
ba2b6aea
...
...
@@ -28,7 +28,7 @@ public:
protected
:
void
_sink_it
(
const
std
::
string
&
msg
)
override
;
void
_sink_it
(
const
bufpair_t
&
msg
)
override
;
void
_thread_loop
();
private
:
...
...
@@ -57,9 +57,10 @@ inline c11log::sinks::async_sink::~async_sink()
{
_shutdown
();
}
inline
void
c11log
::
sinks
::
async_sink
::
_sink_it
(
const
std
::
string
&
msg
)
inline
void
c11log
::
sinks
::
async_sink
::
_sink_it
(
const
bufpair_t
&
msg
)
{
_q
.
push
(
msg
);
std
::
string
s
{
msg
.
first
,
msg
.
first
+
msg
.
second
};
_q
.
push
(
s
);
}
inline
void
c11log
::
sinks
::
async_sink
::
_thread_loop
()
...
...
@@ -71,9 +72,10 @@ inline void c11log::sinks::async_sink::_thread_loop()
{
if
(
_q
.
pop
(
msg
,
pop_timeout
))
{
bufpair_t
buf
(
msg
.
data
(),
msg
.
size
());
for
(
auto
&
sink
:
_sinks
)
{
sink
->
log
(
msg
,
static_cast
<
level
::
level_enum
>
(
_level
.
load
()));
sink
->
log
(
buf
,
static_cast
<
level
::
level_enum
>
(
_level
.
load
()));
if
(
!
_active
)
return
;
}
...
...
include/c11log/sinks/base_sink.h
View file @
ba2b6aea
...
...
@@ -22,7 +22,7 @@ public:
base_sink
(
const
base_sink
&
)
=
delete
;
base_sink
&
operator
=
(
const
base_sink
&
)
=
delete
;
void
log
(
const
std
::
string
&
msg
,
level
::
level_enum
level
)
void
log
(
const
bufpair_t
&
msg
,
level
::
level_enum
level
)
{
if
(
level
>=
_level
)
{
...
...
@@ -36,14 +36,14 @@ public:
}
protected
:
virtual
void
_sink_it
(
const
std
::
string
&
msg
)
=
0
;
virtual
void
_sink_it
(
const
bufpair_t
&
msg
)
=
0
;
std
::
atomic
<
int
>
_level
{
level
::
INFO
};
};
class
null_sink
:
public
base_sink
{
protected
:
void
_sink_it
(
const
std
::
string
&
)
override
void
_sink_it
(
const
bufpair_t
&
)
override
{
}
};
...
...
include/c11log/sinks/console_sinks.h
View file @
ba2b6aea
...
...
@@ -19,10 +19,10 @@ public:
virtual
~
console_sink
()
=
default
;
protected
:
virtual
void
_sink_it
(
const
std
::
string
&
msg
)
override
virtual
void
_sink_it
(
const
bufpair_t
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_ostream
<<
msg
;
_ostream
.
write
(
msg
.
first
,
msg
.
second
)
;
}
std
::
ostream
&
_ostream
;
...
...
include/c11log/sinks/file_sinks.h
View file @
ba2b6aea
...
...
@@ -26,7 +26,7 @@ public:
{
}
protected
:
void
_sink_it
(
const
std
::
string
&
msg
)
override
void
_sink_it
(
const
bufpair_t
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_flush_helper
.
write
(
_ofstream
,
msg
);
...
...
@@ -59,14 +59,14 @@ public:
}
protected
:
void
_sink_it
(
const
std
::
string
&
msg
)
override
void
_sink_it
(
const
bufpair_t
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_current_size
+=
msg
.
length
()
;
_current_size
+=
msg
.
second
;
if
(
_current_size
>
_max_size
)
{
_rotate
();
_current_size
=
msg
.
length
()
;
_current_size
=
msg
.
second
;
}
_flush_helper
.
write
(
_ofstream
,
msg
);
}
...
...
@@ -132,7 +132,7 @@ public:
}
protected
:
void
_sink_it
(
const
std
::
string
&
msg
)
override
void
_sink_it
(
const
bufpair_t
&
msg
)
override
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_midnight_tp
)
...
...
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