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
90c912a5
Commit
90c912a5
authored
Mar 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip lite
parent
92196139
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
57 additions
and
50 deletions
+57
-50
.clang-tidy
.clang-tidy
+1
-1
clang_tidy.sh
clang_tidy.sh
+2
-1
example.cpp
example/example.cpp
+7
-6
spdlog.h
include/spdlog/spdlog.h
+1
-1
create_lite.cpp
lite-example/create_lite.cpp
+9
-3
example.cpp
lite-example/example.cpp
+6
-5
spdlite.cpp
lite/spdlite.cpp
+8
-7
spdlite.h
lite/spdlite.h
+23
-26
No files found.
.clang-tidy
View file @
90c912a5
Checks: 'modernize-*,modernize-use-override,google-*,-google-runtime-references,misc-*,clang-analyzer-*'
WarningsAsErrors: ''
HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h'
HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h
|spdlite.h
'
AnalyzeTemporaryDtors: false
FormatStyle: none
...
...
clang_tidy.sh
View file @
90c912a5
#!/bin/bash
clang-tidy example/example.cpp
--
-I
./include
clang-tidy example/example.cpp
--
-I
./include
clang-tidy lite-example/example.cpp
--
-I
./include
-I
./lite
example/example.cpp
View file @
90c912a5
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#include "spdlog/spdlog.h"
int
main
()
{
auto
l
=
spdlog
::
default_logger
();
l
->
trace
(
"HELLO {}!!!"
,
"lite"
);
l
->
debug
(
"HELLO {}!!!"
,
"lite"
);
l
->
info
(
"HELLO {}!!!"
,
"lite"
);
l
->
warn
(
"HELLO {}!!!"
,
"lite"
);
l
->
critical
(
"HELLO s{}!!!"
,
"lite"
);
// auto l = spdlog::create_lite();
// spdlog::lite::info("HELLO info {}", 123);
SPDLOG_TRACE
(
"SOME MACRO {}"
,
123
);
SPDLOG_INFO
(
"SOME MACRO {}"
,
"HHHHH"
);
}
\ No newline at end of file
include/spdlog/spdlog.h
View file @
90c912a5
...
...
@@ -326,7 +326,7 @@ inline void critical(const wchar_t *fmt, const Args &... args)
// SPDLOG_LEVEL_OFF
//
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
#define SPDLOG_LOGGER_CALL(logger, level, ...) \
logger->log(spdlog::source_loc{SPDLOG_FILE_BASENAME(__FILE__), __LINE__, SPDLOG_FUNCTION}, level, __VA_ARGS__)
#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
...
...
lite-example/create_lite.cpp
View file @
90c912a5
#include "spdlite.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/basic_file_sink.h"
#include "spdlog/sinks/stdout_color_sinks.h"
spdlog
::
lite
::
logger
spdlog
::
create_lite
(
void
*
ctx
)
{
...
...
@@ -7,7 +11,9 @@ spdlog::lite::logger spdlog::create_lite(void *ctx)
{
//..
}
auto
logger_impl
=
spdlog
::
default_logger
();
logger_impl
->
set_level
(
spdlog
::
level
::
trace
);
return
spdlog
::
lite
::
logger
(
logger_impl
);
auto
logger_impl
=
spdlog
::
stdout_color_mt
(
"mylogger"
);
auto
file_sink
=
std
::
make_shared
<
spdlog
::
sinks
::
basic_file_sink_mt
>
(
"file.txt"
,
true
);
logger_impl
->
sinks
().
push_back
(
file_sink
);
logger_impl
->
set_level
(
spdlog
::
level
::
debug
);
return
spdlog
::
lite
::
logger
(
std
::
move
(
logger_impl
));
}
lite-example/example.cpp
View file @
90c912a5
#define SPDLITE_ACTIVE_LEVEL SPDLITE_LEVEL_
INFO
#define SPDLITE_ACTIVE_LEVEL SPDLITE_LEVEL_
TRACE
#include "spdlite.h"
int
main
()
{
//
auto l = spdlog::create_lite();
//
spdlog::lite::info("HELLO info {}", 123
);
SPDLITE_TRACE
(
"
SOME MACRO {}"
,
123
);
SPDLITE_INFO
(
"SOME MACRO {}"
,
"HHHHH"
);
//auto l = spdlog::create_lite();
//
l.info("Hello spdlog {}", "lite"
);
SPDLITE_TRACE
(
"
HELLO TRACE"
);
}
\ No newline at end of file
lite/spdlite.cpp
View file @
90c912a5
...
...
@@ -20,22 +20,23 @@ spdlog::lite::logger::logger(std::shared_ptr<spdlog::logger> impl)
bool
spdlog
::
lite
::
logger
::
should_log
(
spdlog
::
lite
::
level
level
)
const
SPDLOG_NOEXCEPT
{
auto
spd_level
=
to_spdlog_level
(
level
);
return
impl_
->
should_log
(
spd_level
);
// TODO
level
return
impl_
->
should_log
(
spd_level
);
// TODO
avoid the call using local level member?
}
void
spdlog
::
lite
::
logger
::
log_formatted_
(
spdlog
::
lite
::
level
level
,
const
fmt
::
memory_buffer
&
formatted
)
{
auto
spd_level
=
to_spdlog_level
(
level
);
impl_
->
log
(
spd_level
,
spdlog
::
details
::
fmt_helper
::
to_string_view
(
formatted
));
}
void
spdlog
::
lite
::
logger
::
log_formatted_src
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
)
void
spdlog
::
lite
::
logger
::
log_formatted_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
)
{
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
));
}
void
spdlog
::
lite
::
logger
::
log_formatted_
(
spdlog
::
lite
::
level
level
,
const
fmt
::
memory_buffer
&
formatted
)
{
log_formatted_
(
src_loc
{},
level
,
formatted
);
}
void
spdlog
::
lite
::
logger
::
set_level
(
spdlog
::
lite
::
level
level
)
{
auto
spd_level
=
to_spdlog_level
(
level
);
...
...
lite/spdlite.h
View file @
90c912a5
...
...
@@ -21,12 +21,16 @@
#define SPDLITE_LEVEL_CRITICAL 5
#define SPDLITE_LEVEL_OFF 6
#define SPDLITE_LOGGER_CALL(logger, level, ...) \
if (logger.should_log(level)) \
logger.log(level, __VA_ARGS__)
#define SPDLITE_LOGGER_CALL(logger, level, ...) logger.log(level, __VA_ARGS__)
//with source info
#define SPDLITE_LOGGER_CALL2(logger, level, ...) \
logger.log(spdlog::lite::src_loc{__FILE__, __LINE__, __FUNCTION__}, level, __VA_ARGS__)
#if SPDLITE_ACTIVE_LEVEL <= SPDLITE_LEVEL_TRACE
#define SPDLITE_LOGGER_TRACE(logger, ...) SPDLITE_LOGGER_CALL(logger, spdlog::lite::level::trace, __VA_ARGS__)
#define SPDLITE_LOGGER_TRACE(logger, ...) SPDLITE_LOGGER_CALL
2
(logger, spdlog::lite::level::trace, __VA_ARGS__)
#define SPDLITE_TRACE(...) SPDLITE_LOGGER_TRACE(spdlog::lite::default_logger(), __VA_ARGS__)
#else
#define SPDLITE_LOGGER_TRACE(logger, ...) (void)0
...
...
@@ -90,9 +94,13 @@ enum class level
struct
src_loc
{
const
char
*
filename
;
int
line
;
const
char
*
funcname
;
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
...
...
@@ -100,7 +108,7 @@ class logger
public
:
logger
()
=
default
;
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
);
explicit
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
);
logger
(
const
logger
&
)
=
default
;
logger
(
logger
&&
)
=
default
;
logger
&
operator
=
(
const
logger
&
)
=
default
;
...
...
@@ -110,7 +118,7 @@ public:
bool
should_log
(
spdlog
::
lite
::
level
lvl
)
const
noexcept
;
template
<
typename
...
Args
>
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
void
log
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
...
...
@@ -118,19 +126,13 @@ public:
}
fmt
::
memory_buffer
formatted_buf
;
fmt
::
format_to
(
formatted_buf
,
fmt
,
args
...);
log_formatted_
(
lvl
,
formatted_buf
);
log_formatted_
(
src
,
lvl
,
formatted_buf
);
}
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
))
{
return
;
}
fmt
::
memory_buffer
formatted_buf
;
fmt
::
format_to
(
formatted_buf
,
fmt
,
args
...);
log_formatted_src
(
src
,
lvl
,
formatted_buf
);
log
(
spdlog
::
lite
::
src_loc
{},
lvl
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
...
...
@@ -139,13 +141,7 @@ public:
log
(
spdlog
::
lite
::
level
::
trace
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
void
trace
(
const
char
*
source_file
,
int
source_line
,
const
char
*
source_func
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
spdlog
::
lite
::
src_loc
src
{
source_file
,
source_line
,
source_func
};
log
(
src
,
spdlog
::
lite
::
level
::
trace
,
fmt
,
args
...);
}
template
<
typename
...
Args
>
void
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
...
...
@@ -193,8 +189,9 @@ public:
protected
:
std
::
shared_ptr
<
spdlog
::
logger
>
impl_
;
void
log_formatted_
(
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
void
log_formatted_
src
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
void
log_formatted_
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
};
spdlog
::
lite
::
logger
&
default_logger
();
template
<
typename
...
Args
>
...
...
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