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
a287bccd
Commit
a287bccd
authored
Mar 22, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
var names and some minor cleanups
parent
8494590f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
23 additions
and
47 deletions
+23
-47
example.cpp
example/example.cpp
+5
-6
fast_buf.h
include/c11log/details/fast_buf.h
+2
-5
fast_oss.h
include/c11log/details/fast_oss.h
+5
-26
line_logger.h
include/c11log/details/line_logger.h
+5
-4
logger.h
include/c11log/logger.h
+6
-6
No files found.
example/example.cpp
View file @
a287bccd
// example.cpp : Simple logger example
//
#include <string>
#include <functional>
#include "c11log/logger.h"
#include "c11log/sinks/async_sink.h"
#include "c11log/sinks/file_sinks.h"
#include "c11log/sinks/console_sinks.h"
#include "c11log/details/log_msg.h"
#include "utils.h"
...
...
@@ -16,24 +14,25 @@ using namespace std::chrono;
using
namespace
c11log
;
using
namespace
utils
;
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
||
argv
)
{};
const
unsigned
int
howmany
=
1000000
;
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink
>
(
"log"
,
"txt"
,
1024
*
1024
*
50
,
5
,
0
);
//auto fsink = std::make_shared<sinks::simple_file_sink>("simplelog", "txt");
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
logger
cout_logger
(
"cout"
,
{
null_sink
,
sinks
::
stdout_sink
()});
cout_logger
.
info
()
<<
"Hello cout logger!"
;
cout_logger
.
info
()
<<
"Hello cout logger!"
;
logger
my_logger
(
"my_logger"
,
{
null_sink
});
std
::
string
s
(
100
,
'0'
);
const
unsigned
int
howmany
=
5000000
;
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
s
;
...
...
include/c11log/details/fast_buf.h
View file @
a287bccd
...
...
@@ -5,14 +5,11 @@
#include <cstring>
#include <vector>
// Fast
buffer
// Fast
memory storage
// stores its contents on the stack when possible, in vector<char> otherwise
// NOTE: User should be remember that returned buffer might be on the stack!!
namespace
c11log
{
namespace
details
{
namespace
c11log
{
namespace
details
{
template
<
std
::
size_t
STACK_SIZE
=
128
>
class
fast_buf
...
...
include/c11log/details/fast_oss.h
View file @
a287bccd
#pragma once
// Faster than ostringstream--returns its string by ref
#include <ostream>
#include "c11log/details/fast_buf.h"
namespace
c11log
...
...
@@ -19,21 +19,14 @@ public:
str_devicebuf
(
str_devicebuf
&&
other
)
=
delete
;
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();
{
_fastbuf
.
clear
();
}
...
...
@@ -46,21 +39,13 @@ protected:
// copy the give buffer into the accumulated string.
// 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
;
}
int_type
overflow
(
int_type
ch
)
override
{
bool
not_eofile
=
traits_type
::
not_eof
(
ch
);
if
(
not_eofile
)
{
...
...
@@ -70,7 +55,6 @@ protected:
return
not_eofile
;
}
private
:
//std::string _str;
fast_buf
<
192
>
_fastbuf
;
};
...
...
@@ -83,12 +67,7 @@ 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
();
...
...
include/c11log/details/line_logger.h
View file @
a287bccd
...
...
@@ -38,12 +38,13 @@ public:
line_logger
&
operator
=
(
const
line_logger
&
)
=
delete
;
line_logger
&
operator
=
(
line_logger
&&
)
=
delete
;
// The move ctor should only be called on start of logging line,
// where no logging happened yet for this line so no need to copy the string from the other
line_logger
(
line_logger
&&
other
)
:
_callback_logger
(
other
.
_callback_logger
),
// The move ctor should only be called on start of logging line,
// where no logging happened yet for this line so no need to copy the string from the other
_callback_logger
(
other
.
_callback_logger
),
_oss
(),
_level
(
other
.
_level
)
{};
_level
(
other
.
_level
),
_enabled
(
other
.
_enabled
)
{}
~
line_logger
()
...
...
include/c11log/logger.h
View file @
a287bccd
...
...
@@ -67,7 +67,7 @@ private:
std
::
string
_logger_name
=
""
;
formatter_ptr
_formatter
;
sinks_vector_t
_sinks
;
std
::
atomic_int
_
atomic
_level
;
std
::
atomic_int
_
logger
_level
;
void
_log_it
(
const
bufpair_t
&
buf
,
const
level
::
level_enum
level
);
...
...
@@ -91,7 +91,7 @@ inline c11log::logger::logger(const std::string& name, formatter_ptr f, sinks_in
_sinks
(
sinks_list
)
{
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
_
atomic
_level
=
level
::
INFO
;
_
logger
_level
=
level
::
INFO
;
}
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
name
,
sinks_init_list
sinks_list
)
:
...
...
@@ -103,7 +103,7 @@ inline c11log::logger::logger(sinks_init_list sinks_list) :
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
);
return
details
::
line_logger
(
this
,
msg_level
,
msg_level
>=
_
logger
_level
);
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
...
...
@@ -136,17 +136,17 @@ inline const std::string& c11log::logger::get_name() const
inline
void
c11log
::
logger
::
set_level
(
c11log
::
level
::
level_enum
level
)
{
_
atomic
_level
.
store
(
level
);
_
logger
_level
.
store
(
level
);
}
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
get_level
()
const
{
return
static_cast
<
c11log
::
level
::
level_enum
>
(
_
atomic
_level
.
load
());
return
static_cast
<
c11log
::
level
::
level_enum
>
(
_
logger
_level
.
load
());
}
inline
bool
c11log
::
logger
::
should_log
(
c11log
::
level
::
level_enum
level
)
const
{
return
level
>=
_
atomic
_level
.
load
();
return
level
>=
_
logger
_level
.
load
();
}
inline
void
c11log
::
logger
::
_log_it
(
const
bufpair_t
&
buf
,
const
level
::
level_enum
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