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
c7535a91
Commit
c7535a91
authored
Mar 29, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip lite
parent
99a5484d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
44 deletions
+31
-44
create_logger.cpp
lite-example/create_logger.cpp
+2
-2
example.cpp
lite-example/example.cpp
+7
-3
spdlite.cpp
lite/spdlite.cpp
+5
-5
spdlite.h
lite/spdlite.h
+17
-34
No files found.
lite-example/create_logger.cpp
View file @
c7535a91
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
#define UNUSED(x) (void)(x)
#define UNUSED(x) (void)(x)
// example of creating lite logger with console and file sink
// example of creating lite logger with console and file sink
spdlog
::
lite
::
logger
spdlog
::
create_lite
(
void
*
ctx
)
spdlog
::
lite
::
logger
spdlog
::
lite
::
create_logger
(
void
*
ctx
)
{
{
UNUSED
(
ctx
);
UNUSED
(
ctx
);
std
::
shared_ptr
<
spdlog
::
logger
>
logger_impl
;
std
::
shared_ptr
<
spdlog
::
logger
>
logger_impl
;
...
@@ -17,7 +17,7 @@ spdlog::lite::logger spdlog::create_lite(void *ctx)
...
@@ -17,7 +17,7 @@ spdlog::lite::logger spdlog::create_lite(void *ctx)
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
"log.txt"
,
true
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
"log.txt"
,
true
);
file_sink
->
set_level
(
spdlog
::
level
::
info
);
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
=
std
::
make_
unique
<
spdlog
::
logger
>
(
"my-logger"
,
spdlog
::
sinks_init_list
{
console_sink
,
file_sink
});
logger_impl
->
set_level
(
spdlog
::
level
::
debug
);
logger_impl
->
set_level
(
spdlog
::
level
::
debug
);
return
spdlog
::
lite
::
logger
(
std
::
move
(
logger_impl
));
return
spdlog
::
lite
::
logger
(
std
::
move
(
logger_impl
));
}
}
lite-example/example.cpp
View file @
c7535a91
...
@@ -2,15 +2,18 @@
...
@@ -2,15 +2,18 @@
int
main
()
int
main
()
{
{
auto
l
=
spdlog
::
create_lite
();
auto
l
=
spdlog
::
lite
::
create_logger
();
l
.
set_level
(
spdlog
::
lite
::
level
::
trace
);
l
.
set_level
(
spdlog
::
lite
::
level
::
trace
);
l
.
trace_printf
(
"Hello %s "
,
"GABI"
);
l
.
trace_printf
(
"Hello %s "
,
"GABI"
);
l
.
info_printf
(
"Hello %d"
,
12346
);
l
.
info_printf
(
"Hello %d"
,
12346
);
l
.
warn_printf
(
"Hello %f"
,
12346.5656
);
l
.
warn_printf
(
"Hello %f"
,
12346.5656
);
l
.
warn
(
"Hello {}"
,
"LITE :) "
);
l
.
warn
(
"Hello {}"
,
"LITE :) "
);
auto
l2
=
l
.
clone
(
"logger2"
);
auto
l2
=
l
.
clone
(
"logger2"
);
l2
.
debug
(
"HELLO"
);
l2
.
debug
(
"HELLO"
);
auto
l3
=
std
::
move
(
l
);
l3
.
warn
(
"HELLO FROM L3"
);
}
}
\ No newline at end of file
lite/spdlite.cpp
View file @
c7535a91
...
@@ -87,18 +87,18 @@ void spdlog::lite::logger::critical_printf(const char *format, ...)
...
@@ -87,18 +87,18 @@ void spdlog::lite::logger::critical_printf(const char *format, ...)
va_end
(
args
);
va_end
(
args
);
}
}
void
spdlog
::
lite
::
logger
::
set_level
(
spdlog
::
lite
::
level
level
)
void
spdlog
::
lite
::
logger
::
set_level
(
spdlog
::
lite
::
level
level
)
noexcept
{
{
auto
spd_level
=
to_spdlog_level
(
level
);
auto
spd_level
=
to_spdlog_level
(
level
);
impl_
->
set_level
(
spd_level
);
impl_
->
set_level
(
spd_level
);
}
}
spdlog
::
lite
::
level
spdlog
::
lite
::
logger
::
get_level
()
cons
t
spdlog
::
lite
::
level
spdlog
::
lite
::
logger
::
level
()
const
noexcep
t
{
{
return
to_lite_level
(
impl_
->
level
());
return
to_lite_level
(
impl_
->
level
());
}
}
std
::
string
spdlog
::
lite
::
logger
::
name
()
const
std
::
string
spdlog
::
lite
::
logger
::
name
()
const
noexcept
{
{
return
impl_
->
name
();
return
impl_
->
name
();
}
}
...
@@ -114,13 +114,13 @@ void spdlog::lite::logger::flush_on(spdlog::lite::level level)
...
@@ -114,13 +114,13 @@ void spdlog::lite::logger::flush_on(spdlog::lite::level level)
impl_
->
flush_on
(
spd_level
);
impl_
->
flush_on
(
spd_level
);
}
}
spdlog
::
lite
::
level
spdlog
::
lite
::
logger
::
flush_level
()
const
spdlog
::
lite
::
level
spdlog
::
lite
::
logger
::
flush_level
()
const
noexcept
{
{
return
to_lite_level
(
impl_
->
flush_level
());
return
to_lite_level
(
impl_
->
flush_level
());
}
}
// pattern
// pattern
void
spdlog
::
lite
::
logger
::
set_pattern
(
std
::
string
pattern
)
void
spdlog
::
lite
::
logger
::
set_pattern
(
std
::
string
pattern
)
noexcept
{
{
impl_
->
set_pattern
(
std
::
move
(
pattern
));
impl_
->
set_pattern
(
std
::
move
(
pattern
));
}
}
...
...
lite/spdlite.h
View file @
c7535a91
...
@@ -42,7 +42,7 @@ enum class level
...
@@ -42,7 +42,7 @@ enum class level
class
logger
class
logger
{
{
public
:
public
:
explicit
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
);
explicit
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
);
logger
(
const
logger
&
)
=
default
;
logger
(
const
logger
&
)
=
default
;
logger
(
logger
&&
)
=
default
;
logger
(
logger
&&
)
=
default
;
logger
&
operator
=
(
const
logger
&
)
=
default
;
logger
&
operator
=
(
const
logger
&
)
=
default
;
...
@@ -65,6 +65,8 @@ public:
...
@@ -65,6 +65,8 @@ public:
// log string view
// log string view
void
log
(
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log
(
lite
::
level
lvl
,
const
string_view_t
&
sv
);
// log using printf format
void
log_printf
(
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
);
void
log_printf
(
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
);
//
//
...
@@ -98,10 +100,8 @@ public:
...
@@ -98,10 +100,8 @@ public:
}
}
void
debug_printf
(
const
char
*
format
,
...);
void
debug_printf
(
const
char
*
format
,
...);
//
// info
// info
//
void
info
(
const
char
*
msg
)
void
info
(
const
char
*
msg
)
{
{
log
(
lite
::
level
::
info
,
string_view_t
(
msg
));
log
(
lite
::
level
::
info
,
string_view_t
(
msg
));
...
@@ -115,9 +115,7 @@ public:
...
@@ -115,9 +115,7 @@ public:
void
info_printf
(
const
char
*
format
,
...);
void
info_printf
(
const
char
*
format
,
...);
//
// warn
// warn
//
void
warn
(
const
char
*
msg
)
void
warn
(
const
char
*
msg
)
{
{
log
(
lite
::
level
::
warn
,
string_view_t
(
msg
));
log
(
lite
::
level
::
warn
,
string_view_t
(
msg
));
...
@@ -131,9 +129,7 @@ public:
...
@@ -131,9 +129,7 @@ public:
void
warn_printf
(
const
char
*
format
,
...);
void
warn_printf
(
const
char
*
format
,
...);
//
// error
// error
//
void
error
(
const
char
*
msg
)
void
error
(
const
char
*
msg
)
{
{
log
(
lite
::
level
::
err
,
string_view_t
(
msg
));
log
(
lite
::
level
::
err
,
string_view_t
(
msg
));
...
@@ -147,9 +143,7 @@ public:
...
@@ -147,9 +143,7 @@ public:
void
error_printf
(
const
char
*
format
,
...);
void
error_printf
(
const
char
*
format
,
...);
//
// critical
// critical
//
void
critical
(
const
char
*
msg
)
void
critical
(
const
char
*
msg
)
{
{
log
(
lite
::
level
::
critical
,
string_view_t
(
msg
));
log
(
lite
::
level
::
critical
,
string_view_t
(
msg
));
...
@@ -163,28 +157,18 @@ public:
...
@@ -163,28 +157,18 @@ public:
void
critical_printf
(
const
char
*
format
,
...);
void
critical_printf
(
const
char
*
format
,
...);
//
//
setters/getters
// setters/getters
void
set_level
(
lite
::
level
level
)
noexcept
;
//
void
set_pattern
(
std
::
string
pattern
)
noexcept
;
std
::
string
name
()
cons
t
;
lite
::
level
level
()
const
noexcep
t
;
void
set_level
(
lite
::
level
level
)
;
std
::
string
name
()
const
noexcept
;
lite
::
level
get_level
()
cons
t
;
lite
::
level
flush_level
()
const
noexcep
t
;
//
// flush
// flush
//
void
flush
();
void
flush
();
void
flush_on
(
lite
::
level
log_level
);
void
flush_on
(
lite
::
level
log_level
);
lite
::
level
flush_level
()
const
;
//
// set pattern
//
void
set_pattern
(
std
::
string
pattern
);
//
//clone with new name
//clone with new name
//
spdlog
::
lite
::
logger
clone
(
std
::
string
logger_name
);
spdlog
::
lite
::
logger
clone
(
std
::
string
logger_name
);
protected
:
protected
:
...
@@ -230,10 +214,10 @@ void critical(const char *fmt, const Args &... args)
...
@@ -230,10 +214,10 @@ void critical(const char *fmt, const Args &... args)
default_logger
().
critical
(
fmt
,
args
...);
default_logger
().
critical
(
fmt
,
args
...);
}
}
}
// namespace lite
// user implemented factory to create lite logger
// implement it in a seperated and dedicated compilation unit for fast compiles.
logger
create_logger
(
void
*
ctx
=
nullptr
);
// factory to create lite logger
}
// namespace lite
// implement it in a dedicated compilation unit for fast compiles
}
// namespace spdlog
spdlog
::
lite
::
logger
create_lite
(
void
*
ctx
=
nullptr
);
}
// namespace spdlog
\ No newline at end of file
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