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
c7b8c762
Commit
c7b8c762
authored
Oct 30, 2014
by
gabi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
spdlog
parent
cbddc879
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
267 additions
and
149 deletions
+267
-149
common.h
include/spdlog/common.h
+7
-6
blocking_queue.h
include/spdlog/details/blocking_queue.h
+1
-1
fast_istostr.h
include/spdlog/details/fast_istostr.h
+1
-1
fast_oss.h
include/spdlog/details/fast_oss.h
+1
-1
file_helper.h
include/spdlog/details/file_helper.h
+8
-7
line_logger.h
include/spdlog/details/line_logger.h
+2
-2
log_msg.h
include/spdlog/details/log_msg.h
+1
-1
logger_impl.h
include/spdlog/details/logger_impl.h
+32
-59
null_mutex.h
include/spdlog/details/null_mutex.h
+1
-1
os.h
include/spdlog/details/os.h
+2
-2
pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+5
-5
registry.h
include/spdlog/details/registry.h
+39
-20
spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+51
-0
stack_buf.h
include/spdlog/details/stack_buf.h
+2
-2
formatter.h
include/spdlog/formatter.h
+2
-2
logger.h
include/spdlog/logger.h
+8
-20
async_sink.h
include/spdlog/sinks/async_sink.h
+10
-10
base_sink.h
include/spdlog/sinks/base_sink.h
+1
-1
file_sinks.h
include/spdlog/sinks/file_sinks.h
+4
-4
null_sink.h
include/spdlog/sinks/null_sink.h
+1
-1
ostream_sink.h
include/spdlog/sinks/ostream_sink.h
+1
-1
sink.h
include/spdlog/sinks/sink.h
+1
-1
stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+1
-1
spdlog.h
include/spdlog/spdlog.h
+85
-0
No files found.
include/sp
it
log/common.h
→
include/sp
d
log/common.h
View file @
c7b8c762
...
...
@@ -3,7 +3,7 @@
#include<initializer_list>
#include<chrono>
namespace
sp
it
log
namespace
sp
d
log
{
class
formatter
;
namespace
sinks
{
...
...
@@ -14,7 +14,7 @@ class sink;
using
log_clock
=
std
::
chrono
::
system_clock
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
sp
it
log
::
formatter
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
sp
d
log
::
formatter
>
;
//Log level enum
namespace
level
...
...
@@ -27,11 +27,12 @@ typedef enum
WARN
,
ERR
,
CRITICAL
,
NONE
=
99
ALWAYS
,
OFF
}
level_enum
;
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"warning"
,
"error"
,
"critical"
,
"
fatal"
};
inline
const
char
*
to_str
(
sp
it
log
::
level
::
level_enum
l
)
static
const
char
*
level_names
[]
{
"trace"
,
"debug"
,
"info"
,
"warning"
,
"error"
,
"critical"
,
"
"
,
""
};
inline
const
char
*
to_str
(
sp
d
log
::
level
::
level_enum
l
)
{
return
level_names
[
l
];
}
...
...
@@ -52,4 +53,4 @@ private:
};
}
//sp
it
log
}
//sp
d
log
include/sp
it
log/details/blocking_queue.h
→
include/sp
d
log/details/blocking_queue.h
View file @
c7b8c762
...
...
@@ -10,7 +10,7 @@
#include <mutex>
#include <condition_variable>
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
include/sp
it
log/details/fast_istostr.h
→
include/sp
d
log/details/fast_istostr.h
View file @
c7b8c762
...
...
@@ -5,7 +5,7 @@
//Source: http://stackoverflow.com/a/4351484/192001
//Modified version to pad zeros according to padding arg
namespace
sp
it
log
{
namespace
sp
d
log
{
namespace
details
{
const
char
digit_pairs
[
201
]
=
{
...
...
include/sp
it
log/details/fast_oss.h
→
include/sp
d
log/details/fast_oss.h
View file @
c7b8c762
...
...
@@ -9,7 +9,7 @@
#include "stack_buf.h"
#include<iostream>
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
include/sp
it
log/details/file_helper.h
→
include/sp
d
log/details/file_helper.h
View file @
c7b8c762
...
...
@@ -16,7 +16,7 @@
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
@@ -36,16 +36,14 @@ public:
~
file_helper
()
{
if
(
_fd
)
std
::
fclose
(
_fd
);
close
();
}
void
open
(
const
std
::
string
&
filename
)
{
if
(
_fd
)
std
::
fclose
(
_fd
);
close
();
_filename
=
filename
;
for
(
int
tries
=
0
;
tries
<
open_max_tries
;
++
tries
)
...
...
@@ -61,8 +59,11 @@ public:
void
close
()
{
std
::
fclose
(
_fd
);
_fd
=
nullptr
;
if
(
_fd
)
{
std
::
fclose
(
_fd
);
_fd
=
nullptr
;
}
}
void
write
(
const
log_msg
&
msg
)
...
...
include/sp
it
log/details/line_logger.h
→
include/sp
d
log/details/line_logger.h
View file @
c7b8c762
...
...
@@ -8,7 +8,7 @@
// Line logger class - aggregates operator<< calls to fast ostream
// and logs upon destruction
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
@@ -76,4 +76,4 @@ private:
bool
_enabled
;
};
}
//Namespace details
}
// Namespace sp
it
log
}
// Namespace sp
d
log
include/sp
it
log/details/log_msg.h
→
include/sp
d
log/details/log_msg.h
View file @
c7b8c762
...
...
@@ -3,7 +3,7 @@
#include "../common.h"
#include "./fast_oss.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
include/sp
it
log/details/logger_impl.h
→
include/sp
d
log/details/logger_impl.h
View file @
c7b8c762
...
...
@@ -7,7 +7,7 @@
#include "./line_logger.h"
inline
sp
it
log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks_list
)
:
inline
sp
d
log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks_list
)
:
_name
(
logger_name
),
_sinks
(
sinks_list
)
{
...
...
@@ -16,30 +16,30 @@ inline spitlog::logger::logger(const std::string& logger_name, sinks_init_list s
}
template
<
class
It
>
inline
sp
it
log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
)
:
inline
sp
d
log
::
logger
::
logger
(
const
std
::
string
&
logger_name
,
const
It
&
begin
,
const
It
&
end
)
:
_name
(
logger_name
),
_sinks
(
begin
,
end
)
{}
inline
void
sp
itlog
::
logger
::
set_formatter
(
spit
log
::
formatter_ptr
msg_formatter
)
inline
void
sp
dlog
::
logger
::
set_formatter
(
spd
log
::
formatter_ptr
msg_formatter
)
{
_formatter
=
msg_formatter
;
}
inline
void
sp
itlog
::
logger
::
set_format
(
const
std
::
string
&
format
)
inline
void
sp
dlog
::
logger
::
set_pattern
(
const
std
::
string
&
pattern
)
{
_formatter
=
std
::
make_shared
<
pattern_formatter
>
(
format
);
_formatter
=
std
::
make_shared
<
pattern_formatter
>
(
pattern
);
}
inline
sp
itlog
::
formatter_ptr
spit
log
::
logger
::
get_formatter
()
const
inline
sp
dlog
::
formatter_ptr
spd
log
::
logger
::
get_formatter
()
const
{
return
_formatter
;
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
)
{
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
)
{
bool
msg_enabled
=
should_log
(
lvl
);
details
::
line_logger
l
(
this
,
lvl
,
msg_enabled
);
if
(
msg_enabled
)
...
...
@@ -48,72 +48,83 @@ inline spitlog::details::line_logger spitlog::logger::log(level::level_enum lvl,
}
template
<
typename
...
Args
>
inline
spitlog
::
details
::
line_logger
spitlog
::
logger
::
trace
(
const
Args
&
...
args
)
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
log
(
const
Args
&
...
args
)
{
return
log
(
level
::
ALWAYS
,
args
...);
}
template
<
typename
...
Args
>
inline
spdlog
::
details
::
line_logger
spdlog
::
logger
::
trace
(
const
Args
&
...
args
)
{
return
log
(
level
::
TRACE
,
args
...);
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
debug
(
const
Args
&
...
args
)
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
debug
(
const
Args
&
...
args
)
{
return
log
(
level
::
DEBUG
,
args
...);
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
info
(
const
Args
&
...
args
)
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
info
(
const
Args
&
...
args
)
{
return
log
(
level
::
INFO
,
args
...);
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
warn
(
const
Args
&
...
args
)
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
warn
(
const
Args
&
...
args
)
{
return
log
(
level
::
WARN
,
args
...);
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
error
(
const
Args
&
...
args
)
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
error
(
const
Args
&
...
args
)
{
return
log
(
level
::
ERR
,
args
...);
}
template
<
typename
...
Args
>
inline
sp
itlog
::
details
::
line_logger
spit
log
::
logger
::
critical
(
const
Args
&
...
args
)
inline
sp
dlog
::
details
::
line_logger
spd
log
::
logger
::
critical
(
const
Args
&
...
args
)
{
return
log
(
level
::
CRITICAL
,
args
...);
}
inline
const
std
::
string
&
sp
it
log
::
logger
::
name
()
const
inline
const
std
::
string
&
sp
d
log
::
logger
::
name
()
const
{
return
_name
;
}
inline
void
sp
itlog
::
logger
::
set_level
(
spit
log
::
level
::
level_enum
log_level
)
inline
void
sp
dlog
::
logger
::
set_level
(
spd
log
::
level
::
level_enum
log_level
)
{
_level
.
store
(
log_level
);
}
inline
sp
itlog
::
level
::
level_enum
spit
log
::
logger
::
level
()
const
inline
sp
dlog
::
level
::
level_enum
spd
log
::
logger
::
level
()
const
{
return
static_cast
<
sp
it
log
::
level
::
level_enum
>
(
_level
.
load
());
return
static_cast
<
sp
d
log
::
level
::
level_enum
>
(
_level
.
load
());
}
inline
bool
sp
itlog
::
logger
::
should_log
(
spit
log
::
level
::
level_enum
msg_level
)
const
inline
bool
sp
dlog
::
logger
::
should_log
(
spd
log
::
level
::
level_enum
msg_level
)
const
{
return
msg_level
>=
_level
.
load
();
}
inline
void
spitlog
::
logger
::
_variadic_log
(
spitlog
::
details
::
line_logger
&
)
{}
inline
void
spdlog
::
logger
::
stop_logging
()
{
set_level
(
level
::
OFF
);
}
inline
void
spdlog
::
logger
::
_variadic_log
(
spdlog
::
details
::
line_logger
&
)
{}
template
<
typename
First
,
typename
...
Rest
>
void
sp
itlog
::
logger
::
_variadic_log
(
spit
log
::
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
)
void
sp
dlog
::
logger
::
_variadic_log
(
spd
log
::
details
::
line_logger
&
l
,
const
First
&
first
,
const
Rest
&
...
rest
)
{
l
.
write
(
first
);
l
.
write
(
' '
);
_variadic_log
(
l
,
rest
...);
}
inline
void
sp
it
log
::
logger
::
_log_msg
(
details
::
log_msg
&
msg
)
inline
void
sp
d
log
::
logger
::
_log_msg
(
details
::
log_msg
&
msg
)
{
//Use default formatter if not set
if
(
!
_formatter
)
...
...
@@ -123,41 +134,3 @@ inline void spitlog::logger::_log_msg(details::log_msg& msg)
sink
->
log
(
msg
);
}
//
// Global registry functions
//
#include "./registry.h"
inline
std
::
shared_ptr
<
spitlog
::
logger
>
spitlog
::
get
(
const
std
::
string
&
name
)
{
return
details
::
registry
::
instance
().
get
(
name
);
}
inline
std
::
shared_ptr
<
spitlog
::
logger
>
spitlog
::
create
(
const
std
::
string
&
logger_name
,
spitlog
::
sinks_init_list
sinks
)
{
return
details
::
registry
::
instance
().
create
(
logger_name
,
sinks
);
}
template
<
typename
Sink
,
typename
...
Args
>
inline
std
::
shared_ptr
<
spitlog
::
logger
>
spitlog
::
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
)
{
sink_ptr
sink
=
std
::
make_shared
<
Sink
>
(
args
...);
return
details
::
registry
::
instance
().
create
(
logger_name
,
{
sink
});
}
template
<
class
It
>
inline
std
::
shared_ptr
<
spitlog
::
logger
>
spitlog
::
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
{
return
details
::
registry
::
instance
().
create
(
logger_name
,
std
::
forward
(
sinks_begin
),
std
::
forward
(
sinks_end
));
}
inline
void
spitlog
::
set_formatter
(
spitlog
::
formatter_ptr
f
)
{
details
::
registry
::
instance
().
formatter
(
f
);
}
inline
void
spitlog
::
set_format
(
const
std
::
string
&
format_string
)
{
return
details
::
registry
::
instance
().
set_format
(
format_string
);
}
include/sp
it
log/details/null_mutex.h
→
include/sp
d
log/details/null_mutex.h
View file @
c7b8c762
...
...
@@ -2,7 +2,7 @@
// null, no cost mutex
namespace
sp
it
log
{
namespace
sp
d
log
{
namespace
details
{
struct
null_mutex
{
...
...
include/sp
it
log/details/os.h
→
include/sp
d
log/details/os.h
View file @
c7b8c762
...
...
@@ -7,7 +7,7 @@
#include <Windows.h>
#endif
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
@@ -123,7 +123,7 @@ inline int utc_minutes_offset(const std::tm& tm = localtime())
}
//os
}
//details
}
//sp
it
log
}
//sp
d
log
include/sp
it
log/details/pattern_formatter_impl.h
→
include/sp
d
log/details/pattern_formatter_impl.h
View file @
c7b8c762
...
...
@@ -10,7 +10,7 @@
#include "./fast_oss.h"
#include "./os.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
class
flag_formatter
...
...
@@ -377,12 +377,12 @@ class full_formatter :public flag_formatter
///////////////////////////////////////////////////////////////////////////////
// pattern_formatter inline impl
///////////////////////////////////////////////////////////////////////////////
inline
sp
it
log
::
pattern_formatter
::
pattern_formatter
(
const
std
::
string
&
pattern
)
inline
sp
d
log
::
pattern_formatter
::
pattern_formatter
(
const
std
::
string
&
pattern
)
{
compile_pattern
(
pattern
);
}
inline
void
sp
it
log
::
pattern_formatter
::
compile_pattern
(
const
std
::
string
&
pattern
)
inline
void
sp
d
log
::
pattern_formatter
::
compile_pattern
(
const
std
::
string
&
pattern
)
{
auto
end
=
pattern
.
end
();
std
::
unique_ptr
<
details
::
aggregate_formatter
>
user_chars
;
...
...
@@ -411,7 +411,7 @@ inline void spitlog::pattern_formatter::compile_pattern(const std::string& patte
}
}
inline
void
sp
it
log
::
pattern_formatter
::
handle_flag
(
char
flag
)
inline
void
sp
d
log
::
pattern_formatter
::
handle_flag
(
char
flag
)
{
switch
(
flag
)
{
...
...
@@ -523,7 +523,7 @@ inline void spitlog::pattern_formatter::handle_flag(char flag)
}
inline
void
sp
it
log
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
inline
void
sp
d
log
::
pattern_formatter
::
format
(
details
::
log_msg
&
msg
)
{
for
(
auto
&
f
:
_formatters
)
{
...
...
include/sp
it
log/details/registry.h
→
include/sp
d
log/details/registry.h
View file @
c7b8c762
...
...
@@ -7,58 +7,77 @@
#include <string>
#include <mutex>
#include <unordered_map>
#include "../logger.h"
#include "../common.h"
namespace
sp
it
log
{
namespace
sp
d
log
{
namespace
details
{
class
registry
{
public
:
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
name
)
{
std
::
lock_guard
<
std
::
mutex
>
l
(
_mutex
);
std
::
lock_guard
<
std
::
mutex
>
l
ock
(
_mutex
);
auto
found
=
_loggers
.
find
(
name
);
return
found
==
_loggers
.
end
()
?
nullptr
:
found
->
second
;
}
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
)
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
{
std
::
lock_guard
<
std
::
mutex
>
l
(
_mutex
);
auto
new_logger
=
std
::
make_shared
<
logger
>
(
logger_name
,
sinks
);
std
::
lock_guard
<
std
::
mutex
>
l
ock
(
_mutex
);
auto
new_logger
=
std
::
make_shared
<
logger
>
(
logger_name
,
sinks
_begin
,
sinks_end
);
new_logger
->
set_formatter
(
_formatter
);
new_logger
->
set_level
(
_level
);
_loggers
[
logger_name
]
=
new_logger
;
return
new_logger
;
}
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
)
{
return
create
(
logger_name
,
sinks
.
begin
(),
sinks
.
end
());
}
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sink_ptr
sink
)
{
return
create
(
logger_name
,
{
sink
});
}
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
void
formatter
(
formatter_ptr
f
)
{
std
::
lock_guard
<
std
::
mutex
>
l
(
_mutex
);
auto
new_logger
=
std
::
make_shared
<
logger
>
(
logger_name
,
sinks_begin
,
sinks_end
);
new_logger
->
set_formatter
(
_formatter
);
_loggers
[
logger_name
]
=
new_logger
;
return
new_logger
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_formatter
=
f
;
for
(
auto
&
l
:
_loggers
)
l
.
second
->
set_formatter
(
_formatter
);
}
void
formatter
(
formatter_ptr
f
)
void
set_pattern
(
const
std
::
string
&
pattern
)
{
_formatter
=
f
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_formatter
=
std
::
make_shared
<
pattern_formatter
>
(
pattern
);
for
(
auto
&
l
:
_loggers
)
l
.
second
->
set_formatter
(
_formatter
);
}
formatter_ptr
formatter
(
)
void
set_level
(
level
::
level_enum
log_level
)
{
return
_formatter
;
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
for
(
auto
&
l
:
_loggers
)
l
.
second
->
set_level
(
log_level
);
}
void
s
et_format
(
const
std
::
string
&
format_string
)
void
s
top_all
(
)
{
_formatter
=
std
::
make_shared
<
pattern_formatter
>
(
format_string
);
std
::
lock_guard
<
std
::
mutex
>
lock
(
_mutex
);
_level
=
level
::
OFF
;
for
(
auto
&
l
:
_loggers
)
l
.
second
->
stop_logging
();
}
...
...
@@ -74,7 +93,7 @@ private:
std
::
mutex
_mutex
;
std
::
unordered_map
<
std
::
string
,
std
::
shared_ptr
<
logger
>>
_loggers
;
formatter_ptr
_formatter
;
level
::
level_enum
_level
=
level
::
INFO
;
};
}
}
include/spdlog/details/spdlog_impl.h
0 → 100644
View file @
c7b8c762
#pragma once
//
// Global registry functions
//
#include "registry.h"
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
get
(
const
std
::
string
&
name
)
{
return
details
::
registry
::
instance
().
get
(
name
);
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create
(
const
std
::
string
&
logger_name
,
spdlog
::
sinks_init_list
sinks
)
{
return
details
::
registry
::
instance
().
create
(
logger_name
,
sinks
);
}
template
<
typename
Sink
,
typename
...
Args
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
)
{
sink_ptr
sink
=
std
::
make_shared
<
Sink
>
(
args
...);
return
details
::
registry
::
instance
().
create
(
logger_name
,
{
sink
});
}
template
<
class
It
>
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
)
{
return
details
::
registry
::
instance
().
create
(
logger_name
,
sinks_begin
,
sinks_end
);
}
inline
void
spdlog
::
set_formatter
(
spdlog
::
formatter_ptr
f
)
{
details
::
registry
::
instance
().
formatter
(
f
);
}
inline
void
spdlog
::
set_pattern
(
const
std
::
string
&
format_string
)
{
return
details
::
registry
::
instance
().
set_pattern
(
format_string
);
}
inline
void
spdlog
::
set_level
(
level
::
level_enum
log_level
)
{
return
details
::
registry
::
instance
().
set_level
(
log_level
);
}
inline
void
spdlog
::
stop
()
{
return
details
::
registry
::
instance
().
stop_all
();
}
include/sp
it
log/details/stack_buf.h
→
include/sp
d
log/details/stack_buf.h
View file @
c7b8c762
...
...
@@ -7,7 +7,7 @@
// Fast memory storage on the stack when possible or in std::vector
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
...
...
@@ -108,4 +108,4 @@ private:
};
}
}
//namespace sp
it
log { namespace details {
}
//namespace sp
d
log { namespace details {
include/sp
it
log/formatter.h
→
include/sp
d
log/formatter.h
View file @
c7b8c762
#pragma once
#include "details/log_msg.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
{
class
flag_formatter
;
...
...
@@ -29,5 +29,5 @@ private:
};
}
#include "
./
details/pattern_formatter_impl.h"
#include "details/pattern_formatter_impl.h"
include/sp
it
log/logger.h
→
include/sp
d
log/logger.h
View file @
c7b8c762
...
...
@@ -15,7 +15,7 @@
#include "sinks/base_sink.h"
#include "common.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
details
...
...
@@ -31,7 +31,7 @@ public:
template
<
class
It
>
logger
(
const
std
::
string
&
name
,
const
It
&
begin
,
const
It
&
end
);
void
set_
format
(
const
std
::
string
&
);
void
set_
pattern
(
const
std
::
string
&
);
void
set_formatter
(
formatter_ptr
);
formatter_ptr
get_formatter
()
const
;
...
...
@@ -45,7 +45,10 @@ public:
const
std
::
string
&
name
()
const
;
bool
should_log
(
level
::
level_enum
)
const
;
void
stop_logging
();
template
<
typename
...
Args
>
details
::
line_logger
log
(
level
::
level_enum
lvl
,
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
log
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
trace
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
debug
(
const
Args
&
...
args
);
template
<
typename
...
Args
>
details
::
line_logger
info
(
const
Args
&
...
args
);
...
...
@@ -67,35 +70,20 @@ private:
};
//
// Registry functions for easy loggers creation and retrieval
// example
// auto console_logger = spitlog::create("my_logger", spitlog::sinks<stdout_sink_mt>);
// auto same_logger = spitlog::get("my_logger");
// auto file_logger = c11
//
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
name
);
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
);
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spitlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
);
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
);
void
set_formatter
(
formatter_ptr
f
);
void
set_format
(
const
std
::
string
&
format_string
);
}
//
// Trace & debug macros
//
#ifdef FFLOG_ENABLE_TRACE
#define FFLOG_TRACE(logger, ...) logger->log(sp
it
log::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
#define FFLOG_TRACE(logger, ...) logger->log(sp
d
log::level::TRACE, __FILE__, " #", __LINE__,": " __VA_ARGS__)
#else
#define FFLOG_TRACE(logger, ...) {}
#endif
#ifdef FFLOG_ENABLE_DEBUG
#define FFLOG_DEBUG(logger, ...) logger->log(sp
it
log::level::DEBUG, __VA_ARGS__)
#define FFLOG_DEBUG(logger, ...) logger->log(sp
d
log::level::DEBUG, __VA_ARGS__)
#else
#define FFLOG_DEBUG(logger, ...) {}
#endif
...
...
include/sp
it
log/sinks/async_sink.h
→
include/sp
d
log/sinks/async_sink.h
View file @
c7b8c762
...
...
@@ -13,7 +13,7 @@
#include<iostream>
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
@@ -53,26 +53,26 @@ private:
///////////////////////////////////////////////////////////////////////////////
// async_sink class implementation
///////////////////////////////////////////////////////////////////////////////
inline
sp
it
log
::
sinks
::
async_sink
::
async_sink
(
const
q_type
::
size_type
max_queue_size
)
inline
sp
d
log
::
sinks
::
async_sink
::
async_sink
(
const
q_type
::
size_type
max_queue_size
)
:
_sinks
(),
_active
(
true
),
_q
(
max_queue_size
),
_back_thread
(
&
async_sink
::
_thread_loop
,
this
)
{}
inline
sp
it
log
::
sinks
::
async_sink
::~
async_sink
()
inline
sp
d
log
::
sinks
::
async_sink
::~
async_sink
()
{
_shutdown
();
}
inline
void
sp
it
log
::
sinks
::
async_sink
::
_sink_it
(
const
details
::
log_msg
&
msg
)
inline
void
sp
d
log
::
sinks
::
async_sink
::
_sink_it
(
const
details
::
log_msg
&
msg
)
{
if
(
!
_active
)
return
;
_q
.
push
(
msg
);
}
inline
void
sp
it
log
::
sinks
::
async_sink
::
_thread_loop
()
inline
void
sp
d
log
::
sinks
::
async_sink
::
_thread_loop
()
{
static
std
::
chrono
::
seconds
pop_timeout
{
1
};
while
(
_active
)
...
...
@@ -90,27 +90,27 @@ inline void spitlog::sinks::async_sink::_thread_loop()
}
}
inline
void
sp
itlog
::
sinks
::
async_sink
::
add_sink
(
spit
log
::
sink_ptr
s
)
inline
void
sp
dlog
::
sinks
::
async_sink
::
add_sink
(
spd
log
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
_sinks
.
push_back
(
s
);
}
inline
void
sp
itlog
::
sinks
::
async_sink
::
remove_sink
(
spit
log
::
sink_ptr
s
)
inline
void
sp
dlog
::
sinks
::
async_sink
::
remove_sink
(
spd
log
::
sink_ptr
s
)
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
_sinks
.
erase
(
std
::
remove
(
_sinks
.
begin
(),
_sinks
.
end
(),
s
),
_sinks
.
end
());
}
inline
sp
itlog
::
sinks
::
async_sink
::
q_type
&
spit
log
::
sinks
::
async_sink
::
q
()
inline
sp
dlog
::
sinks
::
async_sink
::
q_type
&
spd
log
::
sinks
::
async_sink
::
q
()
{
return
_q
;
}
inline
void
sp
it
log
::
sinks
::
async_sink
::
shutdown
(
const
std
::
chrono
::
milliseconds
&
timeout
)
inline
void
sp
d
log
::
sinks
::
async_sink
::
shutdown
(
const
std
::
chrono
::
milliseconds
&
timeout
)
{
if
(
timeout
>
std
::
chrono
::
milliseconds
::
zero
())
{
...
...
@@ -124,7 +124,7 @@ inline void spitlog::sinks::async_sink::shutdown(const std::chrono::milliseconds
}
inline
void
sp
it
log
::
sinks
::
async_sink
::
_shutdown
()
inline
void
sp
d
log
::
sinks
::
async_sink
::
_shutdown
()
{
std
::
lock_guard
<
std
::
mutex
>
guard
(
_mutex
);
if
(
_active
)
...
...
include/sp
it
log/sinks/base_sink.h
→
include/sp
d
log/sinks/base_sink.h
View file @
c7b8c762
...
...
@@ -14,7 +14,7 @@
#include "../details/log_msg.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
include/sp
it
log/sinks/file_sinks.h
→
include/sp
d
log/sinks/file_sinks.h
View file @
c7b8c762
...
...
@@ -10,7 +10,7 @@
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
@@ -159,7 +159,7 @@ private:
using
namespace
std
::
chrono
;
auto
now
=
system_clock
::
now
();
time_t
tnow
=
std
::
chrono
::
system_clock
::
to_time_t
(
now
);
tm
date
=
sp
it
log
::
details
::
os
::
localtime
(
tnow
);
tm
date
=
sp
d
log
::
details
::
os
::
localtime
(
tnow
);
date
.
tm_hour
=
date
.
tm_min
=
date
.
tm_sec
=
0
;
auto
midnight
=
std
::
chrono
::
system_clock
::
from_time_t
(
std
::
mktime
(
&
date
));
return
system_clock
::
time_point
(
midnight
+
hours
(
24
));
...
...
@@ -168,8 +168,8 @@ private:
//Create filename for the form basename.YYYY-MM-DD.extension
static
std
::
string
calc_filename
(
const
std
::
string
&
basename
,
const
std
::
string
&
extension
)
{
std
::
tm
tm
=
sp
it
log
::
details
::
os
::
localtime
();
fast_oss
oss
;
std
::
tm
tm
=
sp
d
log
::
details
::
os
::
localtime
();
details
::
fast_oss
oss
;
oss
<<
basename
<<
'.'
;
oss
<<
tm
.
tm_year
+
1900
<<
'-'
<<
std
::
setw
(
2
)
<<
std
::
setfill
(
'0'
)
<<
tm
.
tm_mon
+
1
<<
'-'
<<
tm
.
tm_mday
;
oss
<<
'.'
<<
extension
;
...
...
include/sp
it
log/sinks/null_sink.h
→
include/sp
d
log/sinks/null_sink.h
View file @
c7b8c762
...
...
@@ -4,7 +4,7 @@
#include "../details/null_mutex.h"
namespace
sp
it
log
{
namespace
sp
d
log
{
namespace
sinks
{
template
<
class
Mutex
>
...
...
include/sp
it
log/sinks/ostream_sink.h
→
include/sp
d
log/sinks/ostream_sink.h
View file @
c7b8c762
...
...
@@ -7,7 +7,7 @@
#include "../details/null_mutex.h"
#include "./base_sink.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
include/sp
it
log/sinks/sink.h
→
include/sp
d
log/sinks/sink.h
View file @
c7b8c762
...
...
@@ -2,7 +2,7 @@
#include "../details/log_msg.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
include/sp
it
log/sinks/stdout_sinks.h
→
include/sp
d
log/sinks/stdout_sinks.h
View file @
c7b8c762
...
...
@@ -5,7 +5,7 @@
#include "./ostream_sink.h"
#include "../details/null_mutex.h"
namespace
sp
it
log
namespace
sp
d
log
{
namespace
sinks
{
...
...
include/spdlog/spdlog.h
0 → 100644
View file @
c7b8c762
//
// This is spdlog - an extremely fast and easy to use c++11 logging library
//
// example code (create multi threaded daily logger):
// auto my_logger = spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
// ..
// auto mylog = spdlog::get("mylog");
// mylog->info("Hello logger.", "This is message number", 1, "!!") ;
// mylog->info() << "std streams are also supprted: " << std::hex << 255;
// see example.cpp for more examples
#pragma once
#include "logger.h"
#include "details/registry.h"
namespace
spdlog
{
// Return an existing logger or nullptr if a logger with such name doesn't exist.
// Examples:
//
// spdlog::get("mylog")->info("Hello");
// auto logger = spdlog::get("mylog");
// logger.info("This is another message" , x, y, z);
// logger.info() << "This is another message" << x << y << z;
std
::
shared_ptr
<
logger
>
get
(
const
std
::
string
&
name
);
// Example:
// auto logger = spdlog::create("mylog", {sink1, sink2});
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
sinks_init_list
sinks
);
// Example (create a logger with daily rotating file):
// using namespace spdlog::sinks;
// spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename", "txt");
template
<
typename
Sink
,
typename
...
Args
>
std
::
shared_ptr
<
spdlog
::
logger
>
create
(
const
std
::
string
&
logger_name
,
const
Args
&
...
args
);
// Example:
// using namespace spdlog::sinks;
// std::vector<spdlog::sink_ptr> mySinks;
// mySinks.push_back(std::make_shared<rotating_file_sink_mt>("filename", "txt", 1024 * 1024 * 5, 10));
// mySinks.push_back(std::make_shared<stdout_sink_mt>());
// spdlog::create("mylog", mySinks.begin(), mySinks.end());
template
<
class
It
>
std
::
shared_ptr
<
logger
>
create
(
const
std
::
string
&
logger_name
,
const
It
&
sinks_begin
,
const
It
&
sinks_end
);
// Set global formatting
// Example:
// spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %t");
void
set_pattern
(
const
std
::
string
&
format_string
);
// Set global formatter object
void
set_formatter
(
formatter_ptr
f
);
//Set global active logging level
void
set_level
(
level
::
level_enum
log_level
);
//Stop all loggers
void
stop
();
//
// Trace macro to turn on/off at compile time
// Example: SPDLOG_TRACE(my_logger, "Some trace message");
//
#ifdef _DEBUG
#define SPDLOG_TRACE(logger, ...) logger->log(__FILE__, " #", __LINE__,": " __VA_ARGS__)
#else
#define SPDLOG_TRACE(logger, ...) {}
#endif
}
#include "details/spdlog_impl.h"
\ 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