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
1d86803e
Commit
1d86803e
authored
Jun 19, 2019
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix #1116
parent
b12c1916
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
59 deletions
+154
-59
async.h
include/spdlog/async.h
+1
-2
stdout_sinks-inl.h
include/spdlog/sinks/stdout_sinks-inl.h
+89
-0
stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+39
-57
spdlog.cpp
src/spdlog.cpp
+25
-0
No files found.
include/spdlog/async.h
View file @
1d86803e
...
...
@@ -18,7 +18,6 @@
#include "spdlog/details/registry.h"
#include "spdlog/details/thread_pool.h"
#include <memory>
#include <mutex>
#include <functional>
...
...
@@ -81,7 +80,7 @@ inline void init_thread_pool(size_t q_size, size_t thread_count, std::function<v
// set global thread pool.
inline
void
init_thread_pool
(
size_t
q_size
,
size_t
thread_count
)
{
init_thread_pool
(
q_size
,
thread_count
,
[]{});
init_thread_pool
(
q_size
,
thread_count
,
[]
{});
}
// get the global thread pool.
...
...
include/spdlog/sinks/stdout_sinks-inl.h
0 → 100644
View file @
1d86803e
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
#pragma once
#ifndef SPDLOG_HEADER_ONLY
#include "spdlog/sinks/stdout_sinks.h"
#endif
namespace
spdlog
{
namespace
sinks
{
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
stdout_sink_base
<
ConsoleMutex
>::
stdout_sink_base
(
FILE
*
file
)
:
mutex_
(
ConsoleMutex
::
mutex
())
,
file_
(
file
)
{}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
log
(
const
details
::
log_msg
&
msg
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fmt
::
memory_buffer
formatted
;
formatter_
->
format
(
msg
,
formatted
);
fwrite
(
formatted
.
data
(),
sizeof
(
char
),
formatted
.
size
(),
file_
);
fflush
(
file_
);
// flush every line to terminal
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
flush
()
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
fflush
(
file_
);
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
set_pattern
(
const
std
::
string
&
pattern
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
));
}
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
void
stdout_sink_base
<
ConsoleMutex
>::
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
move
(
sink_formatter
);
}
// stdout sink
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
stdout_sink
<
ConsoleMutex
>::
stdout_sink
()
:
stdout_sink_base
<
ConsoleMutex
>
(
stdout
)
{}
// stderr sink
template
<
typename
ConsoleMutex
>
SPDLOG_INLINE
stderr_sink
<
ConsoleMutex
>::
stderr_sink
()
:
stdout_sink_base
<
ConsoleMutex
>
(
stderr
)
{}
}
// namespace sinks
// factory methods
template
<
typename
Factory
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stdout_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_sink_st
>
(
logger_name
);
}
template
<
typename
Factory
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
>
SPDLOG_INLINE
std
::
shared_ptr
<
logger
>
stderr_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_sink_st
>
(
logger_name
);
}
}
// namespace spdlog
include/spdlog/sinks/stdout_sinks.h
View file @
1d86803e
...
...
@@ -16,82 +16,64 @@ namespace spdlog {
namespace
sinks
{
template
<
typename
TargetStream
,
typename
ConsoleMutex
>
class
stdout_sink
final
:
public
sink
template
<
typename
ConsoleMutex
>
class
stdout_sink
_base
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutex
::
mutex_t
;
stdout_sink
()
:
mutex_
(
ConsoleMutex
::
mutex
())
,
file_
(
TargetStream
::
stream
())
{}
~
stdout_sink
()
override
=
default
;
stdout_sink
(
const
stdout_sink
&
other
)
=
delete
;
stdout_sink
&
operator
=
(
const
stdout_sink
&
other
)
=
delete
;
void
log
(
const
details
::
log_msg
&
msg
)
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
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
(
file_
);
}
void
set_pattern
(
const
std
::
string
&
pattern
)
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
unique_ptr
<
spdlog
::
formatter
>
(
new
pattern_formatter
(
pattern
));
}
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
mutex_
);
formatter_
=
std
::
move
(
sink_formatter
);
}
explicit
stdout_sink_base
(
FILE
*
file
);
~
stdout_sink_base
()
override
=
default
;
stdout_sink_base
(
const
stdout_sink_base
&
other
)
=
delete
;
stdout_sink_base
&
operator
=
(
const
stdout_sink_base
&
other
)
=
delete
;
void
log
(
const
details
::
log_msg
&
msg
)
override
;
void
flush
()
override
;
void
set_pattern
(
const
std
::
string
&
pattern
)
override
;
void
set_formatter
(
std
::
unique_ptr
<
spdlog
::
formatter
>
sink_formatter
)
override
;
private
:
mutex_t
&
mutex_
;
FILE
*
file_
;
};
using
stdout_sink_mt
=
stdout_sink
<
details
::
console_stdout
,
details
::
console_mutex
>
;
using
stdout_sink_st
=
stdout_sink
<
details
::
console_stdout
,
details
::
console_nullmutex
>
;
template
<
typename
ConsoleMutex
>
class
stdout_sink
:
public
stdout_sink_base
<
ConsoleMutex
>
{
public
:
stdout_sink
();
};
template
<
typename
ConsoleMutex
>
class
stderr_sink
:
public
stdout_sink_base
<
ConsoleMutex
>
{
public
:
stderr_sink
();
};
using
stdout_sink_mt
=
stdout_sink
<
details
::
console_mutex
>
;
using
stdout_sink_st
=
stdout_sink
<
details
::
console_nullmutex
>
;
using
stderr_sink_mt
=
std
out_sink
<
details
::
console_stderr
,
details
::
console_mutex
>
;
using
stderr_sink_st
=
std
out_sink
<
details
::
console_stderr
,
details
::
console_nullmutex
>
;
using
stderr_sink_mt
=
std
err_sink
<
details
::
console_mutex
>
;
using
stderr_sink_st
=
std
err_sink
<
details
::
console_nullmutex
>
;
}
// namespace sinks
// factory methods
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_sink_mt
>
(
logger_name
);
}
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
);
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stdout_sink_st
>
(
logger_name
);
}
std
::
shared_ptr
<
logger
>
stdout_logger_st
(
const
std
::
string
&
logger_name
);
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_sink_mt
>
(
logger_name
);
}
std
::
shared_ptr
<
logger
>
stderr_logger_mt
(
const
std
::
string
&
logger_name
);
template
<
typename
Factory
=
spdlog
::
synchronous_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
sinks
::
stderr_sink_st
>
(
logger_name
);
}
std
::
shared_ptr
<
logger
>
stderr_logger_st
(
const
std
::
string
&
logger_name
);
}
// namespace spdlog
#ifdef SPDLOG_HEADER_ONLY
#include "stdout_sinks-inl.h"
#endif
src/spdlog.cpp
View file @
1d86803e
...
...
@@ -61,6 +61,7 @@ template class spdlog::sinks::ansicolor_stderr_sink<spdlog::details::console_mut
template
class
spdlog
::
sinks
::
ansicolor_stderr_sink
<
spdlog
::
details
::
console_nullmutex
>
;
#endif
// factory methods for color sinks
#include "spdlog/sinks/stdout_color_sinks-inl.h"
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_color_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
...
...
@@ -76,6 +77,30 @@ template std::shared_ptr<spdlog::logger> spdlog::stdout_color_st<spdlog::async_f
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_color_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
,
color_mode
mode
);
// stdout/stderr sinks
#include "spdlog/sinks/stdout_sinks-inl.h"
template
class
spdlog
::
sinks
::
stdout_sink_base
<
spdlog
::
details
::
console_mutex
>
;
template
class
spdlog
::
sinks
::
stdout_sink_base
<
spdlog
::
details
::
console_nullmutex
>
;
template
class
spdlog
::
sinks
::
stdout_sink
<
spdlog
::
details
::
console_mutex
>
;
template
class
spdlog
::
sinks
::
stdout_sink
<
spdlog
::
details
::
console_nullmutex
>
;
template
class
spdlog
::
sinks
::
stderr_sink
<
spdlog
::
details
::
console_mutex
>
;
template
class
spdlog
::
sinks
::
stderr_sink
<
spdlog
::
details
::
console_nullmutex
>
;
// factory methods
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stdout_logger_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_mt
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_st
<
spdlog
::
synchronous_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_mt
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
template
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
stderr_logger_st
<
spdlog
::
async_factory
>
(
const
std
::
string
&
logger_name
);
// Slightly modified version of fmt lib's format.cc source file.
// Copyright (c) 2012 - 2016, Victor Zverovich
// All rights reserved.
...
...
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