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
9d687d16
Commit
9d687d16
authored
Mar 08, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixes
parent
a6d1ea77
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
52 additions
and
55 deletions
+52
-55
example.cpp
example/example.cpp
+8
-17
factory.h
include/c11log/details/factory.h
+12
-12
formatter.h
include/c11log/formatter.h
+4
-4
logger.h
include/c11log/logger.h
+28
-22
No files found.
example/example.cpp
View file @
9d687d16
...
...
@@ -20,29 +20,20 @@ int main(int argc, char* argv[])
{
if
(
argc
||
argv
)
{};
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink
>
(
"log"
,
"txt"
,
1024
*
1024
*
50
,
5
,
seconds
(
1
));
//auto &my_logger = get_logger("example");
//auto fsink = std::make_shared<sinks::rotating_file_sink>("log", "txt", 1024*1024*50 , 5, seconds(1));
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
//auto async = std::make_shared<sinks::async_sink>(1000);
//my_logger.add_sink(fsink);
//my_logger.add_sink(null_sink);
logger
cout_logger
(
"cout"
,
{
null_sink
,
sinks
::
stdout_sink
(),
fsink
});
logger
cout_logger
(
"cout"
,
{
null_sink
,
sinks
::
stdout_sink
()});
cout_logger
.
info
()
<<
"Hello cout logger!"
;
logger
log2
{
sinks
::
stdout_sink
()};
log2
.
error
()
<<
"Cool shit"
<<
"!!!"
;
return
0
;
/*
logger
my_logger
(
"my_logger"
,
{
null_sink
});
auto
start
=
system_clock
::
now
();
const unsigned int howmany =
5
000000;
const
unsigned
int
howmany
=
10
000000
;
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
()
<<
"Hello logger "
<<
i
;
...
...
@@ -55,7 +46,7 @@ int main(int argc, char* argv[])
return
0
;
*/
/*
if(argc !=3) {
std::cerr << "Usage: " << argv[0] << " qsize, threads" << std::endl;
...
...
include/c11log/details/factory.h
View file @
9d687d16
...
...
@@ -15,11 +15,11 @@ class factory
public
:
using
logger_ptr
=
std
::
shared_ptr
<
c11log
::
logger
>
;
using
logger_map
=
std
::
unordered_map
<
std
::
string
,
logger_ptr
>
;
void
add_logger
(
const
std
::
string
&
name
,
logger_ptr
);
logger_ptr
get_logger
(
const
std
::
string
&
name
);
void
add_logger
(
const
std
::
string
&
name
,
logger_ptr
);
logger_ptr
get_logger
(
const
std
::
string
&
name
);
static
c11log
::
details
::
factory
&
instance
();
private
:
std
::
mutex
_loggers_mutex
;
std
::
mutex
_loggers_mutex
;
logger_map
_loggers
;
};
...
...
@@ -29,21 +29,21 @@ private:
inline
void
c11log
::
details
::
factory
::
add_logger
(
const
std
::
string
&
name
,
logger_ptr
logger_p
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_loggers_mutex
);
_loggers
.
insert
(
logger_map
::
value_type
(
name
,
logger_p
));
std
::
lock_guard
<
std
::
mutex
>
lock
(
_loggers_mutex
);
_loggers
.
insert
(
logger_map
::
value_type
(
name
,
logger_p
));
}
inline
c11log
::
details
::
factory
::
logger_ptr
c11log
::
details
::
factory
::
get_logger
(
const
std
::
string
&
name
)
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
_loggers_mutex
);
auto
found
=
_loggers
.
find
(
name
);
if
(
found
!=
_loggers
.
end
())
return
found
->
second
;
else
return
logger_ptr
(
nullptr
);
/*
auto found = _loggers.find(name);
auto
found
=
_loggers
.
find
(
name
);
if
(
found
!=
_loggers
.
end
())
return
found
->
second
;
else
return
logger_ptr
(
nullptr
);
/*
auto found = _loggers.find(name);
if (found == _loggers.end()) {
auto new_logger_ptr = std::make_shared<c11log::logger>(name);
...
...
include/c11log/formatter.h
View file @
9d687d16
...
...
@@ -33,10 +33,10 @@ public:
// Format: [2013-12-29 01:04:42.900] [logger_name:Info] Message body
void
format_header
(
const
std
::
string
&
logger_name
,
level
::
level_enum
level
,
const
log_clock
::
time_point
&
tp
,
std
::
ostream
&
dest
)
override
{
_format_time
(
tp
,
dest
);
if
(
!
logger_name
.
empty
())
dest
<<
" ["
<<
logger_name
<<
":"
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
else
dest
<<
" ["
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
if
(
!
logger_name
.
empty
())
dest
<<
" ["
<<
logger_name
<<
":"
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
else
dest
<<
" ["
<<
c11log
::
level
::
to_str
(
level
)
<<
"] "
;
}
private
:
...
...
include/c11log/logger.h
View file @
9d687d16
...
...
@@ -29,34 +29,22 @@ class logger
public
:
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
base_sink
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
c11log
::
formatters
::
formatter
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
c11log
::
formatters
::
formatter
>
;
using
sinks_vector_t
=
std
::
vector
<
sink_ptr
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
logger
(
const
std
::
string
&
name
,
formatter_ptr
f
,
sinks_init_list
sinks_list
);
logger
(
const
std
::
string
&
name
,
sinks_init_list
sinks_list
);
logger
(
sinks_init_list
sinks_list
);
logger
(
const
std
::
string
&
name
,
formatter_ptr
f
,
sinks_init_list
sinks_list
)
:
_logger_name
(
name
),
_formatter
(
f
),
_sinks
(
sinks_list
)
{
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
_atomic_level
=
level
::
INFO
;
}
logger
(
const
std
::
string
&
name
,
sinks_init_list
sinks_list
)
:
logger
(
name
,
std
::
make_shared
<
formatters
::
default_formatter
>
(),
sinks_list
)
{}
logger
(
sinks_init_list
sinks_list
)
:
logger
(
""
,
std
::
make_shared
<
formatters
::
default_formatter
>
(),
sinks_list
)
{}
~
logger
()
=
default
;
//Non copybale in anyway
//Non copybale in anyway
logger
(
const
logger
&
)
=
delete
;
logger
(
logger
&&
)
=
delete
;
logger
(
logger
&&
)
=
delete
;
logger
&
operator
=
(
const
logger
&
)
=
delete
;
logger
&
operator
=
(
logger
&&
)
=
delete
;
logger
&
operator
=
(
logger
&&
)
=
delete
;
void
set_level
(
c11log
::
level
::
level_enum
);
c11log
::
level
::
level_enum
get_level
()
const
;
...
...
@@ -89,9 +77,27 @@ logger& get_logger(const std::string& name);
//
// Logger inline impl
// Logger inline impl
ementation
//
#include "details/line_logger.h"
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
name
,
formatter_ptr
f
,
sinks_init_list
sinks_list
)
:
_logger_name
(
name
),
_formatter
(
f
),
_sinks
(
sinks_list
)
{
//Seems that vs2013 doesnt support atomic member initialization in ctor, so its done here
_atomic_level
=
level
::
INFO
;
}
inline
c11log
::
logger
::
logger
(
const
std
::
string
&
name
,
sinks_init_list
sinks_list
)
:
logger
(
name
,
std
::
make_shared
<
formatters
::
default_formatter
>
(),
sinks_list
)
{}
inline
c11log
::
logger
::
logger
(
sinks_init_list
sinks_list
)
:
logger
(
""
,
std
::
make_shared
<
formatters
::
default_formatter
>
(),
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
);
...
...
@@ -131,7 +137,7 @@ inline void c11log::logger::set_level(c11log::level::level_enum level)
}
inline
c11log
::
level
::
level_enum
c11log
::
logger
::
get_level
()
const
{
{
return
static_cast
<
c11log
::
level
::
level_enum
>
(
_atomic_level
.
load
());
}
...
...
@@ -140,7 +146,7 @@ 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
)
{
{
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