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
1c4be7fb
Commit
1c4be7fb
authored
Mar 28, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logger templates
parent
c09df09b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
74 additions
and
35 deletions
+74
-35
example.cpp
example/example.cpp
+6
-8
common_types.h
include/c11log/common_types.h
+2
-1
line_logger.h
include/c11log/details/line_logger.h
+3
-9
logger.h
include/c11log/logger.h
+62
-17
async_sink.h
include/c11log/sinks/async_sink.h
+1
-0
No files found.
example/example.cpp
View file @
1c4be7fb
...
...
@@ -19,28 +19,26 @@ int main(int argc, char* argv[])
{
if
(
argc
||
argv
)
{};
const
unsigned
int
howmany
=
argc
<=
1
?
1
500
000
:
atoi
(
argv
[
1
]);
const
unsigned
int
howmany
=
argc
<=
1
?
1000
:
atoi
(
argv
[
1
]);
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink
>
(
"log"
,
"txt"
,
1024
*
1024
*
50
,
5
,
0
);
auto
null_sink
=
std
::
make_shared
<
sinks
::
null_sink
>
();
logger
cout_logger
(
"cout"
,
{
sinks
::
stdout_sink
()});
cout_logger
.
info
()
<<
"Hello cout logger!"
;
logger
my_logger
(
"my_logger"
,
{
null_sink
});
std
::
string
s
(
100
,
'0'
);
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
0
;
i
<
howmany
;
i
++
)
my_logger
.
info
(
)
<<
s
;
my_logger
.
info
(
"Hello logger"
)
;
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout_logger
.
info
(
)
<<
"Total "
<<
format
(
howmany
);
cout_logger
.
info
(
)
<<
"Delta "
<<
format
(
delta_d
);
cout_logger
.
info
(
)
<<
"Rate: "
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
;
cout_logger
.
info
(
"Total "
)
<<
format
(
howmany
);
cout_logger
.
info
(
"Delta "
)
<<
format
(
delta_d
);
cout_logger
.
info
(
"Rate: "
)
<<
format
(
howmany
/
delta_d
)
<<
"/sec"
;
return
0
;
...
...
include/c11log/common_types.h
View file @
1c4be7fb
...
...
@@ -16,11 +16,12 @@ typedef enum
INFO
,
WARNING
,
ERROR
,
CRITICAL
,
FATAL
,
NONE
=
99
}
level_enum
;
static
const
char
*
level_names
[]
{
"debug"
,
"info"
,
"warning"
,
"error"
,
"fatal"
};
static
const
char
*
level_names
[]
{
"debug"
,
"info"
,
"warning"
,
"error"
,
"
critical"
,
"
fatal"
};
inline
const
char
*
to_str
(
c11log
::
level
::
level_enum
l
)
{
return
level_names
[
l
];
...
...
include/c11log/details/line_logger.h
View file @
1c4be7fb
...
...
@@ -8,7 +8,6 @@
// line logger class. should be used by the logger as an rvalue only.
// aggregates logging string until the end of the line and then calls the logger upon destruction
namespace
c11log
{
//class logger;
...
...
@@ -49,7 +48,6 @@ public:
_oss
(),
_enabled
(
other
.
_enabled
)
{}
~
line_logger
()
{
if
(
_enabled
)
...
...
@@ -59,15 +57,13 @@ public:
_callback_logger
->
_log_it
(
_log_msg
);
}
}
template
<
typename
T
>
line_logger
&
&
operator
<<
(
const
T
&
what
)
line_logger
&
operator
<<
(
const
T
&
what
)
{
if
(
_enabled
)
_oss
<<
what
;
return
std
::
move
(
*
this
);
return
*
this
;
}
private
:
...
...
@@ -75,8 +71,6 @@ private:
log_msg
_log_msg
;
details
::
stack_oss
_oss
;
bool
_enabled
;
};
}
//Namespace details
}
// Namespace c11log
include/c11log/logger.h
View file @
1c4be7fb
...
...
@@ -53,12 +53,14 @@ public:
const
std
::
string
&
get_name
()
const
;
bool
should_log
(
c11log
::
level
::
level_enum
)
const
;
details
::
line_logger
log
(
level
::
level_enum
);
details
::
line_logger
debug
();
details
::
line_logger
info
();
details
::
line_logger
warn
();
details
::
line_logger
error
();
details
::
line_logger
fatal
();
details
::
line_logger
log
(
c11log
::
level
::
level_enum
);
template
<
typename
T
>
details
::
line_logger
debug
(
const
T
&
);
template
<
typename
T
>
details
::
line_logger
info
(
const
T
&
);
template
<
typename
T
>
details
::
line_logger
warn
(
const
T
&
);
template
<
typename
T
>
details
::
line_logger
error
(
const
T
&
);
template
<
typename
T
>
details
::
line_logger
critical
(
const
T
&
);
template
<
typename
T
>
details
::
line_logger
fatal
(
const
T
&
);
private
:
friend
details
::
line_logger
;
...
...
@@ -103,34 +105,77 @@ inline c11log::details::line_logger c11log::logger::log(c11log::level::level_enu
return
details
::
line_logger
(
this
,
msg_level
,
msg_level
>=
_logger_level
);
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
(
const
T
&
what
)
{
return
log
(
c11log
::
level
::
DEBUG
);
bool
really_log
=
should_log
(
level
::
DEBUG
);
details
::
line_logger
l
(
this
,
level
::
DEBUG
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
(
const
T
&
what
)
{
bool
really_log
=
should_log
(
level
::
INFO
);
details
::
line_logger
l
(
this
,
level
::
INFO
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
(
const
T
&
what
)
{
return
log
(
c11log
::
level
::
INFO
);
bool
really_log
=
should_log
(
level
::
WARNING
);
details
::
line_logger
l
(
this
,
level
::
WARNING
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
error
(
const
T
&
what
)
{
return
log
(
c11log
::
level
::
WARNING
);
bool
really_log
=
should_log
(
level
::
ERROR
);
details
::
line_logger
l
(
this
,
level
::
ERROR
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
error
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
critical
(
const
T
&
what
)
{
return
log
(
level
::
ERROR
);
bool
really_log
=
should_log
(
level
::
CRITICAL
);
details
::
line_logger
l
(
this
,
level
::
CRITICAL
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
(
const
T
&
what
)
{
return
log
(
c11log
::
level
::
FATAL
);
bool
really_log
=
should_log
(
level
::
FATAL
);
details
::
line_logger
l
(
this
,
level
::
FATAL
,
really_log
);
if
(
really_log
)
l
<<
what
;
return
l
;
}
inline
const
std
::
string
&
c11log
::
logger
::
get_name
()
const
{
return
_logger_name
;
}
inline
void
c11log
::
logger
::
set_level
(
c11log
::
level
::
level_enum
level
)
{
_logger_level
.
store
(
level
);
...
...
include/c11log/sinks/async_sink.h
View file @
1c4be7fb
...
...
@@ -74,6 +74,7 @@ inline void c11log::sinks::async_sink::_sink_it(const details::log_msg& msg)
auto
new_shared
=
std
::
shared_ptr
<
details
::
log_msg
>
(
new_msg
,
[](
details
::
log_msg
*
msg_to_delete
)
{
delete
[]
msg_to_delete
->
msg_buf
.
first
;
delete
msg_to_delete
;
});
_q
.
push
(
new_shared
);
}
...
...
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