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
621e0a83
Commit
621e0a83
authored
Mar 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added printf syntax support for even faster compilation!
parent
4449bf6f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
122 additions
and
47 deletions
+122
-47
example.cpp
example/example.cpp
+5
-5
example.cpp
lite-example/example.cpp
+6
-3
spdlite.cpp
lite/spdlite.cpp
+65
-9
spdlite.h
lite/spdlite.h
+46
-30
No files found.
example/example.cpp
View file @
621e0a83
...
...
@@ -3,9 +3,10 @@
int
main
()
{
// auto l = spdlog::create_lite();
// spdlog::lite::info("HELLO info {}", 123);
using
namespace
spdlog
;
auto
l
=
spdlog
::
default_logger
();
l
->
set_level
(
spdlog
::
level
::
trace
);
l
->
trace
(
"hello123123213 "
);
SPDLOG_TRACE
(
"SOME MACRO {}"
,
123
);
SPDLOG_INFO
(
"SOME MACRO {}"
,
"HHHHH"
);
}
\ No newline at end of file
lite-example/example.cpp
View file @
621e0a83
...
...
@@ -5,7 +5,9 @@ int main()
using
namespace
spdlog
;
auto
l
=
spdlog
::
create_lite
();
l
.
set_level
(
spdlog
::
lite
::
level
::
trace
);
lite
::
default_logger
().
set_level
(
l
.
get_level
());
lite
::
trace
(
"hello"
);
lite
::
trace
(
"hello {}"
,
std
::
string
(
"again"
));
l
.
trace_f
(
"Hello %s "
,
"GABI"
);
l
.
info_f
(
"Hello %d"
,
12346
);
}
\ No newline at end of file
lite/spdlite.cpp
View file @
621e0a83
...
...
@@ -23,23 +23,71 @@ bool spdlog::lite::logger::should_log(spdlog::lite::level level) const SPDLOG_NO
return
impl_
->
should_log
(
spd_level
);
// TODO avoid the call using local level member?
}
void
spdlog
::
lite
::
logger
::
log
_formatted_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
)
void
spdlog
::
lite
::
logger
::
log
(
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
)
{
auto
spd_level
=
to_spdlog_level
(
lvl
);
spdlog
::
source_loc
source_loc
{
src
.
filename
,
src
.
line
,
src
.
funcname
};
impl_
->
log
(
source_loc
,
spd_level
,
spdlog
::
details
::
fmt_helper
::
to_string_view
(
formatted
));
impl_
->
log
(
spd_level
,
sv
);
}
void
spdlog
::
lite
::
logger
::
log_string_view_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
)
void
spdlog
::
lite
::
logger
::
log_printf
(
spdlog
::
lite
::
level
lvl
,
const
char
*
format
,
va_list
args
)
{
auto
spd_level
=
to_spdlog_level
(
lvl
);
spdlog
::
source_loc
source_loc
{
src
.
filename
,
src
.
line
,
src
.
funcname
};
impl_
->
log
(
source_loc
,
spd_level
,
sv
);
char
buffer
[
500
];
auto
size
=
vsnprintf
(
buffer
,
sizeof
(
buffer
),
format
,
args
);
if
(
size
<
0
)
{
size
=
snprintf
(
buffer
,
sizeof
(
buffer
),
"invalid format (%s)"
,
format
);
}
log
(
lvl
,
string_view_t
{
buffer
,
static_cast
<
size_t
>
(
size
)});
}
void
spdlog
::
lite
::
logger
::
trace_f
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
trace
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
debug_f
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
debug
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
info_f
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
info
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
log_string_view_
(
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
)
void
spdlog
::
lite
::
logger
::
warn_f
(
const
char
*
format
,
...
)
{
log_string_view_
(
spdlog
::
lite
::
src_loc
{},
lvl
,
sv
);
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
warn
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
error_f
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
err
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
critical_f
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
log_printf
(
lite
::
level
::
critical
,
format
,
args
);
va_end
(
args
);
}
void
spdlog
::
lite
::
logger
::
set_level
(
spdlog
::
lite
::
level
level
)
...
...
@@ -80,8 +128,16 @@ void spdlog::lite::logger::set_pattern(std::string pattern)
impl_
->
set_pattern
(
std
::
move
(
pattern
));
}
void
spdlog
::
lite
::
logger
::
log_formatted_
(
spdlog
::
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
));
}
spdlog
::
lite
::
logger
&
spdlog
::
lite
::
default_logger
()
{
static
spdlog
::
lite
::
logger
s_default
(
spdlog
::
default_logger
());
return
s_default
;
}
lite/spdlite.h
View file @
621e0a83
...
...
@@ -97,20 +97,6 @@ enum class level
off
=
SPDLITE_LEVEL_OFF
};
struct
src_loc
{
src_loc
()
=
default
;
src_loc
(
const
char
*
filename
,
int
line
,
const
char
*
funcname
)
:
filename
(
filename
)
,
line
(
line
)
,
funcname
(
funcname
)
{
}
const
char
*
filename
=
nullptr
;
int
line
=
0
;
const
char
*
funcname
=
nullptr
;
};
class
logger
{
...
...
@@ -127,7 +113,7 @@ public:
bool
should_log
(
spdlog
::
lite
::
level
lvl
)
const
noexcept
;
template
<
typename
...
Args
>
void
log
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
...
...
@@ -135,19 +121,20 @@ public:
}
fmt
::
memory_buffer
formatted_buf
;
fmt
::
format_to
(
formatted_buf
,
fmt
,
args
...);
log_formatted_
(
src
,
lvl
,
formatted_buf
);
log_formatted_
(
lvl
,
formatted_buf
);
}
template
<
typename
...
Args
>
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
log
(
spdlog
::
lite
::
src_loc
{},
lvl
,
fmt
,
args
...);
}
// 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
);
//
// trace
//
void
trace
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
trace
,
msg
);
log
(
spdlog
::
lite
::
level
::
trace
,
string_view_t
(
msg
)
);
}
template
<
typename
...
Args
>
...
...
@@ -156,10 +143,14 @@ public:
log
(
spdlog
::
lite
::
level
::
trace
,
fmt
,
args
...);
}
void
trace_f
(
const
char
*
printf_format
,
...);
//
// debug
//
void
debug
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
debug
,
msg
);
log
(
spdlog
::
lite
::
level
::
debug
,
string_view_t
(
msg
)
);
}
template
<
typename
...
Args
>
...
...
@@ -168,10 +159,14 @@ public:
log
(
spdlog
::
lite
::
level
::
debug
,
fmt
,
args
...);
}
void
debug_f
(
const
char
*
printf_format
,
...);
//
// info
//
void
info
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
info
,
msg
);
log
(
spdlog
::
lite
::
level
::
info
,
string_view_t
(
msg
)
);
}
template
<
typename
...
Args
>
...
...
@@ -180,10 +175,14 @@ public:
log
(
spdlog
::
lite
::
level
::
info
,
fmt
,
args
...);
}
void
info_f
(
const
char
*
printf_format
,
...);
//
// warn
//
void
warn
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
warn
,
msg
);
log
(
spdlog
::
lite
::
level
::
warn
,
string_view_t
(
msg
)
);
}
template
<
typename
...
Args
>
...
...
@@ -192,22 +191,31 @@ public:
log
(
spdlog
::
lite
::
level
::
warn
,
fmt
,
args
...);
}
void
warn_f
(
const
char
*
printf_format
,
...);
//
// error
//
void
error
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
err
,
msg
);
log
(
spdlog
::
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
...);
}
void
error_f
(
const
char
*
printf_format
,
...);
//
// critical
//
void
critical
(
const
char
*
msg
)
{
log
_string_view_
(
spdlog
::
lite
::
level
::
critical
,
msg
);
log
(
spdlog
::
lite
::
level
::
critical
,
string_view_t
(
msg
)
);
}
template
<
typename
...
Args
>
...
...
@@ -216,9 +224,18 @@ public:
log
(
spdlog
::
lite
::
level
::
critical
,
fmt
,
args
...);
}
void
critical_f
(
const
char
*
printf_format
,
...);
//
// setters/getters
//
std
::
string
name
()
const
;
void
set_level
(
lite
::
level
level
);
lite
::
level
get_level
()
const
;
//
// flush
//
void
flush
();
void
flush_on
(
spdlog
::
lite
::
level
log_level
);
spdlog
::
lite
::
level
flush_level
()
const
;
...
...
@@ -226,9 +243,8 @@ public:
protected
:
std
::
shared_ptr
<
spdlog
::
logger
>
impl_
;
void
log_formatted_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
void
log_string_view_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log_string_view_
(
spdlog
::
lite
::
level
lvl
,
const
string_view_t
&
sv
);
void
log_formatted_
(
spdlog
::
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