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
59b4dd4c
Commit
59b4dd4c
authored
Mar 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
2f907e3a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
29 deletions
+38
-29
create_lite.cpp
lite-example/create_lite.cpp
+14
-9
example.cpp
lite-example/example.cpp
+1
-1
spdlite.h
lite/spdlite.h
+23
-19
No files found.
lite-example/create_lite.cpp
View file @
59b4dd4c
...
...
@@ -3,16 +3,21 @@
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#define UNUSED(x) (void)(x)
// example of creating lite logger with console and file sink
spdlog
::
lite
::
logger
spdlog
::
create_lite
(
void
*
ctx
)
{
if
(
ctx
)
{
//..
}
auto
logger_impl
=
spdlog
::
stdout_color_mt
(
"mylogger"
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
"file.txt"
,
true
);
file_sink
->
set_level
(
spdlog
::
level
::
info
);
logger_impl
->
sinks
().
push_back
(
file_sink
);
logger_impl
->
set_level
(
spdlog
::
level
::
trace
);
UNUSED
(
ctx
);
std
::
shared_ptr
<
spdlog
::
logger
>
logger_impl
;
auto
console_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
stdout_color_sink_mt
>
();
console_sink
->
set_level
(
spdlog
::
level
::
debug
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
"log.txt"
,
true
);
file_sink
->
set_level
(
spdlog
::
level
::
info
);
logger_impl
=
std
::
make_shared
<
spdlog
::
logger
>
(
"my-logger"
,
spdlog
::
sinks_init_list
{
console_sink
,
file_sink
});
logger_impl
->
set_level
(
spdlog
::
level
::
debug
);
return
spdlog
::
lite
::
logger
(
std
::
move
(
logger_impl
));
}
lite-example/example.cpp
View file @
59b4dd4c
...
...
@@ -2,7 +2,7 @@
int
main
()
{
auto
l
=
spdlog
::
create_lite
();
auto
l
=
spdlog
::
create_lite
(
(
void
*
)
"async"
);
l
.
set_level
(
spdlog
::
lite
::
level
::
trace
);
l
.
trace_f
(
"Hello %s "
,
"GABI"
);
...
...
lite/spdlite.h
View file @
59b4dd4c
...
...
@@ -43,10 +43,10 @@ public:
~
logger
()
=
default
;
bool
should_log
(
spdlog
::
lite
::
level
lvl
)
const
noexcept
;
bool
should_log
(
lite
::
level
lvl
)
const
noexcept
;
template
<
typename
...
Args
>
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
void
log
(
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
...
...
@@ -58,21 +58,21 @@ public:
}
// log string view
void
log
(
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log_printf
(
spdlog
::
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
);
void
log
(
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log_printf
(
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
);
//
// trace
//
void
trace
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
trace
,
string_view_t
(
msg
));
log
(
lite
::
level
::
trace
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
trace
,
fmt
,
args
...);
log
(
lite
::
level
::
trace
,
fmt
,
args
...);
}
void
trace_f
(
const
char
*
printf_format
,
...);
...
...
@@ -82,13 +82,13 @@ public:
//
void
debug
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
debug
,
string_view_t
(
msg
));
log
(
lite
::
level
::
debug
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
debug
,
fmt
,
args
...);
log
(
lite
::
level
::
debug
,
fmt
,
args
...);
}
void
debug_f
(
const
char
*
printf_format
,
...);
...
...
@@ -98,13 +98,13 @@ public:
//
void
info
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
info
,
string_view_t
(
msg
));
log
(
lite
::
level
::
info
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
info
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
info
,
fmt
,
args
...);
log
(
lite
::
level
::
info
,
fmt
,
args
...);
}
void
info_f
(
const
char
*
printf_format
,
...);
...
...
@@ -114,13 +114,13 @@ public:
//
void
warn
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
warn
,
string_view_t
(
msg
));
log
(
lite
::
level
::
warn
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
warn
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
warn
,
fmt
,
args
...);
log
(
lite
::
level
::
warn
,
fmt
,
args
...);
}
void
warn_f
(
const
char
*
printf_format
,
...);
...
...
@@ -130,13 +130,13 @@ public:
//
void
error
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
err
,
string_view_t
(
msg
));
log
(
lite
::
level
::
err
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
error
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
err
,
fmt
,
args
...);
log
(
lite
::
level
::
err
,
fmt
,
args
...);
}
void
error_f
(
const
char
*
printf_format
,
...);
...
...
@@ -146,13 +146,13 @@ public:
//
void
critical
(
const
char
*
msg
)
{
log
(
spdlog
::
lite
::
level
::
critical
,
string_view_t
(
msg
));
log
(
lite
::
level
::
critical
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
critical
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
level
::
critical
,
fmt
,
args
...);
log
(
lite
::
level
::
critical
,
fmt
,
args
...);
}
void
critical_f
(
const
char
*
printf_format
,
...);
...
...
@@ -168,13 +168,17 @@ public:
// flush
//
void
flush
();
void
flush_on
(
spdlog
::
lite
::
level
log_level
);
spdlog
::
lite
::
level
flush_level
()
const
;
void
flush_on
(
lite
::
level
log_level
);
lite
::
level
flush_level
()
const
;
//
// set pattern
//
void
set_pattern
(
std
::
string
pattern
);
protected
:
std
::
shared_ptr
<
spdlog
::
logger
>
impl_
;
void
log_formatted_
(
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
void
log_formatted_
(
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
};
spdlog
::
lite
::
logger
&
default_logger
();
...
...
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