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
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
47 deletions
+53
-47
example.cpp
example/example.cpp
+4
-3
fast_oss.h
include/c11log/details/fast_oss.h
+12
-10
line_logger.h
include/c11log/details/line_logger.h
+19
-11
formatter.h
include/c11log/formatter.h
+15
-15
logger.h
include/c11log/logger.h
+3
-8
No files found.
example/example.cpp
View file @
bf75bfd9
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
//
//
#include <string>
#include <string>
#include <functional>
#include <functional>
#include <iomanip>
#include "c11log/logger.h"
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/file_sinks.h"
...
@@ -60,10 +59,12 @@ int main(int argc, char* argv[])
...
@@ -60,10 +59,12 @@ int main(int argc, char* argv[])
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
//auto async = std::make_shared<sinks::async_sink>(1000);
//auto async = std::make_shared<sinks::async_sink>(1000);
//async->add_sink(fsink);
//async->add_sink(fsink);
my_logger
.
add_sink
(
fsink
);
my_logger
.
add_sink
(
null_sink
);
auto
start
=
system_clock
::
now
();
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
++
)
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
...
...
include/c11log/details/fast_oss.h
View file @
bf75bfd9
...
@@ -10,12 +10,15 @@ public:
...
@@ -10,12 +10,15 @@ public:
str_devicebuf
()
=
default
;
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
~
str_devicebuf
()
=
default
;
str_devicebuf
(
const
str_devicebuf
&
other
)
:
std
::
streambuf
(),
_str
(
other
.
_str
)
{}
str_devicebuf
(
const
str_devicebuf
&
other
)
:
std
::
streambuf
(),
_str
(
other
.
_str
)
{}
str_devicebuf
&
operator
=
(
const
str_devicebuf
other
)
{
if
(
this
!=
&
other
)
str_devicebuf
(
str_devicebuf
&&
other
)
:
std
::
streambuf
(),
_str
(
std
::
move
(
other
.
_str
))
{
_str
=
other
.
_str
;
other
.
_str
.
clear
();
return
*
this
;
}
}
str_devicebuf
&
operator
=
(
const
str_devicebuf
&
)
=
delete
;
str_devicebuf
&
operator
=
(
str_devicebuf
&&
)
=
delete
;
const
std
::
string
&
str_ref
()
const
{
const
std
::
string
&
str_ref
()
const
{
return
_str
;
return
_str
;
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
...
@@ -50,12 +53,11 @@ public:
...
@@ -50,12 +53,11 @@ public:
~
fast_oss
()
=
default
;
~
fast_oss
()
=
default
;
fast_oss
(
const
fast_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
other
.
_dev
)
{}
fast_oss
(
const
fast_oss
&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
other
.
_dev
)
{}
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
{
fast_oss
(
fast_oss
&&
other
)
:
std
::
basic_ios
<
char
>
(),
std
::
ostream
(
&
_dev
),
_dev
(
std
::
move
(
other
.
_dev
))
{}
if
(
&
other
!=
this
)
_dev
=
other
.
_dev
;
fast_oss
&
operator
=
(
const
fast_oss
&
other
)
=
delete
;
return
*
this
;
}
const
std
::
string
&
str_ref
()
const
{
const
std
::
string
&
str_ref
()
const
{
return
_dev
.
str_ref
();
return
_dev
.
str_ref
();
...
...
include/c11log/details/line_logger.h
View file @
bf75bfd9
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "../common_types.h"
#include "../common_types.h"
#include "../logger.h"
#include "../logger.h"
#include
"fast_oss.h"
#include
<iostream>
namespace
c11log
{
namespace
c11log
{
class
logger
;
class
logger
;
...
@@ -10,41 +10,49 @@ namespace details {
...
@@ -10,41 +10,49 @@ namespace details {
class
line_logger
{
class
line_logger
{
public
:
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
),
_callback_logger
(
callback_logger
),
_oss
(),
_oss
(),
_level
(
msg_level
)
{
_level
(
msg_level
),
_enabled
(
enabled
)
{
callback_logger
->
_formatter
->
format_header
(
callback_logger
->
_logger_name
,
callback_logger
->
_formatter
->
format_header
(
callback_logger
->
_logger_name
,
msg_level
,
msg_level
,
log_clock
::
now
(),
log_clock
::
now
(),
_oss
);
_oss
);
}
}
line_logger
(
logger
*
)
:
_callback_logger
(
nullptr
)
{};
// No copy intended. Only move
line_logger
(
const
line_logger
&
other
)
:
line_logger
(
const
line_logger
&
other
)
=
delete
;
line_logger
(
line_logger
&&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
_callback_logger
(
other
.
_callback_logger
),
_oss
(
other
.
_oss
),
_oss
(
std
::
move
(
other
.
_oss
)),
_level
(
other
.
_level
)
{};
_level
(
other
.
_level
)
{
};
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
line_logger
&
operator
=
(
line_logger
&&
)
=
delete
;
~
line_logger
()
{
~
line_logger
()
{
if
(
_
callback_logger
)
{
if
(
_
enabled
)
{
_oss
<<
'\n'
;
_oss
<<
'\n'
;
_callback_logger
->
_log_it
(
_oss
.
str
_ref
()
);
_callback_logger
->
_log_it
(
_oss
.
str
(),
_level
);
}
}
}
}
template
<
typename
T
>
template
<
typename
T
>
line_logger
&
operator
<<
(
const
T
&
msg
)
{
line_logger
&
operator
<<
(
const
T
&
msg
)
{
if
(
_
callback_logger
)
if
(
_
enabled
)
_oss
<<
msg
;
_oss
<<
msg
;
return
*
this
;
return
*
this
;
}
}
private
:
private
:
logger
*
_callback_logger
;
logger
*
_callback_logger
;
details
::
fast_oss
_oss
;
std
::
ostringstream
_oss
;
level
::
level_enum
_level
;
level
::
level_enum
_level
;
bool
_enabled
;
};
};
}
//Namespace details
}
//Namespace details
...
...
include/c11log/formatter.h
View file @
bf75bfd9
...
@@ -49,29 +49,29 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
...
@@ -49,29 +49,29 @@ inline void c11log::formatters::default_formatter::_format_time(const log_clock:
__declspec
(
thread
)
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
__declspec
(
thread
)
static
char
last_time_str
[
64
];
__declspec
(
thread
)
static
char
last_time_str
[
64
];
#else
#else
thread_local
static
std
::
tm
last_tm
=
{
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
};
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
];
thread_local
static
char
last_time_str
[
64
];
#endif
#endif
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
auto
tm_now
=
details
::
os
::
localtime
(
log_clock
::
to_time_t
(
tp
));
using
namespace
c11log
::
details
::
os
;
using
namespace
c11log
::
details
::
os
;
if
(
last_tm
!=
tm_now
)
if
(
last_tm
!=
tm_now
)
{
{
#ifdef _MSC_VER
#ifdef _MSC_VER
::
sprintf_s
::
sprintf_s
#else
#else
::
snprintf
::
snprintf
#endif
#endif
(
last_time_str
,
sizeof
(
last_time_str
),
"[%d-%02d-%02d %02d:%02d:%02d]"
,
(
last_time_str
,
sizeof
(
last_time_str
),
"[%d-%02d-%02d %02d:%02d:%02d]"
,
tm_now
.
tm_year
+
1900
,
tm_now
.
tm_year
+
1900
,
tm_now
.
tm_mon
+
1
,
tm_now
.
tm_mon
+
1
,
tm_now
.
tm_mday
,
tm_now
.
tm_mday
,
tm_now
.
tm_hour
,
tm_now
.
tm_hour
,
tm_now
.
tm_min
,
tm_now
.
tm_min
,
tm_now
.
tm_sec
);
tm_now
.
tm_sec
);
last_tm
=
tm_now
;
last_tm
=
tm_now
;
}
}
dest
<<
last_time_str
;
dest
<<
last_time_str
;
}
}
include/c11log/logger.h
View file @
bf75bfd9
...
@@ -66,7 +66,7 @@ private:
...
@@ -66,7 +66,7 @@ private:
std
::
mutex
_mutex
;
std
::
mutex
_mutex
;
std
::
atomic_int
_atomic_level
;
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);
...
@@ -85,11 +85,7 @@ logger& get_logger(const std::string& name);
#include "details/line_logger.h"
#include "details/line_logger.h"
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
{
{
return
details
::
line_logger
(
this
,
msg_level
,
msg_level
>=
_atomic_level
);
if
(
msg_level
>=
_atomic_level
)
return
details
::
line_logger
(
this
,
msg_level
);
else
return
details
::
line_logger
(
nullptr
);
}
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
...
@@ -157,9 +153,8 @@ inline bool c11log::logger::should_log(c11log::level::level_enum level) const
...
@@ -157,9 +153,8 @@ inline bool c11log::logger::should_log(c11log::level::level_enum level) const
{
{
return
level
>=
_atomic_level
.
load
();
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
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
for
(
auto
&
sink
:
_sinks
)
for
(
auto
&
sink
:
_sinks
)
sink
->
log
(
msg
,
level
);
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