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
9e1ba516
Commit
9e1ba516
authored
Mar 30, 2014
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nice logger api improvement
parent
ff824cdb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
53 additions
and
35 deletions
+53
-35
example.cpp
example/example.cpp
+6
-5
line_logger.h
include/c11log/details/line_logger.h
+10
-2
logger.h
include/c11log/logger.h
+37
-28
No files found.
example/example.cpp
View file @
9e1ba516
...
...
@@ -21,7 +21,8 @@ int main(int argc, char* argv[])
const
unsigned
int
howmany
=
argc
<=
1
?
1000000
:
atoi
(
argv
[
1
]);
logger
cout_logger
(
""
,
sinks
::
stdout_sink
());
cout_logger
.
info
()
<<
"Hello "
<<
"man"
;
cout_logger
.
info
(
"Hello "
)
<<
"man"
<<
123
<<
" : "
<<
0.45
f
;
cout_logger
.
info
(
"This is very nice! "
)
<<
"Yes gabi.."
<<
":)"
;
auto
fsink
=
std
::
make_shared
<
sinks
::
rotating_file_sink
>
(
"log"
,
"txt"
,
1024
*
1024
*
50
,
5
,
0
);
auto
nullsink
=
sinks
::
null_sink
::
get
();
...
...
@@ -32,16 +33,16 @@ int main(int argc, char* argv[])
auto
start
=
system_clock
::
now
();
for
(
unsigned
int
i
=
1
;
i
<=
howmany
;
++
i
)
my_logger
.
info
(
)
<<
"Hello logger: "
;
my_logger
.
info
(
"Hello logger: "
)
;
//auto s = howmany - as->q().size();
auto
s
=
howmany
;
auto
delta
=
system_clock
::
now
()
-
start
;
auto
delta_d
=
duration_cast
<
duration
<
double
>>
(
delta
).
count
();
cout_logger
.
info
(
)
<<
"Total:"
<<
format
(
s
);
cout_logger
.
info
(
)
<<
"Delta:"
<<
format
(
delta_d
);
cout_logger
.
info
(
)
<<
"Rate:"
<<
format
(
s
/
delta_d
)
<<
"/sec"
;
cout_logger
.
info
(
"Total:"
)
<<
format
(
s
);
cout_logger
.
info
(
"Delta:"
)
<<
format
(
delta_d
);
cout_logger
.
info
(
"Rate:"
)
<<
format
(
s
/
delta_d
)
<<
"/sec"
;
return
0
;
}
include/c11log/details/line_logger.h
View file @
9e1ba516
...
...
@@ -58,17 +58,25 @@ public:
}
}
template
<
typename
T
>
line_logger
&
operator
<<
(
const
T
&
what
)
template
<
typename
T
>
void
write
(
const
T
&
what
)
{
if
(
_enabled
)
{
_oss
<<
what
;
_empty
=
false
;
}
}
template
<
typename
T
>
line_logger
&
operator
<<
(
const
T
&
what
)
{
write
(
what
);
return
*
this
;
}
private
:
logger
*
_callback_logger
;
log_msg
_log_msg
;
...
...
include/c11log/logger.h
View file @
9e1ba516
...
...
@@ -49,15 +49,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
critical
();
details
::
line_logger
fatal
();
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
;
...
...
@@ -71,6 +70,8 @@ private:
};
//Get from loggers pool if exists with such name
logger
&
get_logger
(
const
std
::
string
&
name
);
}
...
...
@@ -97,39 +98,47 @@ inline c11log::logger::logger(const std::string& name, sink_ptr sink, formatter_
logger
(
name
,
{
sink
},
f
)
{}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
log
(
c11log
::
level
::
level_enum
msg_level
)
{
return
details
::
line_logger
(
this
,
msg_level
,
msg_level
>=
_min_level
);
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
debug
(
const
T
&
msg
)
{
return
details
::
line_logger
(
this
,
level
::
DEBUG
,
should_log
(
level
::
DEBUG
));
details
::
line_logger
l
(
this
,
level
::
DEBUG
,
should_log
(
level
::
DEBUG
));
l
.
write
(
msg
);
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
()
{
return
details
::
line_logger
(
this
,
level
::
INFO
,
should_log
(
level
::
INFO
));
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
info
(
const
T
&
msg
)
{
return
details
::
line_logger
(
this
,
level
::
WARNING
,
should_log
(
level
::
WARNING
));
details
::
line_logger
l
(
this
,
level
::
INFO
,
should_log
(
level
::
INFO
));
l
.
write
(
msg
);
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
error
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
warn
(
const
T
&
msg
)
{
return
details
::
line_logger
(
this
,
level
::
ERROR
,
should_log
(
level
::
ERROR
));
details
::
line_logger
l
(
this
,
level
::
WARNING
,
should_log
(
level
::
WARNING
));
l
.
write
(
msg
);
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
critical
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
critical
(
const
T
&
msg
)
{
return
details
::
line_logger
(
this
,
level
::
CRITICAL
,
should_log
(
level
::
CRITICAL
));
details
::
line_logger
l
(
this
,
level
::
CRITICAL
,
should_log
(
level
::
CRITICAL
));
l
.
write
(
msg
);
return
l
;
}
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
()
template
<
typename
T
>
inline
c11log
::
details
::
line_logger
c11log
::
logger
::
fatal
(
const
T
&
msg
)
{
return
details
::
line_logger
(
this
,
level
::
FATAL
,
should_log
(
level
::
FATAL
));
details
::
line_logger
l
(
this
,
level
::
FATAL
,
should_log
(
level
::
FATAL
));
l
.
write
(
msg
);
return
l
;
}
inline
const
std
::
string
&
c11log
::
logger
::
get_name
()
const
{
return
_logger_name
;
...
...
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