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
e4d3eb64
Commit
e4d3eb64
authored
Apr 19, 2018
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Udpated example and spdlog.h
parent
0969118c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
499 additions
and
550 deletions
+499
-550
example.cpp
example/example.cpp
+15
-39
example.sln
example/example.sln
+1
-1
android_sink.h
include/spdlog/sinks/android_sink.h
+76
-65
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+126
-125
color_sinks.h
include/spdlog/sinks/color_sinks.h
+0
-12
file_sinks.h
include/spdlog/sinks/file_sinks.h
+0
-0
stdout_color_sinks.h
include/spdlog/sinks/stdout_color_sinks.h
+56
-0
stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+63
-38
syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+55
-47
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+106
-106
spdlog.h
include/spdlog/spdlog.h
+1
-111
tweakme.h
include/spdlog/tweakme.h
+0
-6
No files found.
example/example.cpp
View file @
e4d3eb64
...
...
@@ -11,19 +11,13 @@
#define SPDLOG_DEBUG_ON
#include "spdlog/color_logger.h"
//#include "spdlog/stdout_logger.h"
//#include "spdlog/async.h"
#include "spdlog/spdlog.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/file_sinks.h"
#include <iostream>
#include <memory>
void
async_example
();
void
syslog_example
();
void
android_example
();
void
user_defined_example
();
void
err_handler_example
();
...
...
@@ -31,23 +25,8 @@ namespace spd = spdlog;
int
main
(
int
,
char
*
[])
{
try
{
// Console logger with color
//spd::init_thread_pool(8192, 3);
auto
console1
=
spdlog
::
stdout_color_mt
(
"console111"
);
auto
console2
=
spdlog
::
stdout_color_mt
<>
(
"console2"
);
//auto console3 = spdlog::stdout_color_mt<spdlog::create_async>("console3");
for
(
int
i
=
0
;
i
<
10000
;
i
++
)
{
console1
->
info
(
111111
);
console2
->
warn
(
222222
);
}
spdlog
::
drop_all
();
return
0
;
{
auto
console
=
spdlog
::
stdout_color_st
(
"console"
);
console
->
info
(
"Welcome to spdlog!"
);
...
...
@@ -100,12 +79,7 @@ int main(int, char *[])
// Asynchronous logging is very fast..
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
async_example
();
// syslog example. linux/osx only
syslog_example
();
// android example. compile with NDK
android_example
();
// Log user-defined types example
user_defined_example
();
...
...
@@ -130,38 +104,40 @@ int main(int, char *[])
#include "spdlog/async.h"
void
async_example
()
{
auto
async_file
=
spd
::
basic_logger_mt
<
spdlog
::
create_async
>
(
"async_file_logger"
,
"logs/async_log.txt"
);
for
(
int
i
=
0
;
i
<
100
;
++
i
)
{
async_file
->
info
(
"Async message #{}"
,
i
);
}
}
//
optional change
thread pool settings *before* creating the logger:
// spdlog::init_thread_pool(
8192, 1);
// if not called a defaults are:
8192 queue size
and 1 worker thread.
//
you can also modify
thread pool settings *before* creating the logger:
// spdlog::init_thread_pool(
32768, 4); // queue with 32k of pre allocated items and 4 backing threads.
// if not called a defaults are:
preallocated 8192 queue items
and 1 worker thread.
}
// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#incude "spdlog/sinks/syslog_sink.h"
void
syslog_example
()
{
#ifdef SPDLOG_ENABLE_SYSLOG
std
::
string
ident
=
"spdlog-example"
;
auto
syslog_logger
=
spd
::
syslog_logger
(
"syslog"
,
ident
,
LOG_PID
);
syslog_logger
->
warn
(
"This is warning that will end up in syslog."
);
#endif
}
#endif
// Android example
#if defined(__ANDROID__)
#incude "spdlog/sinks/android_sink.h"
void
android_example
()
{
#if defined(__ANDROID__)
std
::
string
tag
=
"spdlog-android"
;
auto
android_logger
=
spd
::
android_logger
(
"android"
,
tag
);
android_logger
->
critical
(
"Use
\"
adb shell logcat
\"
to view this message."
);
#endif
}
#endif
// user defined types logging by implementing operator<<
struct
my_type
{
...
...
example/example.sln
View file @
e4d3eb64
...
...
@@ -58,7 +58,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sinks", "sinks", "{27D16BB9
..\include\spdlog\sinks\android_sink.h = ..\include\spdlog\sinks\android_sink.h
..\include\spdlog\sinks\ansicolor_sink.h = ..\include\spdlog\sinks\ansicolor_sink.h
..\include\spdlog\sinks\base_sink.h = ..\include\spdlog\sinks\base_sink.h
..\include\spdlog\
color_logger.h = ..\include\spdlog\color_logger
.h
..\include\spdlog\
sinks\stdout_color_sinks.h = ..\include\spdlog\sinks\stdout_color_sinks
.h
..\include\spdlog\sinks\dist_sink.h = ..\include\spdlog\sinks\dist_sink.h
..\include\spdlog\sinks\file_sinks.h = ..\include\spdlog\sinks\file_sinks.h
..\include\spdlog\sinks\msvc_sink.h = ..\include\spdlog\sinks\msvc_sink.h
...
...
include/spdlog/sinks/android_sink.h
View file @
e4d3eb64
...
...
@@ -21,71 +21,82 @@
#endif
namespace
spdlog
{
namespace
sinks
{
/*
* Android sink (logging using __android_log_write)
* __android_log_write is thread-safe. No lock is needed.
*/
class
android_sink
:
public
sink
{
public
:
explicit
android_sink
(
const
std
::
string
&
tag
=
"spdlog"
,
bool
use_raw_msg
=
false
)
:
_tag
(
tag
)
,
_use_raw_msg
(
use_raw_msg
)
{
}
void
log
(
const
details
::
log_msg
&
msg
)
override
{
const
android_LogPriority
priority
=
convert_to_android
(
msg
.
level
);
const
char
*
msg_output
=
(
_use_raw_msg
?
msg
.
raw
.
c_str
()
:
msg
.
formatted
.
c_str
());
// See system/core/liblog/logger_write.c for explanation of return value
int
ret
=
__android_log_write
(
priority
,
_tag
.
c_str
(),
msg_output
);
int
retry_count
=
0
;
while
((
ret
==
-
11
/*EAGAIN*/
)
&&
(
retry_count
<
SPDLOG_ANDROID_RETRIES
))
{
details
::
os
::
sleep_for_millis
(
5
);
ret
=
__android_log_write
(
priority
,
_tag
.
c_str
(),
msg_output
);
retry_count
++
;
}
if
(
ret
<
0
)
{
throw
spdlog_ex
(
"__android_log_write() failed"
,
ret
);
}
}
void
flush
()
override
{}
private
:
static
android_LogPriority
convert_to_android
(
spdlog
::
level
::
level_enum
level
)
{
switch
(
level
)
{
case
spdlog
:
:
level
::
trace
:
return
ANDROID_LOG_VERBOSE
;
case
spdlog
:
:
level
::
debug
:
return
ANDROID_LOG_DEBUG
;
case
spdlog
:
:
level
::
info
:
return
ANDROID_LOG_INFO
;
case
spdlog
:
:
level
::
warn
:
return
ANDROID_LOG_WARN
;
case
spdlog
:
:
level
::
err
:
return
ANDROID_LOG_ERROR
;
case
spdlog
:
:
level
::
critical
:
return
ANDROID_LOG_FATAL
;
default
:
return
ANDROID_LOG_DEFAULT
;
}
}
std
::
string
_tag
;
bool
_use_raw_msg
;
};
}
// namespace sinks
namespace
sinks
{
/*
* Android sink (logging using __android_log_write)
* __android_log_write is thread-safe. No lock is needed.
*/
class
android_sink
:
public
sink
{
public
:
explicit
android_sink
(
const
std
::
string
&
tag
=
"spdlog"
,
bool
use_raw_msg
=
false
)
:
_tag
(
tag
)
,
_use_raw_msg
(
use_raw_msg
)
{
}
void
log
(
const
details
::
log_msg
&
msg
)
override
{
const
android_LogPriority
priority
=
convert_to_android
(
msg
.
level
);
const
char
*
msg_output
=
(
_use_raw_msg
?
msg
.
raw
.
c_str
()
:
msg
.
formatted
.
c_str
());
// See system/core/liblog/logger_write.c for explanation of return value
int
ret
=
__android_log_write
(
priority
,
_tag
.
c_str
(),
msg_output
);
int
retry_count
=
0
;
while
((
ret
==
-
11
/*EAGAIN*/
)
&&
(
retry_count
<
SPDLOG_ANDROID_RETRIES
))
{
details
::
os
::
sleep_for_millis
(
5
);
ret
=
__android_log_write
(
priority
,
_tag
.
c_str
(),
msg_output
);
retry_count
++
;
}
if
(
ret
<
0
)
{
throw
spdlog_ex
(
"__android_log_write() failed"
,
ret
);
}
}
void
flush
()
override
{}
private
:
static
android_LogPriority
convert_to_android
(
spdlog
::
level
::
level_enum
level
)
{
switch
(
level
)
{
case
spdlog
:
:
level
::
trace
:
return
ANDROID_LOG_VERBOSE
;
case
spdlog
:
:
level
::
debug
:
return
ANDROID_LOG_DEBUG
;
case
spdlog
:
:
level
::
info
:
return
ANDROID_LOG_INFO
;
case
spdlog
:
:
level
::
warn
:
return
ANDROID_LOG_WARN
;
case
spdlog
:
:
level
::
err
:
return
ANDROID_LOG_ERROR
;
case
spdlog
:
:
level
::
critical
:
return
ANDROID_LOG_FATAL
;
default
:
return
ANDROID_LOG_DEFAULT
;
}
}
std
::
string
_tag
;
bool
_use_raw_msg
;
};
}
// namespace sinks
// Create and register android syslog logger
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
android_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
tag
=
"spdlog"
)
{
return
return
Factory
::
template
create
<
sinks
::
android_sink
>
(
logger_name
,
tag
);
}
}
// namespace spdlog
#endif
include/spdlog/sinks/ansicolor_sink.h
View file @
e4d3eb64
...
...
@@ -15,130 +15,131 @@
#include <mutex>
namespace
spdlog
{
namespace
sinks
{
/**
* This sink prefixes the output with an ANSI escape sequence color code depending on the severity
* of the message.
* If no color terminal detected, omit the escape codes.
*/
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
class
ansicolor_sink
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
ansicolor_sink
()
:
target_file_
(
StdoutTrait
::
stream
()),
_mutex
(
ConsoleMutexTrait
::
mutex
())
{
should_do_colors_
=
details
::
os
::
in_terminal
(
file
)
&&
details
::
os
::
is_color_terminal
();
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
colors_
[
level
::
warn
]
=
yellow
+
bold
;
colors_
[
level
::
err
]
=
red
+
bold
;
colors_
[
level
::
critical
]
=
bold
+
on_red
;
colors_
[
level
::
off
]
=
reset
;
}
~
ansicolor_sink
()
override
{
_flush
();
}
ansicolor_sink
(
const
ansicolor_sink
&
other
)
=
delete
;
ansicolor_sink
&
operator
=
(
const
ansicolor_sink
&
other
)
=
delete
;
void
set_color
(
level
::
level_enum
color_level
,
const
std
::
string
&
color
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
colors_
[
color_level
]
=
color
;
}
/// Formatting codes
const
std
::
string
reset
=
"
\033
[m"
;
const
std
::
string
bold
=
"
\033
[1m"
;
const
std
::
string
dark
=
"
\033
[2m"
;
const
std
::
string
underline
=
"
\033
[4m"
;
const
std
::
string
blink
=
"
\033
[5m"
;
const
std
::
string
reverse
=
"
\033
[7m"
;
const
std
::
string
concealed
=
"
\033
[8m"
;
const
std
::
string
clear_line
=
"
\033
[K"
;
// Foreground colors
const
std
::
string
black
=
"
\033
[30m"
;
const
std
::
string
red
=
"
\033
[31m"
;
const
std
::
string
green
=
"
\033
[32m"
;
const
std
::
string
yellow
=
"
\033
[33m"
;
const
std
::
string
blue
=
"
\033
[34m"
;
const
std
::
string
magenta
=
"
\033
[35m"
;
const
std
::
string
cyan
=
"
\033
[36m"
;
const
std
::
string
white
=
"
\033
[37m"
;
/// Background colors
const
std
::
string
on_black
=
"
\033
[40m"
;
const
std
::
string
on_red
=
"
\033
[41m"
;
const
std
::
string
on_green
=
"
\033
[42m"
;
const
std
::
string
on_yellow
=
"
\033
[43m"
;
const
std
::
string
on_blue
=
"
\033
[44m"
;
const
std
::
string
on_magenta
=
"
\033
[45m"
;
const
std
::
string
on_cyan
=
"
\033
[46m"
;
const
std
::
string
on_white
=
"
\033
[47m"
;
void
log
(
const
details
::
log_msg
&
msg
)
SPDLOG_FINAL
override
{
// Wrap the originally formatted message in color codes.
// If color is not supported in the terminal, log as is instead.
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
namespace
sinks
{
/**
* This sink prefixes the output with an ANSI escape sequence color code depending on the severity
* of the message.
* If no color terminal detected, omit the escape codes.
*/
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
class
ansicolor_sink
:
public
sink
{
// before color range
_print_range
(
msg
,
0
,
msg
.
color_range_start
);
// in color range
_print_ccode
(
colors_
[
msg
.
level
]);
_print_range
(
msg
,
msg
.
color_range_start
,
msg
.
color_range_end
);
_print_ccode
(
reset
);
// after color range
_print_range
(
msg
,
msg
.
color_range_end
,
msg
.
formatted
.
size
());
}
else
// no color
{
_print_range
(
msg
,
0
,
msg
.
formatted
.
size
());
}
fflush
(
target_file_
);
}
void
flush
()
SPDLOG_FINAL
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
fflush
(
target_file_
);
}
private
:
void
_print_ccode
(
const
std
::
string
&
color_code
)
{
fwrite
(
color_code
.
data
(),
sizeof
(
char
),
color_code
.
size
(),
target_file_
);
}
void
_print_range
(
const
details
::
log_msg
&
msg
,
size_t
start
,
size_t
end
)
{
fwrite
(
msg
.
formatted
.
data
()
+
start
,
sizeof
(
char
),
end
-
start
,
target_file_
);
}
FILE
*
target_file_
;
mutex_t
&
_mutex
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
std
::
string
,
level
::
level_hasher
>
colors_
;
};
using
ansicolor_stdout_sink_mt
=
ansicolor_sink
<
details
::
console_stdout_trait
,
details
::
console_mutex_trait
>
;
using
ansicolor_stdout_sink_st
=
ansicolor_sink
<
details
::
console_stdout_trait
,
details
::
console_null_mutex_trait
>
;
using
ansicolor_stderr_sink_mt
=
ansicolor_sink
<
details
::
console_stderr_trait
,
details
::
console_mutex_trait
>
;
using
ansicolor_stderr_sink_st
=
ansicolor_sink
<
details
::
console_stderr_trait
,
details
::
console_null_mutex_trait
>
;
}
// namespace sinks
public
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
ansicolor_sink
()
:
target_file_
(
StdoutTrait
::
stream
()),
_mutex
(
ConsoleMutexTrait
::
mutex
())
{
should_do_colors_
=
details
::
os
::
in_terminal
(
file
)
&&
details
::
os
::
is_color_terminal
();
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
colors_
[
level
::
warn
]
=
yellow
+
bold
;
colors_
[
level
::
err
]
=
red
+
bold
;
colors_
[
level
::
critical
]
=
bold
+
on_red
;
colors_
[
level
::
off
]
=
reset
;
}
~
ansicolor_sink
()
override
{
_flush
();
}
ansicolor_sink
(
const
ansicolor_sink
&
other
)
=
delete
;
ansicolor_sink
&
operator
=
(
const
ansicolor_sink
&
other
)
=
delete
;
void
set_color
(
level
::
level_enum
color_level
,
const
std
::
string
&
color
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
colors_
[
color_level
]
=
color
;
}
/// Formatting codes
const
std
::
string
reset
=
"
\033
[m"
;
const
std
::
string
bold
=
"
\033
[1m"
;
const
std
::
string
dark
=
"
\033
[2m"
;
const
std
::
string
underline
=
"
\033
[4m"
;
const
std
::
string
blink
=
"
\033
[5m"
;
const
std
::
string
reverse
=
"
\033
[7m"
;
const
std
::
string
concealed
=
"
\033
[8m"
;
const
std
::
string
clear_line
=
"
\033
[K"
;
// Foreground colors
const
std
::
string
black
=
"
\033
[30m"
;
const
std
::
string
red
=
"
\033
[31m"
;
const
std
::
string
green
=
"
\033
[32m"
;
const
std
::
string
yellow
=
"
\033
[33m"
;
const
std
::
string
blue
=
"
\033
[34m"
;
const
std
::
string
magenta
=
"
\033
[35m"
;
const
std
::
string
cyan
=
"
\033
[36m"
;
const
std
::
string
white
=
"
\033
[37m"
;
/// Background colors
const
std
::
string
on_black
=
"
\033
[40m"
;
const
std
::
string
on_red
=
"
\033
[41m"
;
const
std
::
string
on_green
=
"
\033
[42m"
;
const
std
::
string
on_yellow
=
"
\033
[43m"
;
const
std
::
string
on_blue
=
"
\033
[44m"
;
const
std
::
string
on_magenta
=
"
\033
[45m"
;
const
std
::
string
on_cyan
=
"
\033
[46m"
;
const
std
::
string
on_white
=
"
\033
[47m"
;
void
log
(
const
details
::
log_msg
&
msg
)
SPDLOG_FINAL
override
{
// Wrap the originally formatted message in color codes.
// If color is not supported in the terminal, log as is instead.
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
if
(
should_do_colors_
&&
msg
.
color_range_end
>
msg
.
color_range_start
)
{
// before color range
_print_range
(
msg
,
0
,
msg
.
color_range_start
);
// in color range
_print_ccode
(
colors_
[
msg
.
level
]);
_print_range
(
msg
,
msg
.
color_range_start
,
msg
.
color_range_end
);
_print_ccode
(
reset
);
// after color range
_print_range
(
msg
,
msg
.
color_range_end
,
msg
.
formatted
.
size
());
}
else
// no color
{
_print_range
(
msg
,
0
,
msg
.
formatted
.
size
());
}
fflush
(
target_file_
);
}
void
flush
()
SPDLOG_FINAL
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
fflush
(
target_file_
);
}
private
:
void
_print_ccode
(
const
std
::
string
&
color_code
)
{
fwrite
(
color_code
.
data
(),
sizeof
(
char
),
color_code
.
size
(),
target_file_
);
}
void
_print_range
(
const
details
::
log_msg
&
msg
,
size_t
start
,
size_t
end
)
{
fwrite
(
msg
.
formatted
.
data
()
+
start
,
sizeof
(
char
),
end
-
start
,
target_file_
);
}
FILE
*
target_file_
;
mutex_t
&
_mutex
;
bool
should_do_colors_
;
std
::
unordered_map
<
level
::
level_enum
,
std
::
string
,
level
::
level_hasher
>
colors_
;
};
using
ansicolor_stdout_sink_mt
=
ansicolor_sink
<
details
::
console_stdout_trait
,
details
::
console_mutex_trait
>
;
using
ansicolor_stdout_sink_st
=
ansicolor_sink
<
details
::
console_stdout_trait
,
details
::
console_null_mutex_trait
>
;
using
ansicolor_stderr_sink_mt
=
ansicolor_sink
<
details
::
console_stderr_trait
,
details
::
console_mutex_trait
>
;
using
ansicolor_stderr_sink_st
=
ansicolor_sink
<
details
::
console_stderr_trait
,
details
::
console_null_mutex_trait
>
;
}
// namespace sinks
}
// namespace spdlog
include/spdlog/sinks/color_sinks.h
deleted
100644 → 0
View file @
0969118c
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once
#ifdef _WIN32
#include "wincolor_sink.h"
#else
#include "ansicolor_sink.h"
#endif
include/spdlog/sinks/file_sinks.h
View file @
e4d3eb64
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/stdout_color_sinks.h
0 → 100644
View file @
e4d3eb64
//
// Copyright(c) 2018 spdlog
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
#pragma once
#include "../spdlog.h"
#ifdef _WIN32
#include "wincolor_sink.h"
#else
#include "ansicolor_sink.h"
#endif
namespace
{
using
namespace
spdlog
::
sinks
;
#ifdef _WIN32
using
stdout_color_sink_mt
=
wincolor_stdout_sink_mt
;
using
stdout_color_sink_st
=
wincolor_stdout_sink_st
;
using
stderr_color_sink_mt
=
wincolor_stderr_sink_mt
;
using
stderr_color_sink_st
=
wincolor_stderr_sink_st
;
#else
using
stdout_color_sink_mt
=
ansicolor_stdout_sink_mt
;
using
stdout_color_sink_st
=
ansicolor_stdout_sink_st
;
using
stderr_color_sink_mt
=
ansicolor_stderr_sink_mt
;
using
stderr_color_sink_st
=
ansicolor_stderr_sink_st
;
#endif
}
namespace
spdlog
{
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stdout_color_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stdout_color_sink_st
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stderr_color_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_color_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
createstderr_color_sink_mt
>
(
logger_name
);
}
}
\ No newline at end of file
include/spdlog/sinks/stdout_sinks.h
View file @
e4d3eb64
...
...
@@ -13,42 +13,67 @@
#include <mutex>
namespace
spdlog
{
namespace
sinks
{
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
class
stdout_sink
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
stdout_sink
()
:
_mutex
(
ConsoleMutexTrait
::
console_mutex
()),
_file
(
StdoutTrait
::
stream
())
{}
~
stdout_sink
()
=
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
);
fwrite
(
msg
.
formatted
.
data
(),
sizeof
(
char
),
msg
.
formatted
.
size
(),
_file
);
fflush
(
StdoutTrait
::
stream
());
}
void
flush
()
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
fflush
(
StdoutTrait
::
stream
());
}
private
:
typename
mutex_t
&
_mutex
;
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
>
;
}
// namespace sinks
namespace
sinks
{
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
class
stdout_sink
:
public
sink
{
public
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
stdout_sink
()
:
_mutex
(
ConsoleMutexTrait
::
console_mutex
()),
_file
(
StdoutTrait
::
stream
())
{}
~
stdout_sink
()
=
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
);
fwrite
(
msg
.
formatted
.
data
(),
sizeof
(
char
),
msg
.
formatted
.
size
(),
_file
);
fflush
(
StdoutTrait
::
stream
());
}
void
flush
()
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
fflush
(
StdoutTrait
::
stream
());
}
private
:
typename
mutex_t
&
_mutex
;
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
>
;
}
// namespace sinks
// factory methods
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stdout_color_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stdout_color_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_logger_mt
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stderr_color_sink_mt
>
(
logger_name
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stderr_logger_st
(
const
std
::
string
&
logger_name
)
{
return
Factory
::
template
create
<
stderr_logger_sink_mt
>
(
logger_name
);
}
}
// namespace spdlog
include/spdlog/sinks/syslog_sink.h
View file @
e4d3eb64
...
...
@@ -17,60 +17,68 @@
#include <syslog.h>
namespace
spdlog
{
namespace
sinks
{
/**
* Sink that write to syslog using the `syscall()` library call.
*
* Locking is not needed, as `syslog()` itself is thread-safe.
*/
class
syslog_sink
:
public
sink
{
public
:
//
syslog_sink
(
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
)
:
_ident
(
ident
)
{
_priorities
[
static_cast
<
size_t
>
(
level
::
trace
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
size_t
>
(
level
::
debug
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
size_t
>
(
level
::
info
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
size_t
>
(
level
::
warn
)]
=
LOG_WARNING
;
_priorities
[
static_cast
<
size_t
>
(
level
::
err
)]
=
LOG_ERR
;
_priorities
[
static_cast
<
size_t
>
(
level
::
critical
)]
=
LOG_CRIT
;
_priorities
[
static_cast
<
size_t
>
(
level
::
off
)]
=
LOG_INFO
;
namespace
sinks
{
/**
* Sink that write to syslog using the `syscall()` library call.
*
* Locking is not needed, as `syslog()` itself is thread-safe.
*/
class
syslog_sink
:
public
sink
{
public
:
//
syslog_sink
(
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
)
:
_ident
(
ident
)
{
_priorities
[
static_cast
<
size_t
>
(
level
::
trace
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
size_t
>
(
level
::
debug
)]
=
LOG_DEBUG
;
_priorities
[
static_cast
<
size_t
>
(
level
::
info
)]
=
LOG_INFO
;
_priorities
[
static_cast
<
size_t
>
(
level
::
warn
)]
=
LOG_WARNING
;
_priorities
[
static_cast
<
size_t
>
(
level
::
err
)]
=
LOG_ERR
;
_priorities
[
static_cast
<
size_t
>
(
level
::
critical
)]
=
LOG_CRIT
;
_priorities
[
static_cast
<
size_t
>
(
level
::
off
)]
=
LOG_INFO
;
// set ident to be program name if empty
::
openlog
(
_ident
.
empty
()
?
nullptr
:
_ident
.
c_str
(),
syslog_option
,
syslog_facility
);
}
// set ident to be program name if empty
::
openlog
(
_ident
.
empty
()
?
nullptr
:
_ident
.
c_str
(),
syslog_option
,
syslog_facility
);
}
~
syslog_sink
()
override
{
::
closelog
();
}
~
syslog_sink
()
override
{
::
closelog
();
}
syslog_sink
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
&
operator
=
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
(
const
syslog_sink
&
)
=
delete
;
syslog_sink
&
operator
=
(
const
syslog_sink
&
)
=
delete
;
void
log
(
const
details
::
log_msg
&
msg
)
override
{
::
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
msg
.
raw
.
str
().
c_str
());
}
void
log
(
const
details
::
log_msg
&
msg
)
override
{
::
syslog
(
syslog_prio_from_level
(
msg
),
"%s"
,
msg
.
raw
.
str
().
c_str
());
}
void
flush
()
override
{}
void
flush
()
override
{}
private
:
std
::
array
<
int
,
7
>
_priorities
;
// must store the ident because the man says openlog might use the pointer as is and not a string copy
const
std
::
string
_ident
;
private
:
std
::
array
<
int
,
7
>
_priorities
;
// must store the ident because the man says openlog might use the pointer as is and not a string copy
const
std
::
string
_ident
;
//
// Simply maps spdlog's log level to syslog priority level.
//
int
syslog_prio_from_level
(
const
details
::
log_msg
&
msg
)
const
{
return
_priorities
[
static_cast
<
size_t
>
(
msg
.
level
)];
}
};
}
// namespace sinks
//
// Simply maps spdlog's log level to syslog priority level.
//
int
syslog_prio_from_level
(
const
details
::
log_msg
&
msg
)
const
{
return
_priorities
[
static_cast
<
size_t
>
(
msg
.
level
)];
}
};
}
// namespace sinks
// Create and register a syslog logger
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
syslog_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facilty
=
(
1
<<
3
))
{
return
return
Factory
::
template
create
<
sinks
::
syslog_sink
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
}
}
// namespace spdlog
#endif
include/spdlog/sinks/wincolor_sink.h
View file @
e4d3eb64
...
...
@@ -18,111 +18,111 @@
#include <wincon.h>
namespace
spdlog
{
namespace
sinks
{
/*
* Windows color console sink. Uses WriteConsoleA to write to the console with colors
*/
template
<
class
HandleTrait
,
class
ConsoleMutexTrait
>
class
wincolor_sink
:
public
sink
{
public
:
const
WORD
BOLD
=
FOREGROUND_INTENSITY
;
const
WORD
RED
=
FOREGROUND_RED
;
const
WORD
GREEN
=
FOREGROUND_GREEN
;
const
WORD
CYAN
=
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
WHITE
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
()
:
out_handle_
(
HandleTrait
::
handle
()),
_mutex
(
ConsoleMutexTrait
::
console_mutex
())
{
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
colors_
[
level
::
info
]
=
GREEN
;
colors_
[
level
::
warn
]
=
YELLOW
|
BOLD
;
colors_
[
level
::
err
]
=
RED
|
BOLD
;
// red bold
colors_
[
level
::
critical
]
=
BACKGROUND_RED
|
WHITE
|
BOLD
;
// white bold on red background
colors_
[
level
::
off
]
=
0
;
}
~
wincolor_sink
()
override
{
this
->
flush
();
}
wincolor_sink
(
const
wincolor_sink
&
other
)
=
delete
;
wincolor_sink
&
operator
=
(
const
wincolor_sink
&
other
)
=
delete
;
// change the color for the given level
void
set_color
(
level
::
level_enum
level
,
WORD
color
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
colors_
[
level
]
=
color
;
}
void
log
(
const
details
::
log_msg
&
msg
)
SPDLOG_FINAL
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
if
(
msg
.
color_range_end
>
msg
.
color_range_start
)
namespace
sinks
{
/*
* Windows color console sink. Uses WriteConsoleA to write to the console with colors
*/
template
<
class
HandleTrait
,
class
ConsoleMutexTrait
>
class
wincolor_sink
:
public
sink
{
// before color range
_print_range
(
msg
,
0
,
msg
.
color_range_start
);
// in color range
auto
orig_attribs
=
set_console_attribs
(
colors_
[
msg
.
level
]);
_print_range
(
msg
,
msg
.
color_range_start
,
msg
.
color_range_end
);
::
SetConsoleTextAttribute
(
out_handle_
,
orig_attribs
);
// reset to orig colors
// after color range
_print_range
(
msg
,
msg
.
color_range_end
,
msg
.
formatted
.
size
());
}
else
// print without colors if color range is invalid
{
_print_range
(
msg
,
0
,
msg
.
formatted
.
size
());
}
}
void
flush
()
SPDLOG_FINAL
override
{
// windows console always flushed?
}
private
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
// set color and return the orig console attributes (for resetting later)
WORD
set_console_attribs
(
WORD
attribs
)
{
CONSOLE_SCREEN_BUFFER_INFO
orig_buffer_info
;
::
GetConsoleScreenBufferInfo
(
out_handle_
,
&
orig_buffer_info
);
WORD
back_color
=
orig_buffer_info
.
wAttributes
;
// retrieve the current background color
back_color
&=
static_cast
<
WORD
>
(
~
(
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
|
FOREGROUND_INTENSITY
));
// keep the background color unchanged
::
SetConsoleTextAttribute
(
out_handle_
,
attribs
|
back_color
);
return
orig_buffer_info
.
wAttributes
;
// return orig attribs
}
// print a range of formatted message to console
void
_print_range
(
const
details
::
log_msg
&
msg
,
size_t
start
,
size_t
end
)
{
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
::
WriteConsoleA
(
out_handle_
,
msg
.
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
}
HANDLE
out_handle_
;
mutex_t
&
_mutex
;
std
::
unordered_map
<
level
::
level_enum
,
WORD
,
level
::
level_hasher
>
colors_
;
};
using
wincolor_stdout_sink_mt
=
wincolor_sink
<
details
::
console_stdout_trait
,
details
::
console_mutex_trait
>
;
using
wincolor_stdout_sink_st
=
wincolor_sink
<
details
::
console_stdout_trait
,
details
::
console_null_mutex_trait
>
;
using
wincolor_stderr_sink_mt
=
wincolor_sink
<
details
::
console_stderr_trait
,
details
::
console_mutex_trait
>
;
using
wincolor_stderr_sink_st
=
wincolor_sink
<
details
::
console_stderr_trait
,
details
::
console_null_mutex_trait
>
;
}
// namespace sinks
public
:
const
WORD
BOLD
=
FOREGROUND_INTENSITY
;
const
WORD
RED
=
FOREGROUND_RED
;
const
WORD
GREEN
=
FOREGROUND_GREEN
;
const
WORD
CYAN
=
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
WHITE
=
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
;
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
()
:
out_handle_
(
HandleTrait
::
handle
()),
_mutex
(
ConsoleMutexTrait
::
console_mutex
())
{
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
colors_
[
level
::
info
]
=
GREEN
;
colors_
[
level
::
warn
]
=
YELLOW
|
BOLD
;
colors_
[
level
::
err
]
=
RED
|
BOLD
;
// red bold
colors_
[
level
::
critical
]
=
BACKGROUND_RED
|
WHITE
|
BOLD
;
// white bold on red background
colors_
[
level
::
off
]
=
0
;
}
~
wincolor_sink
()
override
{
this
->
flush
();
}
wincolor_sink
(
const
wincolor_sink
&
other
)
=
delete
;
wincolor_sink
&
operator
=
(
const
wincolor_sink
&
other
)
=
delete
;
// change the color for the given level
void
set_color
(
level
::
level_enum
level
,
WORD
color
)
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
colors_
[
level
]
=
color
;
}
void
log
(
const
details
::
log_msg
&
msg
)
SPDLOG_FINAL
override
{
std
::
lock_guard
<
mutex_t
>
lock
(
_mutex
);
if
(
msg
.
color_range_end
>
msg
.
color_range_start
)
{
// before color range
_print_range
(
msg
,
0
,
msg
.
color_range_start
);
// in color range
auto
orig_attribs
=
set_console_attribs
(
colors_
[
msg
.
level
]);
_print_range
(
msg
,
msg
.
color_range_start
,
msg
.
color_range_end
);
::
SetConsoleTextAttribute
(
out_handle_
,
orig_attribs
);
// reset to orig colors
// after color range
_print_range
(
msg
,
msg
.
color_range_end
,
msg
.
formatted
.
size
());
}
else
// print without colors if color range is invalid
{
_print_range
(
msg
,
0
,
msg
.
formatted
.
size
());
}
}
void
flush
()
SPDLOG_FINAL
override
{
// windows console always flushed?
}
private
:
using
mutex_t
=
typename
ConsoleMutexTrait
::
mutex_t
;
// set color and return the orig console attributes (for resetting later)
WORD
set_console_attribs
(
WORD
attribs
)
{
CONSOLE_SCREEN_BUFFER_INFO
orig_buffer_info
;
::
GetConsoleScreenBufferInfo
(
out_handle_
,
&
orig_buffer_info
);
WORD
back_color
=
orig_buffer_info
.
wAttributes
;
// retrieve the current background color
back_color
&=
static_cast
<
WORD
>
(
~
(
FOREGROUND_RED
|
FOREGROUND_GREEN
|
FOREGROUND_BLUE
|
FOREGROUND_INTENSITY
));
// keep the background color unchanged
::
SetConsoleTextAttribute
(
out_handle_
,
attribs
|
back_color
);
return
orig_buffer_info
.
wAttributes
;
// return orig attribs
}
// print a range of formatted message to console
void
_print_range
(
const
details
::
log_msg
&
msg
,
size_t
start
,
size_t
end
)
{
auto
size
=
static_cast
<
DWORD
>
(
end
-
start
);
::
WriteConsoleA
(
out_handle_
,
msg
.
formatted
.
data
()
+
start
,
size
,
nullptr
,
nullptr
);
}
HANDLE
out_handle_
;
mutex_t
&
_mutex
;
std
::
unordered_map
<
level
::
level_enum
,
WORD
,
level
::
level_hasher
>
colors_
;
};
using
wincolor_stdout_sink_mt
=
wincolor_sink
<
details
::
console_stdout_trait
,
details
::
console_mutex_trait
>
;
using
wincolor_stdout_sink_st
=
wincolor_sink
<
details
::
console_stdout_trait
,
details
::
console_null_mutex_trait
>
;
using
wincolor_stderr_sink_mt
=
wincolor_sink
<
details
::
console_stderr_trait
,
details
::
console_mutex_trait
>
;
using
wincolor_stderr_sink_st
=
wincolor_sink
<
details
::
console_stderr_trait
,
details
::
console_null_mutex_trait
>
;
}
// namespace sinks
}
// namespace spdlog
include/spdlog/spdlog.h
View file @
e4d3eb64
...
...
@@ -8,17 +8,9 @@
#pragma once
#include "details/registry.h"
#include "sinks/file_sinks.h"
#include "sinks/stdout_sinks.h"
#include "common.h"
#include "logger.h"
#ifdef __ANDROID__
#include "sinks/android_sink.h"
#endif
#include <chrono>
#include <functional>
#include <memory>
...
...
@@ -27,7 +19,7 @@
namespace
spdlog
{
// Default logger factory- creates synchronous loggers
struct
create_synchronous
struct
default_factory
{
template
<
typename
Sink
,
typename
...
SinkArgs
>
...
...
@@ -40,41 +32,6 @@ struct create_synchronous
}
};
using
default_factory
=
create_synchronous
;
//
// color console loggers
//
// you must include "spdlog/sinks/color_sinks.h" before creating color loggers
//
// #include "spdlog/color_console.h"
//
// using namespace spdlog::sinks
// auto logger = spdlog::console<stdout_color_mt>("logger_name1");
// auto logger = spdlog::console<stdout_color_st>("logger_name2");
// auto looger = spdlog::console<stderr_color_mt>("logger_name3");
//
//
// create asynchrounous color logger
// you must include "spdlog/asynch.h" before creating async loggers
//
// #include "spdlog/asynch."
// #include "spdlog/sinks/color_sinks.h"
// auto async_console = spdlog::console<stderr_color_st, spdlog::create_async>("some_name");
// or
// auto async_console = spdlog::create_async_logger<stdout_color_mt>("Console2");
//template<typename console_type, typename Factory = create_synchronous>
//inline std::shared_ptr<logger> console(const std::string &logger_name)
//{
// return Factory::template create<console_type>(logger_name);
//}
// Create and register a logger with a templated sink type
// The logger's level, formatter and flush level will be set according the global settings.
...
...
@@ -159,73 +116,6 @@ inline void drop_all()
details
::
registry
::
instance
().
drop_all
();
}
//
// Create and register multi/single threaded basic file logger.
// Basic logger simply writes to given file without any limitations or rotations.
//
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
basic_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
{
return
Factory
::
template
create
<
sinks
::
simple_file_sink_mt
>
(
logger_name
,
filename
,
truncate
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
basic_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
bool
truncate
=
false
)
{
return
Factory
::
template
create
<
sinks
::
simple_file_sink_st
>
(
logger_name
,
filename
,
truncate
);
}
//
// Create and register multi/single threaded rotating file logger
//
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
)
{
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
max_file_size
,
max_files
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
size_t
max_file_size
,
size_t
max_files
)
{
return
Factory
::
template
create
<
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
max_file_size
,
max_files
);
}
//
// Create file logger which creates new file on the given time (default in midnight):
//
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
)
{
return
Factory
::
template
create
<
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
hour
,
minute
);
}
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
filename_t
&
filename
,
int
hour
=
0
,
int
minute
=
0
)
{
return
Factory
::
template
create
<
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
hour
,
minute
);
}
#ifdef SPDLOG_ENABLE_SYSLOG
// Create and register a syslog logger
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
syslog_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facilty
=
(
1
<<
3
))
{
return
return
Factory
::
template
create
<
sinks
::
syslog_sink
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
}
#endif
#if defined(__ANDROID__)
// Create and register android syslog logger
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
android_logger
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
tag
=
"spdlog"
)
{
return
return
Factory
::
template
create
<
sinks
::
android_sink
>
(
logger_name
,
tag
);
}
#endif
///////////////////////////////////////////////////////////////////////////////
//
...
...
include/spdlog/tweakme.h
View file @
e4d3eb64
...
...
@@ -102,12 +102,6 @@
// #define SPDLOG_FMT_PRINTF
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable syslog (disabled by default)
//
// #define SPDLOG_ENABLE_SYSLOG
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable wchar_t support (convert to utf8)
//
...
...
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