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
bf75bfd9
Commit
bf75bfd9
authored
Mar 06, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed fast_oss in favour of simple ostringsream
parent
5f4bc308
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
37 additions
and
31 deletions
+37
-31
example.cpp
example/example.cpp
+4
-3
fast_oss.h
include/c11log/details/fast_oss.h
+11
-9
line_logger.h
include/c11log/details/line_logger.h
+19
-11
formatter.h
include/c11log/formatter.h
+0
-0
logger.h
include/c11log/logger.h
+3
-8
No files found.
example/example.cpp
View file @
bf75bfd9
...
...
@@ -2,7 +2,6 @@
//
#include <string>
#include <functional>
#include <iomanip>
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
...
...
@@ -60,10 +59,12 @@ int main(int argc, char* argv[])
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
//auto async = std::make_shared<sinks::async_sink>(1000);
//async->add_sink(fsink);
my_logger
.
add_sink
(
fsink
);
my_logger
.
add_sink
(
null_sink
);
auto
start
=
system_clock
::
now
();
const
unsigned
int
howmany
=
10
000000
;
const
unsigned
int
howmany
=
5
000000
;
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
...
...
include/c11log/details/fast_oss.h
View file @
bf75bfd9
...
...
@@ -10,12 +10,15 @@ public:
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
str_devicebuf
(
const
str_devicebuf
&
other
)
:
std
::
streambuf
(),
_str
(
other
.
_str
)
{}
str_devicebuf
&
operator
=
(
const
str_devicebuf
other
)
{
if
(
this
!=
&
other
)
_str
=
other
.
_str
;
return
*
this
;
str_devicebuf
(
str_devicebuf
&&
other
)
:
std
::
streambuf
(),
_str
(
std
::
move
(
other
.
_str
))
{
other
.
_str
.
clear
();
}
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
&
operator
=
(
str_devicebuf
&&
)
=
delete
;
const
std
::
string
&
str_ref
()
const
{
return
_str
;
std
::
ostringstream
oss
;
...
...
@@ -51,11 +54,10 @@ public:
fast_oss
(
const
fast_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
other
.
_dev
)
{}
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
{
if
(
&
other
!=
this
)
_dev
=
other
.
_dev
;
return
*
this
;
}
fast_oss
(
fast_oss
&&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
std
::
move
(
other
.
_dev
))
{}
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
=
delete
;
const
std
::
string
&
str_ref
()
const
{
return
_dev
.
str_ref
();
...
...
include/c11log/details/line_logger.h
View file @
bf75bfd9
...
...
@@ -2,7 +2,7 @@
#include "../common_types.h"
#include "../logger.h"
#include
"fast_oss.h"
#include
<iostream>
namespace
c11log
{
class
logger
;
...
...
@@ -10,41 +10,49 @@ namespace details {
class
line_logger
{
public
:
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
)
:
line_logger
(
logger
*
callback_logger
,
level
::
level_enum
msg_level
,
bool
enabled
)
:
_callback_logger
(
callback_logger
),
_oss
(),
_level
(
msg_level
)
{
_level
(
msg_level
),
_enabled
(
enabled
)
{
callback_logger
->
_formatter
->
format_header
(
callback_logger
->
_logger_name
,
msg_level
,
log_clock
::
now
(),
_oss
);
}
line_logger
(
logger
*
)
:
_callback_logger
(
nullptr
)
{};
line_logger
(
const
line_logger
&
other
)
:
// No copy intended. Only move
line_logger
(
const
line_logger
&
other
)
=
delete
;
line_logger
(
line_logger
&&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
_oss
(
other
.
_oss
),
_level
(
other
.
_level
)
{};
_oss
(
std
::
move
(
other
.
_oss
)),
_level
(
other
.
_level
)
{
};
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
line_logger
&
operator
=
(
line_logger
&&
)
=
delete
;
~
line_logger
()
{
if
(
_
callback_logger
)
{
if
(
_
enabled
)
{
_oss
<<
'\n'
;
_callback_logger
->
_log_it
(
_oss
.
str
_ref
()
);
_callback_logger
->
_log_it
(
_oss
.
str
(),
_level
);
}
}
template
<
typename
T
>
line_logger
&
operator
<<
(
const
T
&
msg
)
{
if
(
_
callback_logger
)
if
(
_
enabled
)
_oss
<<
msg
;
return
*
this
;
}
private
:
logger
*
_callback_logger
;
details
::
fast_oss
_oss
;
std
::
ostringstream
_oss
;
level
::
level_enum
_level
;
bool
_enabled
;
};
}
//Namespace details
...
...
include/c11log/formatter.h
View file @
bf75bfd9
include/c11log/logger.h
View file @
bf75bfd9
...
...
@@ -66,7 +66,7 @@ private:
std
::
mutex
_mutex
;
std
::
atomic_int
_atomic_level
;
void
_log_it
(
const
std
::
string
&
msg
);
void
_log_it
(
const
std
::
string
&
msg
,
const
level
::
level_enum
level
);
};
...
...
@@ -85,11 +85,7 @@ logger& get_logger(const std::string& name);
#include "details/line_logger.h"
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
{
if
(
msg_level
>=
_atomic_level
)
return
details
::
line_logger
(
this
,
msg_level
);
else
return
details
::
line_logger
(
nullptr
);
return
details
::
line_logger
(
this
,
msg_level
,
msg_level
>=
_atomic_level
);
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
...
...
@@ -157,9 +153,8 @@ 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
)
inline
void
c11log
::
logger
::
_log_it
(
const
std
::
string
&
msg
,
const
level
::
level_enum
level
)
{
level
::
level_enum
level
=
static_cast
<
level
::
level_enum
>
(
_atomic_level
.
load
());
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
for
(
auto
&
sink
:
_sinks
)
sink
->
log
(
msg
,
level
);
...
...
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