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
1d72edcc
Commit
1d72edcc
authored
Mar 23, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clang-format
parent
c29b7d22
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
78 additions
and
86 deletions
+78
-86
common.h
include/spdlog/common.h
+4
-1
rotating_file_sink.h
include/spdlog/sinks/rotating_file_sink.h
+2
-2
systemd_sink.h
include/spdlog/sinks/systemd_sink.h
+7
-13
create_lite.cpp
lite-example/create_lite.cpp
+3
-5
example.cpp
lite-example/example.cpp
+2
-4
logger.cpp
lite/logger.cpp
+2
-4
logger.h
lite/logger.h
+58
-57
No files found.
include/spdlog/common.h
View file @
1d72edcc
...
...
@@ -128,7 +128,10 @@ enum level_enum
static
string_view_t
level_string_views
[]
SPDLOG_LEVEL_NAMES
;
#if !defined(SPDLOG_SHORT_LEVEL_NAMES)
#define SPDLOG_SHORT_LEVEL_NAMES {"T", "D", "I", "W", "E", "C", "O"}
#define SPDLOG_SHORT_LEVEL_NAMES \
{ \
"T", "D", "I", "W", "E", "C", "O" \
}
#endif
static
const
char
*
short_level_names
[]
SPDLOG_SHORT_LEVEL_NAMES
;
...
...
include/spdlog/sinks/rotating_file_sink.h
View file @
1d72edcc
...
...
@@ -31,7 +31,7 @@ template<typename Mutex>
class
rotating_file_sink
final
:
public
base_sink
<
Mutex
>
{
public
:
rotating_file_sink
(
filename_t
base_filename
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
bool
rotate_on_open
=
false
)
rotating_file_sink
(
filename_t
base_filename
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
bool
rotate_on_open
=
false
)
:
base_filename_
(
std
::
move
(
base_filename
))
,
max_size_
(
max_size
)
,
max_files_
(
max_files
)
...
...
@@ -150,7 +150,7 @@ using rotating_file_sink_st = rotating_file_sink<details::null_mutex>;
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
rotate_on_open
=
false
)
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
rotate_on_open
=
false
)
{
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
max_file_size
,
max_files
,
rotate_on_open
);
}
...
...
include/spdlog/sinks/systemd_sink.h
View file @
1d72edcc
...
...
@@ -18,8 +18,10 @@
namespace
spdlog
{
namespace
sinks
{
inline
int
syslog_level
(
level
::
level_enum
l
)
{
switch
(
l
)
{
inline
int
syslog_level
(
level
::
level_enum
l
)
{
switch
(
l
)
{
case
level
:
:
off
:
case
level
:
:
trace
:
case
level
:
:
debug
:
...
...
@@ -57,13 +59,7 @@ public:
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
{
if
(
sd_journal_print
(
syslog_level
(
msg
.
level
),
"%.*s"
,
static_cast
<
int
>
(
msg
.
payload
.
size
()),
msg
.
payload
.
data
()
)
)
if
(
sd_journal_print
(
syslog_level
(
msg
.
level
),
"%.*s"
,
static_cast
<
int
>
(
msg
.
payload
.
size
()),
msg
.
payload
.
data
()))
throw
spdlog_ex
(
"Failed writing to systemd"
);
}
...
...
@@ -76,15 +72,13 @@ using systemd_sink_st = systemd_sink<details::null_mutex>;
// Create and register a syslog logger
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
systemd_logger_mt
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
systemd_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
systemd_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
systemd_logger_st
(
const
std
::
string
&
logger_name
)
inline
std
::
shared_ptr
<
logger
>
systemd_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
systemd_sink_st
>
(
logger_name
);
}
...
...
lite-example/create_lite.cpp
View file @
1d72edcc
#include "logger.h"
#include "spdlog/spdlog.h"
spdlog
::
lite
::
logger
spdlog
::
create_lite
(
void
*
ctx
)
spdlog
::
lite
::
logger
spdlog
::
create_lite
(
void
*
ctx
)
{
if
(
ctx
)
{
if
(
ctx
)
{
//..
}
auto
logger_impl
=
spdlog
::
default_logger
();
logger_impl
->
set_level
(
spdlog
::
level
::
trace
);
return
spdlog
::
lite
::
logger
(
logger_impl
);
}
lite-example/example.cpp
View file @
1d72edcc
...
...
@@ -3,9 +3,8 @@
int
main
()
{
//auto l = spdlog::create_lite();
//spdlog::lite::info("HELLO info {}", 123);
//
auto l = spdlog::create_lite();
//
spdlog::lite::info("HELLO info {}", 123);
SPDLITE_TRACE
(
"SOME MACRO {}"
,
123
);
SPDLITE_INFO
(
"SOME MACRO {}"
,
"HHHHH"
);
}
\ No newline at end of file
lite/logger.cpp
View file @
1d72edcc
...
...
@@ -4,7 +4,7 @@
static
spdlog
::
level
::
level_enum
to_spdlog_level
(
spdlog
::
lite
::
level
level
)
{
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level
);
return
static_cast
<
spdlog
::
level
::
level_enum
>
(
level
);
}
static
spdlog
::
lite
::
level
to_lite_level
(
spdlog
::
level
::
level_enum
level
)
...
...
@@ -20,7 +20,7 @@ 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 level
}
void
spdlog
::
lite
::
logger
::
log_formatted_
(
spdlog
::
lite
::
level
level
,
const
fmt
::
memory_buffer
&
formatted
)
...
...
@@ -29,7 +29,6 @@ void spdlog::lite::logger::log_formatted_(spdlog::lite::level level, const fmt::
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
)
{
auto
spd_level
=
to_spdlog_level
(
lvl
);
...
...
@@ -75,7 +74,6 @@ void spdlog::lite::logger::set_pattern(std::string pattern)
impl_
->
set_pattern
(
std
::
move
(
pattern
));
}
spdlog
::
lite
::
logger
&
spdlog
::
lite
::
default_logger
()
{
static
spdlog
::
lite
::
logger
s_default
(
spdlog
::
default_logger
());
...
...
lite/logger.h
View file @
1d72edcc
...
...
@@ -73,44 +73,47 @@
#define SPDLITE_CRITICAL(...) (void)0
#endif
namespace
spdlog
{
class
logger
;
class
logger
;
namespace
lite
{
enum
class
level
{
namespace
lite
{
enum
class
level
{
trace
=
SPDLITE_LEVEL_TRACE
,
debug
=
SPDLITE_LEVEL_DEBUG
,
debug
=
SPDLITE_LEVEL_DEBUG
,
info
=
SPDLITE_LEVEL_INFO
,
warn
=
SPDLITE_LEVEL_WARN
,
err
=
SPDLITE_LEVEL_ERROR
,
critical
=
SPDLITE_LEVEL_CRITICAL
,
off
=
SPDLITE_LEVEL_OFF
};
};
struct
src_loc
{
struct
src_loc
{
const
char
*
filename
;
int
line
;
const
char
*
funcname
;
};
const
char
*
funcname
;
};
class
logger
{
public
:
class
logger
{
public
:
logger
()
=
default
;
logger
(
std
::
shared_ptr
<
spdlog
::
logger
>
impl
);
logger
(
const
logger
&
)
=
default
;
logger
(
logger
&&
)
=
default
;
logger
&
operator
=
(
const
logger
&
)
=
default
;
logger
(
const
logger
&
)
=
default
;
logger
(
logger
&&
)
=
default
;
logger
&
operator
=
(
const
logger
&
)
=
default
;
~
logger
()
=
default
;
bool
should_log
(
spdlog
::
lite
::
level
lvl
)
const
noexcept
;
template
<
typename
...
Args
>
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
void
log
(
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
return
;
}
fmt
::
memory_buffer
formatted_buf
;
...
...
@@ -118,10 +121,11 @@ namespace spdlog {
log_formatted_
(
lvl
,
formatted_buf
);
}
template
<
typename
...
Args
>
void
log
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
void
log
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
char
*
fmt
,
const
Args
&
...
args
)
{
if
(
!
should_log
(
lvl
))
{
return
;
}
fmt
::
memory_buffer
formatted_buf
;
...
...
@@ -129,7 +133,6 @@ namespace spdlog {
log_formatted_src
(
src
,
lvl
,
formatted_buf
);
}
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
...
...
@@ -137,7 +140,7 @@ namespace spdlog {
}
template
<
typename
...
Args
>
void
trace
(
const
char
*
source_file
,
int
source_line
,
const
char
*
source_func
,
const
char
*
fmt
,
const
Args
&
...
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
...);
...
...
@@ -187,55 +190,52 @@ namespace spdlog {
// pattern
void
set_pattern
(
std
::
string
pattern
);
protected
:
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
);
};
spdlog
::
lite
::
logger
&
default_logger
();
void
log_formatted_src
(
const
spdlog
::
lite
::
src_loc
&
src
,
spdlog
::
lite
::
level
lvl
,
const
fmt
::
memory_buffer
&
formatted
);
};
spdlog
::
lite
::
logger
&
default_logger
();
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
template
<
typename
...
Args
>
void
trace
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
trace
(
fmt
,
args
...);
}
template
<
typename
...
Args
>
void
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
}
template
<
typename
...
Args
>
void
debug
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
debug
(
fmt
,
args
...);
}
}
template
<
typename
...
Args
>
void
info
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
template
<
typename
...
Args
>
void
info
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
info
(
fmt
,
args
...);
}
}
template
<
typename
...
Args
>
void
warn
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
template
<
typename
...
Args
>
void
warn
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
warn
(
fmt
,
args
...);
}
}
template
<
typename
...
Args
>
void
error
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
template
<
typename
...
Args
>
void
error
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
error
(
fmt
,
args
...);
}
}
template
<
typename
...
Args
>
void
critical
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
template
<
typename
...
Args
>
void
critical
(
const
char
*
fmt
,
const
Args
&
...
args
)
{
default_logger
().
critical
(
fmt
,
args
...);
}
}
}
// namespace lite
}
// namespace lite
// factory to create lite logger
// implement it in a dedicated compilation unit for fast compiles
spdlog
::
lite
::
logger
create_lite
(
void
*
ctx
=
nullptr
);
// factory to create lite logger
// implement it in a dedicated compilation unit for fast compiles
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