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
fd3f13cd
Commit
fd3f13cd
authored
Nov 20, 2014
by
gabi
Committed by
gabime
Nov 20, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert sink accepting only char* and size_t
parent
a3a8f107
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
64 additions
and
77 deletions
+64
-77
README.md
README.md
+11
-18
file_helper.h
include/spdlog/details/file_helper.h
+8
-8
logger_impl.h
include/spdlog/details/logger_impl.h
+1
-2
async_sink.h
include/spdlog/sinks/async_sink.h
+21
-28
base_sink.h
include/spdlog/sinks/base_sink.h
+3
-3
file_sinks.h
include/spdlog/sinks/file_sinks.h
+14
-14
null_sink.h
include/spdlog/sinks/null_sink.h
+1
-1
ostream_sink.h
include/spdlog/sinks/ostream_sink.h
+3
-2
sink.h
include/spdlog/sinks/sink.h
+2
-1
No files found.
README.md
View file @
fd3f13cd
...
...
@@ -14,24 +14,17 @@ Just copy the files to your build tree and use a C++11 compiler
*
mingw with g++ 4.9.x
##Features
*
Very fast - performance is the primary goal (see becnhmarks below).
*
Headers only.
*
No dependencies.
*
Cross platform - Linux / Windows on 32/64 bits.
*
Variadic-template/stream call styles:
```logger.info("variadic", x, y) << "or stream" << x << y;```
*
[
Custom
](
https://github.com/gabime/spdlog/wiki/Custom-formatting
)
formatting.
*
Multi/Single threaded loggers.
*
Various log targets:
*
Rotating log files.
*
Daily log files.
*
Console logging.
*
Linux syslog.
*
Easily extendable with custom log targets (just implement a single function in the
[
sink
](
include/spdlog/sinks/sink.h
)
interface).
*
Optional async logging .
*
Log levels.
*
Very fast - performance is the primary goal (see becnhmarks below)
*
Headers only
*
No dependencies
*
Cross platform - Linux / Windows on 32/64 bits
*
Multi/Single threaded loggers
*
Rotating log files
*
Daily log files
*
Console logging
*
Optional async logging
*
Logging levels
*
Custom formatting with user defined patterns
## Benchmarks
...
...
include/spdlog/details/file_helper.h
View file @
fd3f13cd
...
...
@@ -82,10 +82,10 @@ public:
void
reopen
()
{
if
(
_filename
.
empty
())
throw
spdlog_ex
(
"Failed re opening file - was not opened before"
);
open
(
_filename
);
if
(
_filename
.
empty
())
throw
spdlog_ex
(
"Failed re opening file - was not opened before"
);
open
(
_filename
);
}
void
close
()
...
...
@@ -97,11 +97,11 @@ public:
}
}
void
write
(
const
char
*
data
,
size_t
size
)
void
write
(
const
log_msg
&
msg
)
{
if
(
std
::
fwrite
(
data
,
sizeof
(
char
),
size
,
_fd
)
!=
size
)
auto
&
buf
=
msg
.
formatted
.
buf
();
size_t
size
=
buf
.
size
();
if
(
std
::
fwrite
(
buf
.
data
()
,
sizeof
(
char
),
size
,
_fd
)
!=
size
)
throw
spdlog_ex
(
"Failed writing to file "
+
_filename
);
if
(
--
_flush_countdown
==
0
)
...
...
include/spdlog/details/logger_impl.h
View file @
fd3f13cd
...
...
@@ -184,8 +184,7 @@ inline void spdlog::logger::_variadic_log(spdlog::details::line_logger& l, const
inline
void
spdlog
::
logger
::
_log_msg
(
details
::
log_msg
&
msg
)
{
_formatter
->
format
(
msg
);
auto
buf
=
msg
.
formatted
.
buf
();
for
(
auto
&
sink
:
_sinks
)
sink
->
sink_it
(
buf
.
data
(),
buf
.
size
()
);
sink
->
log
(
msg
);
}
include/spdlog/sinks/async_sink.h
View file @
fd3f13cd
...
...
@@ -53,8 +53,7 @@ namespace sinks
class
async_sink
:
public
base_sink
<
details
::
null_mutex
>
{
public
:
using
data_type
=
std
::
pair
<
const
char
*
,
size_t
>
;
using
q_type
=
details
::
blocking_queue
<
data_type
>
;
using
q_type
=
details
::
blocking_queue
<
details
::
log_msg
>
;
explicit
async_sink
(
const
q_type
::
size_type
max_queue_size
);
...
...
@@ -69,7 +68,7 @@ public:
protected
:
void
_sink_it
(
const
char
*
,
size_t
)
override
;
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
;
void
_thread_loop
();
private
:
...
...
@@ -107,12 +106,10 @@ inline spdlog::sinks::async_sink::~async_sink()
_join
();
}
inline
void
spdlog
::
sinks
::
async_sink
::
_sink_it
(
const
char
*
data
,
size_t
size
)
inline
void
spdlog
::
sinks
::
async_sink
::
_sink_it
(
const
details
::
log_msg
&
msg
)
{
_push_sentry
();
auto
data_copy
=
new
char
[
size
];
std
::
memcpy
(
data_copy
,
data
,
size
);
_q
.
push
(
data_type
(
data_copy
,
size
));
_q
.
push
(
msg
);
}
...
...
@@ -123,35 +120,31 @@ inline void spdlog::sinks::async_sink::_thread_loop()
while
(
_active
)
{
q_type
::
item_type
msg
;
if
(
!
_q
.
pop
(
msg
,
pop_timeout
))
continue
;
if
(
!
_active
)
return
;
for
(
auto
&
s
:
_sinks
)
if
(
_q
.
pop
(
msg
,
pop_timeout
))
{
try
if
(
!
_active
)
return
;
for
(
auto
&
s
:
_sinks
)
{
s
->
sink_it
(
msg
.
first
,
msg
.
second
);
}
try
{
s
->
log
(
msg
);
}
catch
(
const
std
::
exception
&
ex
)
{
_last_backthread_ex
=
std
::
make_shared
<
spdlog_ex
>
(
ex
.
what
());
}
catch
(...)
{
_last_backthread_ex
=
std
::
make_shared
<
spdlog_ex
>
(
"Unknown exception"
);
}
catch
(
const
std
::
exception
&
ex
)
{
_last_backthread_ex
=
std
::
make_shared
<
spdlog_ex
>
(
ex
.
what
());
}
catch
(...)
{
_last_backthread_ex
=
std
::
make_shared
<
spdlog_ex
>
(
"Unknown exception"
);
}
}
delete
[]
msg
.
first
;
}
}
inline
void
spdlog
::
sinks
::
async_sink
::
add_sink
(
spdlog
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
...
...
include/spdlog/sinks/base_sink.h
View file @
fd3f13cd
...
...
@@ -52,15 +52,15 @@ public:
base_sink
(
const
base_sink
&
)
=
delete
;
base_sink
&
operator
=
(
const
base_sink
&
)
=
delete
;
void
sink_it
(
const
char
*
data
,
size_t
size
)
override
void
log
(
const
details
::
log_msg
&
msg
)
override
{
std
::
lock_guard
<
Mutex
>
lock
(
_mutex
);
_sink_it
(
data
,
size
);
_sink_it
(
msg
);
};
protected
:
virtual
void
_sink_it
(
const
char
*
data
,
size_t
size
)
=
0
;
virtual
void
_sink_it
(
const
details
::
log_msg
&
msg
)
=
0
;
Mutex
_mutex
;
};
}
...
...
include/spdlog/sinks/file_sinks.h
View file @
fd3f13cd
...
...
@@ -52,9 +52,9 @@ public:
}
protected
:
void
_sink_it
(
const
char
*
data
,
size_t
size
)
override
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_file_helper
.
write
(
data
,
size
);
_file_helper
.
write
(
msg
);
}
private
:
details
::
file_helper
_file_helper
;
...
...
@@ -85,15 +85,15 @@ public:
protected
:
void
_sink_it
(
const
char
*
data
,
size_t
size
)
override
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_current_size
+=
size
;
_current_size
+=
msg
.
formatted
.
size
()
;
if
(
_current_size
>
_max_size
)
{
_rotate
();
_current_size
=
size
;
_current_size
=
msg
.
formatted
.
size
()
;
}
_file_helper
.
write
(
data
,
size
);
_file_helper
.
write
(
msg
);
}
...
...
@@ -125,12 +125,12 @@ private:
std
::
string
target
=
calc_filename
(
_base_filename
,
i
,
_extension
);
if
(
details
::
file_helper
::
file_exists
(
target
))
{
if
(
std
::
remove
(
target
.
c_str
())
!=
0
)
{
throw
spdlog_ex
(
"rotating_file_sink: failed removing "
+
target
);
}
}
{
if
(
std
::
remove
(
target
.
c_str
())
!=
0
)
{
throw
spdlog_ex
(
"rotating_file_sink: failed removing "
+
target
);
}
}
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
std
::
rename
(
src
.
c_str
(),
target
.
c_str
()))
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming "
+
src
+
" to "
+
target
);
...
...
@@ -169,7 +169,7 @@ public:
protected
:
void
_sink_it
(
const
char
*
data
,
size_t
size
)
override
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_midnight_tp
)
{
...
...
@@ -177,7 +177,7 @@ protected:
_file_helper
.
open
(
calc_filename
(
_base_filename
,
_extension
));
_midnight_tp
=
_calc_midnight_tp
();
}
_file_helper
.
write
(
data
,
size
);
_file_helper
.
write
(
msg
);
}
private
:
...
...
include/spdlog/sinks/null_sink.h
View file @
fd3f13cd
...
...
@@ -37,7 +37,7 @@ template <class Mutex>
class
null_sink
:
public
base_sink
<
Mutex
>
{
protected
:
void
_sink_it
(
const
char
*
,
size_t
)
override
void
_sink_it
(
const
details
::
log_msg
&
)
override
{}
};
...
...
include/spdlog/sinks/ostream_sink.h
View file @
fd3f13cd
...
...
@@ -45,9 +45,10 @@ public:
virtual
~
ostream_sink
()
=
default
;
protected
:
v
oid
_sink_it
(
const
char
*
data
,
size_t
size
)
override
v
irtual
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_ostream
.
write
(
data
,
size
);
auto
&
buf
=
msg
.
formatted
.
buf
();
_ostream
.
write
(
buf
.
data
(),
buf
.
size
());
}
std
::
ostream
&
_ostream
;
};
...
...
include/spdlog/sinks/sink.h
View file @
fd3f13cd
...
...
@@ -24,6 +24,7 @@
#pragma once
#include "../details/log_msg.h"
namespace
spdlog
{
...
...
@@ -33,7 +34,7 @@ class sink
{
public
:
virtual
~
sink
()
{}
virtual
void
sink_it
(
const
char
*
data
,
size_t
size
)
=
0
;
virtual
void
log
(
const
details
::
log_msg
&
msg
)
=
0
;
};
}
}
...
...
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