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
bc7cd2cc
Commit
bc7cd2cc
authored
Mar 30, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move lite namespace to topelevel spdlite
parent
18426691
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
62 deletions
+61
-62
create_logger.cpp
lite-example/create_logger.cpp
+2
-2
example.cpp
lite-example/example.cpp
+2
-2
spdlite.cpp
lite/spdlite.cpp
+31
-31
spdlite.h
lite/spdlite.h
+26
-27
No files found.
lite-example/create_logger.cpp
View file @
bc7cd2cc
...
...
@@ -6,7 +6,7 @@
#define UNUSED(x) (void)(x)
// example of creating lite logger with console and file sink
spdl
og
::
lite
::
logger
spdlog
::
lite
::
create_logger
(
void
*
ctx
)
spdl
ite
::
logger
spd
lite
::
create_logger
(
void
*
ctx
)
{
UNUSED
(
ctx
);
std
::
shared_ptr
<
spdlog
::
logger
>
logger_impl
;
...
...
@@ -19,5 +19,5 @@ spdlog::lite::logger spdlog::lite::create_logger(void *ctx)
logger_impl
=
std
::
make_unique
<
spdlog
::
logger
>
(
"my-logger"
,
spdlog
::
sinks_init_list
{
console_sink
,
file_sink
});
logger_impl
->
set_level
(
spdlog
::
level
::
debug
);
return
spdl
og
::
l
ite
::
logger
(
std
::
move
(
logger_impl
));
return
spdlite
::
logger
(
std
::
move
(
logger_impl
));
}
lite-example/example.cpp
View file @
bc7cd2cc
...
...
@@ -2,8 +2,8 @@
int
main
()
{
auto
l
=
spdl
og
::
l
ite
::
create_logger
();
l
.
set_level
(
spdl
og
::
l
ite
::
level
::
trace
);
auto
l
=
spdlite
::
create_logger
();
l
.
set_level
(
spdlite
::
level
::
trace
);
l
.
trace_printf
(
"Hello %s "
,
"GABI"
);
l
.
info_printf
(
"Hello %d"
,
12346
);
...
...
lite/spdlite.cpp
View file @
bc7cd2cc
#include "spdlite.h"
#include "spdlog/spdlog.h"
static
spdlog
::
level
::
level_enum
to_spdlog_level
(
spdl
og
::
l
ite
::
level
level
)
static
spdlog
::
level
::
level_enum
to_spdlog_level
(
spdlite
::
level
level
)
{
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level
);
}
static
spdl
og
::
l
ite
::
level
to_lite_level
(
spdlog
::
level
::
level_enum
level
)
static
spdlite
::
level
to_lite_level
(
spdlog
::
level
::
level_enum
level
)
{
return
static_cast
<
spdl
og
::
l
ite
::
level
>
(
level
);
return
static_cast
<
spdlite
::
level
>
(
level
);
}
spdl
og
::
l
ite
::
logger
::
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
)
spdlite
::
logger
::
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
)
{
impl_
=
std
::
move
(
impl
);
}
bool
spdl
og
::
lite
::
logger
::
should_log
(
spdlog
::
lite
::
level
level
)
const
SPDLOG_NOEXCEPT
bool
spdl
ite
::
logger
::
should_log
(
spd
lite
::
level
level
)
const
SPDLOG_NOEXCEPT
{
auto
spd_level
=
to_spdlog_level
(
level
);
return
impl_
->
should_log
(
spd_level
);
// TODO avoid the call using local level member?
}
void
spdl
og
::
lite
::
logger
::
log
(
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
)
void
spdl
ite
::
logger
::
log
(
spd
lite
::
level
lvl
,
const
string_view_t
&
sv
)
{
auto
spd_level
=
to_spdlog_level
(
lvl
);
impl_
->
log
(
spd_level
,
sv
);
}
void
spdl
og
::
lite
::
logger
::
log_printf
(
spdlog
::
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
)
void
spdl
ite
::
logger
::
log_printf
(
spd
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
)
{
char
buffer
[
500
];
auto
size
=
vsnprintf
(
buffer
,
sizeof
(
buffer
),
format
,
args
);
...
...
@@ -39,105 +39,105 @@ void spdlog::lite::logger::log_printf(spdlog::lite::level lvl, const char *forma
log
(
lvl
,
string_view_t
{
buffer
,
static_cast
<
size_t
>
(
size
)});
}
void
spdl
og
::
l
ite
::
logger
::
trace_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
trace_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
trace
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
trace
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
l
ite
::
logger
::
debug_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
debug_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
debug
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
debug
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
l
ite
::
logger
::
info_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
info_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
info
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
info
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
l
ite
::
logger
::
warn_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
warn_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
warn
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
warn
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
l
ite
::
logger
::
error_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
error_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
err
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
err
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
l
ite
::
logger
::
critical_printf
(
const
char
*
format
,
...)
void
spdlite
::
logger
::
critical_printf
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
critical
,
format
,
args
);
log_printf
(
spd
lite
::
level
::
critical
,
format
,
args
);
va_end
(
args
);
}
void
spdl
og
::
lite
::
logger
::
set_level
(
spdlog
::
lite
::
level
level
)
noexcept
void
spdl
ite
::
logger
::
set_level
(
spd
lite
::
level
level
)
noexcept
{
auto
spd_level
=
to_spdlog_level
(
level
);
impl_
->
set_level
(
spd_level
);
}
spdl
og
::
lite
::
level
spdlog
::
lite
::
logger
::
level
()
const
noexcept
spdl
ite
::
level
spd
lite
::
logger
::
level
()
const
noexcept
{
return
to_lite_level
(
impl_
->
level
());
}
std
::
string
spdl
og
::
l
ite
::
logger
::
name
()
const
noexcept
std
::
string
spdlite
::
logger
::
name
()
const
noexcept
{
return
impl_
->
name
();
}
void
spdl
og
::
l
ite
::
logger
::
flush
()
void
spdlite
::
logger
::
flush
()
{
impl_
->
flush
();
}
void
spdl
og
::
lite
::
logger
::
flush_on
(
spdlog
::
lite
::
level
level
)
void
spdl
ite
::
logger
::
flush_on
(
spd
lite
::
level
level
)
{
auto
spd_level
=
to_spdlog_level
(
level
);
impl_
->
flush_on
(
spd_level
);
}
spdl
og
::
lite
::
level
spdlog
::
lite
::
logger
::
flush_level
()
const
noexcept
spdl
ite
::
level
spd
lite
::
logger
::
flush_level
()
const
noexcept
{
return
to_lite_level
(
impl_
->
flush_level
());
}
// pattern
void
spdl
og
::
l
ite
::
logger
::
set_pattern
(
std
::
string
pattern
)
noexcept
void
spdlite
::
logger
::
set_pattern
(
std
::
string
pattern
)
noexcept
{
impl_
->
set_pattern
(
std
::
move
(
pattern
));
}
spdl
og
::
lite
::
logger
spdlog
::
lite
::
logger
::
clone
(
std
::
string
logger_name
)
spdl
ite
::
logger
spd
lite
::
logger
::
clone
(
std
::
string
logger_name
)
{
return
spdl
og
::
l
ite
::
logger
(
impl_
->
clone
(
std
::
move
(
logger_name
)));
return
spdlite
::
logger
(
impl_
->
clone
(
std
::
move
(
logger_name
)));
}
void
spdl
og
::
lite
::
logger
::
log_formatted_
(
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
)
void
spdl
ite
::
logger
::
log_formatted_
(
spd
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
)
{
auto
spd_level
=
to_spdlog_level
(
lvl
);
impl_
->
log
(
spd_level
,
spdlog
::
details
::
fmt_helper
::
to_string_view
(
formatted
));
}
spdl
og
::
lite
::
logger
&
spdlog
::
lite
::
default_logger
()
spdl
ite
::
logger
&
spd
lite
::
default_logger
()
{
static
spdl
og
::
l
ite
::
logger
s_default
(
spdlog
::
default_logger
());
static
spdlite
::
logger
s_default
(
spdlog
::
default_logger
());
return
s_default
;
}
lite/spdlite.h
View file @
bc7cd2cc
...
...
@@ -18,8 +18,8 @@
namespace
spdlog
{
class
logger
;
namespace
lite
{
}
namespace
spd
lite
{
// string_view type - either std::string_view or fmt::string_view (pre c++17)
#if defined(FMT_USE_STD_STRING_VIEW)
...
...
@@ -49,10 +49,10 @@ public:
~
logger
()
=
default
;
bool
should_log
(
lite
::
level
lvl
)
const
noexcept
;
bool
should_log
(
spd
lite
::
level
lvl
)
const
noexcept
;
template
<
typename
...
Args
>
void
log
(
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
void
log
(
spd
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
...
...
@@ -64,23 +64,23 @@ public:
}
// log string view
void
log
(
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log
(
spd
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
(
spd
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
);
//
// trace
//
void
trace
(
const
char
*
msg
)
{
log
(
lite
::
level
::
trace
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
trace
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
trace
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
trace
,
fmt
,
args
...);
}
void
trace_printf
(
const
char
*
format
,
...);
...
...
@@ -90,13 +90,13 @@ public:
//
void
debug
(
const
char
*
msg
)
{
log
(
lite
::
level
::
debug
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
debug
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
debug
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
debug
,
fmt
,
args
...);
}
void
debug_printf
(
const
char
*
format
,
...);
...
...
@@ -104,13 +104,13 @@ public:
// info
void
info
(
const
char
*
msg
)
{
log
(
lite
::
level
::
info
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
info
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
info
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
info
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
info
,
fmt
,
args
...);
}
void
info_printf
(
const
char
*
format
,
...);
...
...
@@ -118,13 +118,13 @@ public:
// warn
void
warn
(
const
char
*
msg
)
{
log
(
lite
::
level
::
warn
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
warn
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
warn
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
warn
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
warn
,
fmt
,
args
...);
}
void
warn_printf
(
const
char
*
format
,
...);
...
...
@@ -132,13 +132,13 @@ public:
// error
void
error
(
const
char
*
msg
)
{
log
(
lite
::
level
::
err
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
err
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
error
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
err
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
err
,
fmt
,
args
...);
}
void
error_printf
(
const
char
*
format
,
...);
...
...
@@ -146,37 +146,37 @@ public:
// critical
void
critical
(
const
char
*
msg
)
{
log
(
lite
::
level
::
critical
,
string_view_t
(
msg
));
log
(
spd
lite
::
level
::
critical
,
string_view_t
(
msg
));
}
template
<
typename
...
Args
>
void
critical
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
lite
::
level
::
critical
,
fmt
,
args
...);
log
(
spd
lite
::
level
::
critical
,
fmt
,
args
...);
}
void
critical_printf
(
const
char
*
format
,
...);
// setters/getters
void
set_level
(
lite
::
level
level
)
noexcept
;
void
set_level
(
spd
lite
::
level
level
)
noexcept
;
void
set_pattern
(
std
::
string
pattern
)
noexcept
;
lite
::
level
level
()
const
noexcept
;
spd
lite
::
level
level
()
const
noexcept
;
std
::
string
name
()
const
noexcept
;
lite
::
level
flush_level
()
const
noexcept
;
spd
lite
::
level
flush_level
()
const
noexcept
;
// flush
void
flush
();
void
flush_on
(
lite
::
level
log_level
);
void
flush_on
(
spd
lite
::
level
log_level
);
//clone with new name
spdl
og
::
l
ite
::
logger
clone
(
std
::
string
logger_name
);
spdlite
::
logger
clone
(
std
::
string
logger_name
);
protected
:
std
::
shared_ptr
<
spdlog
::
logger
>
impl_
;
void
log_formatted_
(
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
void
log_formatted_
(
spd
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
};
spdl
og
::
l
ite
::
logger
&
default_logger
();
spdlite
::
logger
&
default_logger
();
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
...
...
@@ -218,6 +218,5 @@ void critical(const char *fmt, const Args &... args)
// implement it in a seperated and dedicated compilation unit for fast compiles.
logger
create_logger
(
void
*
ctx
=
nullptr
);
}
// namespace lite
}
// namespace spdlog
}
// namespace spdlite
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