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
9dc44c39
Commit
9dc44c39
authored
Jul 07, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bugs in stdout_sinks and in msvc
parent
bde4c714
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
59 additions
and
76 deletions
+59
-76
Makefile
example/Makefile
+1
-1
example.cpp
example/example.cpp
+3
-3
fmt_helper.h
include/spdlog/details/fmt_helper.h
+4
-0
pattern_formatter_impl.h
include/spdlog/details/pattern_formatter_impl.h
+6
-6
registry.h
include/spdlog/details/registry.h
+3
-3
thread_pool.h
include/spdlog/details/thread_pool.h
+8
-8
formatter.h
include/spdlog/formatter.h
+0
-2
android_sink.h
include/spdlog/sinks/android_sink.h
+2
-2
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+5
-5
msvc_sink.h
include/spdlog/sinks/msvc_sink.h
+5
-2
sink.h
include/spdlog/sinks/sink.h
+1
-0
stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+16
-12
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+5
-5
windebug_sink.h
include/spdlog/sinks/windebug_sink.h
+0
-27
No files found.
example/Makefile
View file @
9dc44c39
CXX
=
g++
CXX_FLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c++11
-pthread
-I
../include
CXX_FLAGS
=
-Wall
-Wextra
-pedantic
-std
=
c++11
-pthread
-I
../include
-fmax-errors
=
1
CXX_RELEASE_FLAGS
=
-O3
-march
=
native
CXX_DEBUG_FLAGS
=
-g
...
...
example/example.cpp
View file @
9dc44c39
...
...
@@ -55,16 +55,16 @@ int main(int, char *[])
}
}
#include "spdlog/sinks/stdout_
color_
sinks.h" // or "/sinks/stdout_sinks.h" if no colors needed
#include "spdlog/sinks/stdout_sinks.h" // or "/sinks/stdout_sinks.h" if no colors needed
void
stdout_example
()
{
// create color multi threaded logger
auto
console
=
spdlog
::
stdout_
colo
r_mt
(
"console"
);
auto
console
=
spdlog
::
stdout_
logge
r_mt
(
"console"
);
console
->
info
(
"Welcome to spdlog!"
);
console
->
error
(
"Some error message with arg: {}"
,
1
);
auto
err_logger
=
spdlog
::
stderr_
colo
r_mt
(
"error_logger"
);
auto
err_logger
=
spdlog
::
stderr_
logge
r_mt
(
"error_logger"
);
err_logger
->
error
(
"Some error message"
);
// Formatting examples
console
->
warn
(
"Easy padding in numbers like {:08d}"
,
12
);
...
...
include/spdlog/details/fmt_helper.h
View file @
9dc44c39
...
...
@@ -88,6 +88,10 @@ inline void pad3(int n, fmt::memory_buffer &dest)
inline
void
pad6
(
size_t
n
,
fmt
::
memory_buffer
&
dest
)
{
// todo: maybe replace this implementation with
// pad3(n / 1000, dest);
// pad3(n % 1000, dest);
if
(
n
>
99999
)
{
append_int
(
n
,
dest
);
...
...
include/spdlog/details/pattern_formatter_impl.h
View file @
9dc44c39
...
...
@@ -533,7 +533,7 @@ public:
,
last_log_secs_
(
0
)
{
std
::
memset
(
&
cached_tm_
,
0
,
sizeof
(
cached_tm_
));
compile_pattern
(
pattern
);
compile_pattern
_
(
pattern
);
}
pattern_formatter
(
const
pattern_formatter
&
)
=
default
;
...
...
@@ -544,7 +544,7 @@ public:
auto
secs
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
seconds
>
(
msg
.
time
.
time_since_epoch
());
if
(
secs
!=
last_log_secs_
)
{
cached_tm_
=
get_time
(
msg
);
cached_tm_
=
get_time
_
(
msg
);
last_log_secs_
=
secs
;
}
#endif
...
...
@@ -563,7 +563,7 @@ private:
std
::
chrono
::
seconds
last_log_secs_
;
std
::
vector
<
std
::
unique_ptr
<
details
::
flag_formatter
>>
formatters_
;
std
::
tm
get_time
(
const
details
::
log_msg
&
msg
)
std
::
tm
get_time
_
(
const
details
::
log_msg
&
msg
)
{
if
(
pattern_time_
==
pattern_time_type
::
local
)
{
...
...
@@ -572,7 +572,7 @@ private:
return
details
::
os
::
gmtime
(
log_clock
::
to_time_t
(
msg
.
time
));
}
void
handle_flag
(
char
flag
)
void
handle_flag
_
(
char
flag
)
{
switch
(
flag
)
{
...
...
@@ -717,7 +717,7 @@ private:
}
}
void
compile_pattern
(
const
std
::
string
&
pattern
)
void
compile_pattern
_
(
const
std
::
string
&
pattern
)
{
auto
end
=
pattern
.
end
();
std
::
unique_ptr
<
details
::
aggregate_formatter
>
user_chars
;
...
...
@@ -732,7 +732,7 @@ private:
// if(
if
(
++
it
!=
end
)
{
handle_flag
(
*
it
);
handle_flag
_
(
*
it
);
}
else
{
...
...
include/spdlog/details/registry.h
View file @
9dc44c39
...
...
@@ -36,7 +36,7 @@ public:
{
std
::
lock_guard
<
Mutex
>
lock
(
mutex_
);
auto
logger_name
=
new_logger
->
name
();
throw_if_exists
(
logger_name
);
throw_if_exists
_
(
logger_name
);
loggers_
[
logger_name
]
=
new_logger
;
}
...
...
@@ -44,7 +44,7 @@ public:
{
std
::
lock_guard
<
Mutex
>
lock
(
mutex_
);
auto
logger_name
=
new_logger
->
name
();
throw_if_exists
(
logger_name
);
throw_if_exists
_
(
logger_name
);
// create default formatter if not exists
...
...
@@ -162,7 +162,7 @@ public:
private
:
registry_t
<
Mutex
>
()
=
default
;
void
throw_if_exists
(
const
std
::
string
&
logger_name
)
void
throw_if_exists
_
(
const
std
::
string
&
logger_name
)
{
if
(
loggers_
.
find
(
logger_name
)
!=
loggers_
.
end
())
{
...
...
include/spdlog/details/thread_pool.h
View file @
9dc44c39
...
...
@@ -95,7 +95,7 @@ public:
}
for
(
size_t
i
=
0
;
i
<
threads_n
;
i
++
)
{
threads_
.
emplace_back
(
std
::
bind
(
&
thread_pool
::
worker_loop
,
this
));
threads_
.
emplace_back
(
std
::
bind
(
&
thread_pool
::
worker_loop
_
,
this
));
}
}
...
...
@@ -106,7 +106,7 @@ public:
{
for
(
size_t
i
=
0
;
i
<
threads_
.
size
();
i
++
)
{
post_async_msg
(
async_msg
(
async_msg_type
::
terminate
),
async_overflow_policy
::
block_retry
);
post_async_msg
_
(
async_msg
(
async_msg_type
::
terminate
),
async_overflow_policy
::
block_retry
);
}
for
(
auto
&
t
:
threads_
)
...
...
@@ -123,12 +123,12 @@ public:
void
post_log
(
async_logger_ptr
&&
worker_ptr
,
details
::
log_msg
&&
msg
,
async_overflow_policy
overflow_policy
)
{
async_msg
async_m
(
std
::
forward
<
async_logger_ptr
>
(
worker_ptr
),
async_msg_type
::
log
,
std
::
forward
<
log_msg
>
(
msg
));
post_async_msg
(
std
::
move
(
async_m
),
overflow_policy
);
post_async_msg
_
(
std
::
move
(
async_m
),
overflow_policy
);
}
void
post_flush
(
async_logger_ptr
&&
worker_ptr
,
async_overflow_policy
overflow_policy
)
{
post_async_msg
(
async_msg
(
std
::
move
(
worker_ptr
),
async_msg_type
::
flush
),
overflow_policy
);
post_async_msg
_
(
async_msg
(
std
::
move
(
worker_ptr
),
async_msg_type
::
flush
),
overflow_policy
);
}
private
:
...
...
@@ -136,7 +136,7 @@ private:
std
::
vector
<
std
::
thread
>
threads_
;
void
post_async_msg
(
async_msg
&&
new_msg
,
async_overflow_policy
overflow_policy
)
void
post_async_msg
_
(
async_msg
&&
new_msg
,
async_overflow_policy
overflow_policy
)
{
if
(
overflow_policy
==
async_overflow_policy
::
block_retry
)
{
...
...
@@ -148,14 +148,14 @@ private:
}
}
void
worker_loop
()
void
worker_loop
_
()
{
while
(
process_next_msg
())
{};
while
(
process_next_msg
_
())
{};
}
// process next message in the queue
// return true if this thread should still be active (while no terminate msg was received)
bool
process_next_msg
()
bool
process_next_msg
_
()
{
async_msg
incoming_async_msg
;
bool
dequeued
=
q_
.
dequeue_for
(
incoming_async_msg
,
std
::
chrono
::
seconds
(
10
));
...
...
include/spdlog/formatter.h
View file @
9dc44c39
...
...
@@ -17,5 +17,3 @@ public:
virtual
void
format
(
const
details
::
log_msg
&
msg
,
fmt
::
memory_buffer
&
dest
)
=
0
;
};
}
// namespace spdlog
#include "details/pattern_formatter_impl.h"
include/spdlog/sinks/android_sink.h
View file @
9dc44c39
...
...
@@ -38,7 +38,7 @@ public:
void
log
(
const
details
::
log_msg
&
msg
)
override
{
const
android_LogPriority
priority
=
convert_to_android
(
msg
.
level
);
const
android_LogPriority
priority
=
convert_to_android
_
(
msg
.
level
);
fmt
::
memory_buffer
formatted
;
if
(
use_raw_msg_
)
{
...
...
@@ -70,7 +70,7 @@ public:
void
flush
()
override
{}
private
:
static
android_LogPriority
convert_to_android
(
spdlog
::
level
::
level_enum
level
)
static
android_LogPriority
convert_to_android
_
(
spdlog
::
level
::
level_enum
level
)
{
switch
(
level
)
{
...
...
include/spdlog/sinks/ansicolor_sink.h
View file @
9dc44c39
...
...
@@ -5,9 +5,9 @@
#pragma once
#include "spdlog/details/console_globals.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/os.h"
#include "spdlog/details/console_globals.h"
#include <memory>
#include <mutex>
...
...
@@ -22,14 +22,14 @@ namespace sinks {
* of the message.
* If no color terminal detected, omit the escape codes.
*/
template
<
class
StreamTrait
,
class
ConsoleMutexTrait
>
template
<
class
TargetStream
,
class
ConsoleMutex
>
class
ansicolor_sink
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutex
Trait
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
ansicolor_sink
()
:
target_file_
(
StreamTrait
::
stream
())
,
mutex_
(
ConsoleMutex
Trait
::
console_mutex
())
:
target_file_
(
TargetStream
::
stream
())
,
mutex_
(
ConsoleMutex
::
console_mutex
())
{
should_do_colors_
=
details
::
os
::
in_terminal
(
target_file_
)
&&
details
::
os
::
is_color_terminal
();
...
...
include/spdlog/sinks/msvc_sink.h
View file @
9dc44c39
...
...
@@ -27,9 +27,9 @@ public:
explicit
msvc_sink
()
{}
protected
:
void
sink_it_
(
const
details
::
log_msg
&
msg
)
override
void
sink_it_
(
const
details
::
log_msg
&
,
const
fmt
::
memory_buffer
&
formatted
)
override
{
OutputDebugStringA
(
msg
.
formatted
.
c_str
());
OutputDebugStringA
(
fmt
::
to_string
(
formatted
)
.
c_str
());
}
void
flush_
()
override
{}
...
...
@@ -38,6 +38,9 @@ protected:
using
msvc_sink_mt
=
msvc_sink
<
std
::
mutex
>
;
using
msvc_sink_st
=
msvc_sink
<
details
::
null_mutex
>
;
using
windebug_sink_mt
=
msvc_sink_mt
;
using
windebug_sink_st
=
msvc_sink_st
;
}
// namespace sinks
}
// namespace spdlog
...
...
include/spdlog/sinks/sink.h
View file @
9dc44c39
...
...
@@ -6,6 +6,7 @@
#pragma once
#include "spdlog/details/log_msg.h"
#include "spdlog/details/pattern_formatter_impl.h"
#include "spdlog/formatter.h"
namespace
spdlog
{
...
...
include/spdlog/sinks/stdout_sinks.h
View file @
9dc44c39
...
...
@@ -5,26 +5,27 @@
#pragma once
#include "spdlog/details/console_globals.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/traits.h"
#include "spdlog/spdlog.h"
#include <cstdio>
#include <memory>
#include <mutex>
#include <spdlog/details/console_globals.h>
namespace
spdlog
{
namespace
sinks
{
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
template
<
class
TargetStream
,
class
ConsoleMutex
>
class
stdout_sink
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutex
Trait
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
stdout_sink
()
:
mutex_
(
ConsoleMutex
Trait
::
console_mutex
())
,
file_
(
StdoutTrait
::
stream
())
:
mutex_
(
ConsoleMutex
::
console_mutex
())
,
file_
(
TargetStream
::
stream
())
{
}
~
stdout_sink
()
=
default
;
...
...
@@ -35,14 +36,16 @@ public:
void
log
(
const
details
::
log_msg
&
msg
)
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fwrite
(
msg
.
formatted
.
data
(),
sizeof
(
char
),
msg
.
formatted
.
size
(),
file_
);
fflush
(
StdoutTrait
::
stream
());
fmt
::
memory_buffer
formatted
;
formatter_
->
format
(
msg
,
formatted
);
fwrite
(
formatted
.
data
(),
sizeof
(
char
),
formatted
.
size
(),
file_
);
fflush
(
TargetStream
::
stream
());
}
void
flush
()
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fflush
(
StdoutTrait
::
stream
());
fflush
(
TargetStream
::
stream
());
}
private
:
...
...
@@ -50,10 +53,11 @@ private:
FILE
*
file_
;
};
using
stdout_sink_mt
=
stdout_sink
<
details
::
console_stdout_trait
,
details
::
console_mutex_trait
>
;
using
stdout_sink_st
=
stdout_sink
<
details
::
console_stdout_trait
,
details
::
console_null_mutex_trait
>
;
using
stderr_sink_mt
=
stdout_sink
<
details
::
console_stderr_trait
,
details
::
console_mutex_trait
>
;
using
stderr_sink_st
=
stdout_sink
<
details
::
console_stderr_trait
,
details
::
console_null_mutex_trait
>
;
using
stdout_sink_mt
=
stdout_sink
<
details
::
console_stdout_stream
,
details
::
console_global_mutex
>
;
using
stdout_sink_st
=
stdout_sink
<
details
::
console_stdout_stream
,
details
::
console_global_nullmutex
>
;
using
stderr_sink_mt
=
stdout_sink
<
details
::
console_stderr_stream
,
details
::
console_global_mutex
>
;
using
stderr_sink_st
=
stdout_sink
<
details
::
console_stderr_stream
,
details
::
console_global_nullmutex
>
;
}
// namespace sinks
...
...
include/spdlog/sinks/wincolor_sink.h
View file @
9dc44c39
...
...
@@ -7,8 +7,8 @@
#include "../fmt/fmt.h"
#include "spdlog/common.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/details/console_globals.h"
#include "spdlog/details/null_mutex.h"
#include "spdlog/sinks/sink.h"
#include <memory>
...
...
@@ -22,7 +22,7 @@ namespace sinks {
/*
* Windows color console sink. Uses WriteConsoleA to write to the console with colors
*/
template
<
class
HandleTrait
,
class
ConsoleMutexTrait
>
template
<
class
OutHandle
,
class
ConsoleMutex
>
class
wincolor_sink
:
public
sink
{
public
:
...
...
@@ -34,8 +34,8 @@ public:
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
()
:
out_handle_
(
HandleTrait
::
handle
())
,
mutex_
(
ConsoleMutex
Trait
::
console_mutex
())
:
out_handle_
(
OutHandle
::
handle
())
,
mutex_
(
ConsoleMutex
::
console_mutex
())
{
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
...
...
@@ -90,7 +90,7 @@ public:
}
private
:
using
mutex_t
=
typename
ConsoleMutex
Trait
::
mutex_t
;
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
// set color and return the orig console attributes (for resetting later)
WORD
set_console_attribs
(
WORD
attribs
)
{
...
...
include/spdlog/sinks/windebug_sink.h
deleted
100644 → 0
View file @
bde4c714
//
// Copyright(c) 2017 Alexander Dalshov.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once
#if defined(_WIN32)
#include "spdlog/sinks/msvc_sink.h"
namespace
spdlog
{
namespace
sinks
{
/*
* Windows debug sink (logging using OutputDebugStringA, synonym for msvc_sink)
*/
template
<
class
Mutex
>
using
windebug_sink
=
msvc_sink
<
Mutex
>
;
using
windebug_sink_mt
=
msvc_sink_mt
;
using
windebug_sink_st
=
msvc_sink_st
;
}
// namespace sinks
}
// namespace spdlog
#endif
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