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
c962c883
Commit
c962c883
authored
7 years ago
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed linux port of v1.x
parent
c80cc330
Show whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
253 additions
and
272 deletions
+253
-272
bench.cpp
example/bench.cpp
+1
-0
example.cpp
example/example.cpp
+6
-8
async.h
include/spdlog/async.h
+0
-0
async_logger_impl.h
include/spdlog/details/async_logger_impl.h
+0
-0
logger_impl.h
include/spdlog/details/logger_impl.h
+0
-3
os.h
include/spdlog/details/os.h
+1
-13
registry.h
include/spdlog/details/registry.h
+0
-1
traits.h
include/spdlog/details/traits.h
+33
-21
logger.h
include/spdlog/logger.h
+1
-1
android_sink.h
include/spdlog/sinks/android_sink.h
+13
-15
ansicolor_sink.h
include/spdlog/sinks/ansicolor_sink.h
+20
-26
file_sinks.h
include/spdlog/sinks/file_sinks.h
+76
-76
stdout_color_sinks.h
include/spdlog/sinks/stdout_color_sinks.h
+28
-28
stdout_sinks.h
include/spdlog/sinks/stdout_sinks.h
+39
-34
syslog_sink.h
include/spdlog/sinks/syslog_sink.h
+15
-19
wincolor_sink.h
include/spdlog/sinks/wincolor_sink.h
+17
-21
spdlog.h
include/spdlog/spdlog.h
+1
-3
includes.h
tests/includes.h
+2
-3
No files found.
example/bench.cpp
View file @
c962c883
...
...
@@ -7,6 +7,7 @@
// bench.cpp : spdlog benchmarks
//
#include "spdlog/async.h"
#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/null_sink.h"
#include "spdlog/spdlog.h"
...
...
This diff is collapsed.
Click to expand it.
example/example.cpp
View file @
c962c883
//
//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
...
...
@@ -10,9 +10,8 @@
#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON
#include "spdlog/sinks/stdout_color_sinks.h"
#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"
#include <iostream>
#include <memory>
...
...
@@ -60,7 +59,7 @@ int main(int, char *[])
daily_logger
->
info
(
123.44
);
// Customize msg format for all messages
//
spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v"); //crash
//
spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v"); //crash
console
->
info
(
"This an info message with custom format"
);
console
->
error
(
"This an error message with custom format"
);
...
...
@@ -80,7 +79,6 @@ int main(int, char *[])
// Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
async_example
();
// Log user-defined types example
user_defined_example
();
...
...
@@ -117,7 +115,7 @@ void async_example()
// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#incude "spdlog/sinks/syslog_sink.h"
#inc
l
ude "spdlog/sinks/syslog_sink.h"
void
syslog_example
()
{
std
::
string
ident
=
"spdlog-example"
;
...
...
@@ -152,7 +150,7 @@ struct my_type
#include "spdlog/fmt/ostr.h" // must be included
void
user_defined_example
()
{
spd
::
get
(
"console"
)
->
info
(
"user defined type: {}"
,
my_type
{
14
});
spd
::
get
(
"console"
)
->
info
(
"user defined type: {}"
,
my_type
{
14
});
}
//
...
...
@@ -163,5 +161,5 @@ void err_handler_example()
// can be set globaly or per logger(logger->set_error_handler(..))
spdlog
::
set_error_handler
([](
const
std
::
string
&
msg
)
{
spd
::
get
(
"console"
)
->
error
(
"*******my err handler: {}"
,
msg
);
});
spd
::
get
(
"console"
)
->
info
(
"some invalid message to trigger an error {}{}{}{}"
,
3
);
//
spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
//
spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
}
This diff is collapsed.
Click to expand it.
include/spdlog/async.h
View file @
c962c883
This diff is collapsed.
Click to expand it.
include/spdlog/details/async_logger_impl.h
View file @
c962c883
This diff is collapsed.
Click to expand it.
include/spdlog/details/logger_impl.h
View file @
c962c883
...
...
@@ -5,9 +5,6 @@
#pragma once
#include "../logger.h"
#include "../sinks/stdout_sinks.h"
#include <memory>
#include <string>
...
...
This diff is collapsed.
Click to expand it.
include/spdlog/details/os.h
View file @
c962c883
...
...
@@ -13,11 +13,11 @@
#include <cstring>
#include <ctime>
#include <functional>
#include <mutex>
#include <string>
#include <sys/stat.h>
#include <sys/types.h>
#include <thread>
#include <mutex>
#ifdef _WIN32
...
...
@@ -476,18 +476,6 @@ inline bool in_terminal(FILE *file)
#endif
}
// stdout/stderr global mutexes
inline
std
::
mutex
&
stdout_mutex
()
{
static
std
::
mutex
&
mutex
=
std
::
mutex
{};
return
mutex
;
}
inline
std
::
mutex
&
stderr_mutex
()
{
static
std
::
mutex
&
mutex
=
std
::
mutex
{};
return
mutex
;
}
}
// namespace os
}
// namespace details
}
// namespace spdlog
This diff is collapsed.
Click to expand it.
include/spdlog/details/registry.h
View file @
c962c883
...
...
@@ -157,7 +157,6 @@ public:
std
::
lock_guard
<
Mutex
>
lock
(
_tp_mutex
);
_tp
.
reset
();
}
}
Mutex
&
tp_mutex
()
...
...
This diff is collapsed.
Click to expand it.
include/spdlog/details/traits.h
View file @
c962c883
...
...
@@ -6,41 +6,53 @@
#include "stdio.h"
namespace
spdlog
{
namespace
details
{
struct
console_stdout_trait
namespace
details
{
struct
console_stdout_trait
{
static
FILE
*
stream
()
{
static
FILE
*
stream
()
{
return
stdout
;}
return
stdout
;
}
#ifdef _WIN32
static
HANDLE
handle
()
{
return
::
GetStdHandle
(
STD_OUTPUT_HANDLE
);
}
static
HANDLE
handle
()
{
return
::
GetStdHandle
(
STD_OUTPUT_HANDLE
);
}
#endif
};
};
struct
console_stderr_trait
struct
console_stderr_trait
{
static
FILE
*
stream
()
{
static
FILE
*
stream
()
{
return
stdout
;
}
return
stdout
;
}
#ifdef _WIN32
static
HANDLE
handle
()
{
return
::
GetStdHandle
(
STD_ERROR_HANDLE
);
}
static
HANDLE
handle
()
{
return
::
GetStdHandle
(
STD_ERROR_HANDLE
);
}
#endif
};
};
struct
console_mutex_trait
{
struct
console_mutex_trait
{
using
mutex_t
=
std
::
mutex
;
static
mutex_t
&
console_mutex
()
static
mutex_t
&
console_mutex
()
{
static
auto
&
mutex
=
mutex_t
{}
;
static
mutex_t
mutex
;
return
mutex
;
}
};
};
struct
console_null_mutex_trait
{
struct
console_null_mutex_trait
{
using
mutex_t
=
null_mutex
;
static
mutex_t
&
console_mutex
()
static
mutex_t
&
console_mutex
()
{
static
auto
mutex
=
mutex_t
{}
;
static
mutex_t
mutex
;
return
mutex
;
}
};
}
}
};
}
// namespace details
}
// namespace spdlog
This diff is collapsed.
Click to expand it.
include/spdlog/logger.h
View file @
c962c883
...
...
@@ -13,8 +13,8 @@
// 3. Pass the formatted message to its sinks to performa the actual logging
#include "common.h"
#include "sinks/sink.h"
#include "formatter.h"
#include "sinks/sink.h"
#include <memory>
#include <string>
...
...
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/android_sink.h
View file @
c962c883
...
...
@@ -21,15 +21,15 @@
#endif
namespace
spdlog
{
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
:
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
)
...
...
@@ -59,7 +59,7 @@ namespace spdlog {
void
flush
()
override
{}
private
:
private
:
static
android_LogPriority
convert_to_android
(
spdlog
::
level
::
level_enum
level
)
{
switch
(
level
)
...
...
@@ -83,19 +83,17 @@ namespace spdlog {
std
::
string
_tag
;
bool
_use_raw_msg
;
};
}
// namespace sinks
};
}
// namespace sinks
// Create and register android syslog logger
// 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"
)
{
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
...
...
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/ansicolor_sink.h
View file @
c962c883
...
...
@@ -9,30 +9,30 @@
#include "../details/os.h"
#include "../details/traits.h"
#include <string>
#include <unordered_map>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
namespace
spdlog
{
namespace
sinks
{
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
:
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
())
:
target_file_
(
StdoutTrait
::
stream
())
,
_mutex
(
ConsoleMutexTrait
::
console_
mutex
())
{
should_do_colors_
=
details
::
os
::
in_terminal
(
file
)
&&
details
::
os
::
is_color_terminal
();
should_do_colors_
=
details
::
os
::
in_terminal
(
target_file_
)
&&
details
::
os
::
is_color_terminal
();
colors_
[
level
::
trace
]
=
white
;
colors_
[
level
::
debug
]
=
cyan
;
colors_
[
level
::
info
]
=
green
;
...
...
@@ -42,10 +42,7 @@ namespace spdlog {
colors_
[
level
::
off
]
=
reset
;
}
~
ansicolor_sink
()
override
{
_flush
();
}
~
ansicolor_sink
()
override
=
default
;
ansicolor_sink
(
const
ansicolor_sink
&
other
)
=
delete
;
ansicolor_sink
&
operator
=
(
const
ansicolor_sink
&
other
)
=
delete
;
...
...
@@ -86,7 +83,6 @@ namespace spdlog {
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.
...
...
@@ -116,9 +112,7 @@ namespace spdlog {
fflush
(
target_file_
);
}
private
:
private
:
void
_print_ccode
(
const
std
::
string
&
color_code
)
{
fwrite
(
color_code
.
data
(),
sizeof
(
char
),
color_code
.
size
(),
target_file_
);
...
...
@@ -129,17 +123,17 @@ namespace spdlog {
}
FILE
*
target_file_
;
mutex_t
&
_mutex
;
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
>
;
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 sinks
}
// namespace spdlog
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/file_sinks.h
View file @
c962c883
...
...
@@ -4,10 +4,10 @@
//
#pragma once
#include "../details/file_helper.h"
#include "../details/null_mutex.h"
#include "../fmt/fmt.h"
#include "../spdlog.h"
#include "base_sink.h"
#include <algorithm>
...
...
@@ -19,14 +19,14 @@
#include <string>
namespace
spdlog
{
namespace
sinks
{
/*
namespace
sinks
{
/*
* Trivial file sink with single file as target
*/
template
<
class
Mutex
>
class
simple_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
template
<
class
Mutex
>
class
simple_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
explicit
simple_file_sink
(
const
filename_t
&
filename
,
bool
truncate
=
false
)
:
_force_flush
(
false
)
{
...
...
@@ -38,7 +38,7 @@ namespace spdlog {
_force_flush
=
force_flush
;
}
protected
:
protected
:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_file_helper
.
write
(
msg
);
...
...
@@ -53,21 +53,21 @@ namespace spdlog {
_file_helper
.
flush
();
}
private
:
private
:
details
::
file_helper
_file_helper
;
bool
_force_flush
;
};
};
using
simple_file_sink_mt
=
simple_file_sink
<
std
::
mutex
>
;
using
simple_file_sink_st
=
simple_file_sink
<
details
::
null_mutex
>
;
using
simple_file_sink_mt
=
simple_file_sink
<
std
::
mutex
>
;
using
simple_file_sink_st
=
simple_file_sink
<
details
::
null_mutex
>
;
/*
/*
* Rotating file sink based on size
*/
template
<
class
Mutex
>
class
rotating_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
template
<
class
Mutex
>
class
rotating_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
rotating_file_sink
(
filename_t
base_filename
,
std
::
size_t
max_size
,
std
::
size_t
max_files
)
:
_base_filename
(
std
::
move
(
base_filename
))
,
_max_size
(
max_size
)
...
...
@@ -95,7 +95,7 @@ namespace spdlog {
return
w
.
str
();
}
protected
:
protected
:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
_current_size
+=
msg
.
formatted
.
size
();
...
...
@@ -112,7 +112,7 @@ namespace spdlog {
_file_helper
.
flush
();
}
private
:
private
:
// Rotate files:
// log.txt -> log.1.txt
// log.1.txt -> log.2.txt
...
...
@@ -147,16 +147,16 @@ namespace spdlog {
std
::
size_t
_max_files
;
std
::
size_t
_current_size
;
details
::
file_helper
_file_helper
;
};
};
using
rotating_file_sink_mt
=
rotating_file_sink
<
std
::
mutex
>
;
using
rotating_file_sink_st
=
rotating_file_sink
<
details
::
null_mutex
>
;
using
rotating_file_sink_mt
=
rotating_file_sink
<
std
::
mutex
>
;
using
rotating_file_sink_st
=
rotating_file_sink
<
details
::
null_mutex
>
;
/*
/*
* Default generator of daily log file names.
*/
struct
default_daily_file_name_calculator
{
struct
default_daily_file_name_calculator
{
// Create filename for the form filename.YYYY-MM-DD_hh-mm.ext
static
filename_t
calc_filename
(
const
filename_t
&
filename
)
{
...
...
@@ -168,13 +168,13 @@ namespace spdlog {
tm
.
tm_hour
,
tm
.
tm_min
,
ext
);
return
w
.
str
();
}
};
};
/*
/*
* Generator of daily log file names in format basename.YYYY-MM-DD.ext
*/
struct
dateonly_daily_file_name_calculator
{
struct
dateonly_daily_file_name_calculator
{
// Create filename for the form basename.YYYY-MM-DD
static
filename_t
calc_filename
(
const
filename_t
&
filename
)
{
...
...
@@ -185,15 +185,15 @@ namespace spdlog {
w
.
write
(
SPDLOG_FILENAME_T
(
"{}_{:04d}-{:02d}-{:02d}{}"
),
basename
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
ext
);
return
w
.
str
();
}
};
};
/*
/*
* Rotating file sink based on date. rotates at midnight
*/
template
<
class
Mutex
,
class
FileNameCalc
=
default_daily_file_name_calculator
>
class
daily_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
template
<
class
Mutex
,
class
FileNameCalc
=
default_daily_file_name_calculator
>
class
daily_file_sink
SPDLOG_FINAL
:
public
base_sink
<
Mutex
>
{
public
:
// create daily file sink which rotates on given time
daily_file_sink
(
filename_t
base_filename
,
int
rotation_hour
,
int
rotation_minute
)
:
_base_filename
(
std
::
move
(
base_filename
))
...
...
@@ -208,7 +208,7 @@ namespace spdlog {
_file_helper
.
open
(
FileNameCalc
::
calc_filename
(
_base_filename
));
}
protected
:
protected
:
void
_sink_it
(
const
details
::
log_msg
&
msg
)
override
{
if
(
std
::
chrono
::
system_clock
::
now
()
>=
_rotation_tp
)
...
...
@@ -224,7 +224,7 @@ namespace spdlog {
_file_helper
.
flush
();
}
private
:
private
:
std
::
chrono
::
system_clock
::
time_point
_next_rotation_tp
()
{
auto
now
=
std
::
chrono
::
system_clock
::
now
();
...
...
@@ -238,7 +238,7 @@ namespace spdlog {
{
return
rotation_time
;
}
return
{
rotation_time
+
std
::
chrono
::
hours
(
24
)
};
return
{
rotation_time
+
std
::
chrono
::
hours
(
24
)
};
}
filename_t
_base_filename
;
...
...
@@ -246,59 +246,59 @@ namespace spdlog {
int
_rotation_m
;
std
::
chrono
::
system_clock
::
time_point
_rotation_tp
;
details
::
file_helper
_file_helper
;
};
};
using
daily_file_sink_mt
=
daily_file_sink
<
std
::
mutex
>
;
using
daily_file_sink_st
=
daily_file_sink
<
details
::
null_mutex
>
;
using
daily_file_sink_mt
=
daily_file_sink
<
std
::
mutex
>
;
using
daily_file_sink_st
=
daily_file_sink
<
details
::
null_mutex
>
;
}
// namespace sinks
}
// namespace sinks
//
// factory functions to create and register file loggers
//
//
// factory functions to create and register file loggers
//
// 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
)
{
// 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
)
{
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
(
//
// 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
(
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
)
{
//
// 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
)
{
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
);
}
}
}
// namespace spdlog
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/stdout_color_sinks.h
View file @
c962c883
...
...
@@ -13,43 +13,42 @@
#endif
namespace
{
using
namespace
spdlog
::
sinks
;
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
;
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
;
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
namespace
spdlog
namespace
spdlog
{
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_color_mt
(
const
std
::
string
&
logger_name
)
{
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
)
{
}
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
)
{
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
);
}
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
);
}
}
// namespace spdlog
\ No newline at end of file
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/stdout_sinks.h
View file @
c962c883
...
...
@@ -7,22 +7,26 @@
#include "../details/null_mutex.h"
#include "../details/traits.h"
#include "../spdlog.h"
#include <cstdio>
#include <memory>
#include <mutex>
namespace
spdlog
{
namespace
sinks
{
template
<
class
StdoutTrait
,
class
ConsoleMutexTrait
>
class
stdout_sink
:
public
sink
{
public
:
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
()
:
_mutex
(
ConsoleMutexTrait
::
console_mutex
())
,
_file
(
StdoutTrait
::
stream
())
{
}
~
stdout_sink
()
=
default
;
stdout_sink
(
const
stdout_sink
&
other
)
=
delete
;
...
...
@@ -40,40 +44,41 @@ namespace spdlog {
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
>
;
private
:
mutex_t
&
_mutex
;
FILE
*
_file
;
}
;
}
// namespace sinks
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
>
;
// factory methods
template
<
typename
Factory
=
default_factory
>
inline
std
::
shared_ptr
<
logger
>
stdout_logger_mt
(
const
std
::
string
&
logger_name
)
{
}
// 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
)
{
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
)
{
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
)
{
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
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/syslog_sink.h
View file @
c962c883
...
...
@@ -7,8 +7,6 @@
#include "../common.h"
#ifdef SPDLOG_ENABLE_SYSLOG
#include "../details/log_msg.h"
#include "sink.h"
...
...
@@ -17,15 +15,15 @@
#include <syslog.h>
namespace
spdlog
{
namespace
sinks
{
/**
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
:
class
syslog_sink
:
public
sink
{
public
:
//
syslog_sink
(
const
std
::
string
&
ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facility
=
LOG_USER
)
:
_ident
(
ident
)
...
...
@@ -57,7 +55,7 @@ namespace spdlog {
void
flush
()
override
{}
private
:
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
;
...
...
@@ -69,16 +67,14 @@ namespace spdlog {
{
return
_priorities
[
static_cast
<
size_t
>
(
msg
.
level
)];
}
};
}
// namespace sinks
};
}
// 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_facil
ty
=
(
1
<<
3
))
{
return
return
Factory
::
template
create
<
sinks
::
syslog_sink
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
}
// 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
&
syslog_ident
=
""
,
int
syslog_option
=
0
,
int
syslog_facili
ty
=
(
1
<<
3
))
{
return
Factory
::
template
create
<
sinks
::
syslog_sink
>
(
logger_name
,
syslog_ident
,
syslog_option
,
syslog_facility
);
}
}
// namespace spdlog
#endif
This diff is collapsed.
Click to expand it.
include/spdlog/sinks/wincolor_sink.h
View file @
c962c883
...
...
@@ -5,28 +5,26 @@
#pragma once
#include "sink.h"
#include "../common.h"
#include "../details/null_mutex.h"
#include "../details/traits.h"
#include "sink.h"
#include <mutex>
#include <memory>
#include <mutex>
#include <string>
#include <unordered_map>
#include <wincon.h>
namespace
spdlog
{
namespace
sinks
{
/*
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
:
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
;
...
...
@@ -35,8 +33,8 @@ namespace spdlog {
const
WORD
YELLOW
=
FOREGROUND_RED
|
FOREGROUND_GREEN
;
wincolor_sink
()
:
out_handle_
(
HandleTrait
::
handle
()),
_mutex
(
ConsoleMutexTrait
::
console_mutex
())
:
out_handle_
(
HandleTrait
::
handle
())
,
_mutex
(
ConsoleMutexTrait
::
console_mutex
())
{
colors_
[
level
::
trace
]
=
WHITE
;
colors_
[
level
::
debug
]
=
CYAN
;
...
...
@@ -47,7 +45,6 @@ namespace spdlog {
colors_
[
level
::
off
]
=
0
;
}
~
wincolor_sink
()
override
{
this
->
flush
();
...
...
@@ -90,7 +87,7 @@ namespace spdlog {
// windows console always flushed?
}
private
:
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
)
...
...
@@ -115,14 +112,13 @@ namespace spdlog {
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_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
>
;
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 sinks
}
// namespace spdlog
This diff is collapsed.
Click to expand it.
include/spdlog/spdlog.h
View file @
c962c883
...
...
@@ -7,8 +7,8 @@
#pragma once
#include "details/registry.h"
#include "common.h"
#include "details/registry.h"
#include "logger.h"
#include <chrono>
...
...
@@ -32,7 +32,6 @@ struct default_factory
}
};
// 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.
// Example:
...
...
@@ -116,7 +115,6 @@ inline void drop_all()
details
::
registry
::
instance
().
drop_all
();
}
///////////////////////////////////////////////////////////////////////////////
//
// Trace & Debug can be switched on/off at compile time for zero cost debug statements.
...
...
This diff is collapsed.
Click to expand it.
tests/includes.h
View file @
c962c883
...
...
@@ -12,9 +12,8 @@
#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON
#include "../include/spdlog/spdlog.h"
#include "../include/spdlog/async.h"
#include "../include/spdlog/sinks/null_sink.h"
#include "../include/spdlog/sinks/file_sinks.h"
#include "../include/spdlog/sinks/null_sink.h"
#include "../include/spdlog/sinks/ostream_sink.h"
#include "../include/spdlog/spdlog.h"
This diff is collapsed.
Click to expand it.
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