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
cadd181d
Commit
cadd181d
authored
Aug 07, 2015
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reverted pull #111 - wchar support under windows - it pollutes global namespace with new defines
parent
5afce169
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
53 additions
and
91 deletions
+53
-91
common.h
include/spdlog/common.h
+2
-11
file_helper.h
include/spdlog/details/file_helper.h
+13
-14
os.h
include/spdlog/details/os.h
+2
-23
spdlog_impl.h
include/spdlog/details/spdlog_impl.h
+8
-8
file_sinks.h
include/spdlog/sinks/file_sinks.h
+24
-25
spdlog.h
include/spdlog/spdlog.h
+4
-4
tweakme.h
include/spdlog/tweakme.h
+0
-6
No files found.
include/spdlog/common.h
View file @
cadd181d
...
@@ -36,15 +36,6 @@
...
@@ -36,15 +36,6 @@
#define SPDLOG_NOEXCEPT throw()
#define SPDLOG_NOEXCEPT throw()
#endif
#endif
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
typedef
std
::
wstring
tstring
;
typedef
wchar_t
tchar
;
#define S(s) L ## s
#else
#define S(s) s
typedef
std
::
string
tstring
;
typedef
char
tchar
;
#endif
namespace
spdlog
namespace
spdlog
{
{
...
@@ -58,8 +49,8 @@ class sink;
...
@@ -58,8 +49,8 @@ class sink;
// Common types across the lib
// Common types across the lib
using
log_clock
=
std
::
chrono
::
system_clock
;
using
log_clock
=
std
::
chrono
::
system_clock
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sink_ptr
=
std
::
shared_ptr
<
sinks
::
sink
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
sinks_init_list
=
std
::
initializer_list
<
sink_ptr
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
using
formatter_ptr
=
std
::
shared_ptr
<
spdlog
::
formatter
>
;
...
...
include/spdlog/details/file_helper.h
View file @
cadd181d
...
@@ -48,7 +48,7 @@ public:
...
@@ -48,7 +48,7 @@ public:
const
int
open_tries
=
5
;
const
int
open_tries
=
5
;
const
int
open_interval
=
10
;
const
int
open_interval
=
10
;
explicit
file_helper
(
bool
force_flush
)
:
explicit
file_helper
(
bool
force_flush
)
:
_fd
(
nullptr
),
_fd
(
nullptr
),
_force_flush
(
force_flush
)
_force_flush
(
force_flush
)
{}
{}
...
@@ -62,26 +62,26 @@ public:
...
@@ -62,26 +62,26 @@ public:
}
}
void
open
(
const
tstring
&
fname
,
bool
truncate
=
false
)
void
open
(
const
std
::
string
&
fname
,
bool
truncate
=
false
)
{
{
close
();
close
();
const
tchar
*
mode
=
truncate
?
S
(
"wb"
)
:
S
(
"ab"
)
;
const
char
*
mode
=
truncate
?
"wb"
:
"ab"
;
_filename
=
fname
;
_filename
=
fname
;
for
(
int
tries
=
0
;
tries
<
open_tries
;
++
tries
)
for
(
int
tries
=
0
;
tries
<
open_tries
;
++
tries
)
{
{
if
(
!
os
::
fopen_s
(
&
_fd
,
fname
,
mode
))
if
(
!
os
::
fopen_s
(
&
_fd
,
fname
,
mode
))
return
;
return
;
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
open_interval
));
std
::
this_thread
::
sleep_for
(
std
::
chrono
::
milliseconds
(
open_interval
));
}
}
throw
spdlog_ex
(
"Failed opening file for writing"
);
throw
spdlog_ex
(
"Failed opening file
"
+
fname
+
"
for writing"
);
}
}
void
reopen
(
bool
truncate
)
void
reopen
(
bool
truncate
)
{
{
if
(
_filename
.
empty
())
if
(
_filename
.
empty
())
throw
spdlog_ex
(
"Failed re opening file - was not opened before"
);
throw
spdlog_ex
(
"Failed re opening file - was not opened before"
);
open
(
_filename
,
truncate
);
open
(
_filename
,
truncate
);
...
@@ -105,23 +105,23 @@ public:
...
@@ -105,23 +105,23 @@ public:
size_t
size
=
msg
.
formatted
.
size
();
size_t
size
=
msg
.
formatted
.
size
();
auto
data
=
msg
.
formatted
.
data
();
auto
data
=
msg
.
formatted
.
data
();
if
(
std
::
fwrite
(
data
,
1
,
size
,
_fd
)
!=
size
)
if
(
std
::
fwrite
(
data
,
1
,
size
,
_fd
)
!=
size
)
throw
spdlog_ex
(
"Failed writing to file
"
);
throw
spdlog_ex
(
"Failed writing to file
"
+
_filename
);
if
(
_force_flush
)
if
(
_force_flush
)
std
::
fflush
(
_fd
);
std
::
fflush
(
_fd
);
}
}
const
t
string
&
filename
()
const
const
std
::
string
&
filename
()
const
{
{
return
_filename
;
return
_filename
;
}
}
static
bool
file_exists
(
const
t
string
&
name
)
static
bool
file_exists
(
const
std
::
string
&
name
)
{
{
FILE
*
file
;
FILE
*
file
;
if
(
!
os
::
fopen_s
(
&
file
,
name
.
c_str
(),
S
(
"r"
)
))
if
(
!
os
::
fopen_s
(
&
file
,
name
.
c_str
(),
"r"
))
{
{
fclose
(
file
);
fclose
(
file
);
return
true
;
return
true
;
...
@@ -134,11 +134,10 @@ public:
...
@@ -134,11 +134,10 @@ public:
private
:
private
:
FILE
*
_fd
;
FILE
*
_fd
;
t
string
_filename
;
std
::
string
_filename
;
bool
_force_flush
;
bool
_force_flush
;
};
};
}
}
}
}
include/spdlog/details/os.h
View file @
cadd181d
...
@@ -147,37 +147,17 @@ constexpr inline unsigned short eol_size()
...
@@ -147,37 +147,17 @@ constexpr inline unsigned short eol_size()
#endif
#endif
//fopen_s on non windows for writing
//fopen_s on non windows for writing
inline
int
fopen_s
(
FILE
**
fp
,
const
tstring
&
filename
,
const
t
char
*
mode
)
inline
int
fopen_s
(
FILE
**
fp
,
const
std
::
string
&
filename
,
const
char
*
mode
)
{
{
#if defined(WIN32)
#ifdef _WIN32
#if defined(SPDLOG_USE_WCHAR)
*
fp
=
_wfsopen
((
filename
.
c_str
()),
mode
,
_SH_DENYWR
);
#else
*
fp
=
_fsopen
((
filename
.
c_str
()),
mode
,
_SH_DENYWR
);
*
fp
=
_fsopen
((
filename
.
c_str
()),
mode
,
_SH_DENYWR
);
#endif
return
*
fp
==
nullptr
;
return
*
fp
==
nullptr
;
#else
#else
*
fp
=
fopen
((
filename
.
c_str
()),
mode
);
*
fp
=
fopen
((
filename
.
c_str
()),
mode
);
return
*
fp
==
nullptr
;
return
*
fp
==
nullptr
;
#endif
#endif
}
inline
int
remove
(
const
tchar
*
filename
)
{
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
return
_wremove
(
filename
);
#else
return
std
::
remove
(
filename
);
#endif
}
inline
int
rename
(
const
tchar
*
filename1
,
const
tchar
*
filename2
)
{
#if defined(WIN32) && defined(SPDLOG_USE_WCHAR)
return
_wrename
(
filename1
,
filename2
);
#else
return
std
::
rename
(
filename1
,
filename2
);
#endif
}
}
//Return utc offset in minutes or -1 on failure
//Return utc offset in minutes or -1 on failure
...
@@ -215,4 +195,3 @@ inline size_t thread_id()
...
@@ -215,4 +195,3 @@ inline size_t thread_id()
}
//spdlog
}
//spdlog
include/spdlog/details/spdlog_impl.h
View file @
cadd181d
...
@@ -48,24 +48,24 @@ inline void spdlog::drop(const std::string &name)
...
@@ -48,24 +48,24 @@ inline void spdlog::drop(const std::string &name)
}
}
// Create multi/single threaded rotating file logger
// Create multi/single threaded rotating file logger
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
)
{
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
S
(
"txt"
)
,
max_file_size
,
max_files
,
force_flush
);
return
create
<
spdlog
::
sinks
::
rotating_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
force_flush
);
}
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
)
{
{
return
create
<
spdlog
::
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
S
(
"txt"
)
,
max_file_size
,
max_files
,
force_flush
);
return
create
<
spdlog
::
sinks
::
rotating_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
max_file_size
,
max_files
,
force_flush
);
}
}
// Create file logger which creates new file at midnight):
// Create file logger which creates new file at midnight):
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
{
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
S
(
"txt"
)
,
hour
,
minute
,
force_flush
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_mt
>
(
logger_name
,
filename
,
"txt"
,
hour
,
minute
,
force_flush
);
}
}
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
inline
std
::
shared_ptr
<
spdlog
::
logger
>
spdlog
::
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
,
int
minute
,
bool
force_flush
)
{
{
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
S
(
"txt"
)
,
hour
,
minute
,
force_flush
);
return
create
<
spdlog
::
sinks
::
daily_file_sink_st
>
(
logger_name
,
filename
,
"txt"
,
hour
,
minute
,
force_flush
);
}
}
...
...
include/spdlog/sinks/file_sinks.h
View file @
cadd181d
...
@@ -29,7 +29,6 @@
...
@@ -29,7 +29,6 @@
#include "../details/null_mutex.h"
#include "../details/null_mutex.h"
#include "../details/file_helper.h"
#include "../details/file_helper.h"
#include "../details/format.h"
#include "../details/format.h"
#include "../details/os.h"
namespace
spdlog
namespace
spdlog
{
{
...
@@ -66,13 +65,13 @@ typedef simple_file_sink<std::mutex> simple_file_sink_mt;
...
@@ -66,13 +65,13 @@ typedef simple_file_sink<std::mutex> simple_file_sink_mt;
typedef
simple_file_sink
<
details
::
null_mutex
>
simple_file_sink_st
;
typedef
simple_file_sink
<
details
::
null_mutex
>
simple_file_sink_st
;
/*
/*
* Rotating file sink based on size
* Rotating file sink based on size
*/
*/
template
<
class
Mutex
>
template
<
class
Mutex
>
class
rotating_file_sink
:
public
base_sink
<
Mutex
>
class
rotating_file_sink
:
public
base_sink
<
Mutex
>
{
{
public
:
public
:
rotating_file_sink
(
const
tstring
&
base_filename
,
const
t
string
&
extension
,
rotating_file_sink
(
const
std
::
string
&
base_filename
,
const
std
::
string
&
extension
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
std
::
size_t
max_size
,
std
::
size_t
max_files
,
bool
force_flush
=
false
)
:
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
_base_filename
(
base_filename
),
...
@@ -103,13 +102,13 @@ protected:
...
@@ -103,13 +102,13 @@ protected:
}
}
private
:
private
:
static
tstring
calc_filename
(
const
tstring
&
filename
,
std
::
size_t
index
,
const
t
string
&
extension
)
static
std
::
string
calc_filename
(
const
std
::
string
&
filename
,
std
::
size_t
index
,
const
std
::
string
&
extension
)
{
{
fmt
::
T
MemoryWriter
w
;
fmt
::
MemoryWriter
w
;
if
(
index
)
if
(
index
)
w
.
write
(
S
(
"{}.{}.{}"
)
,
filename
,
index
,
extension
);
w
.
write
(
"{}.{}.{}"
,
filename
,
index
,
extension
);
else
else
w
.
write
(
S
(
"{}.{}"
)
,
filename
,
extension
);
w
.
write
(
"{}.{}"
,
filename
,
extension
);
return
w
.
str
();
return
w
.
str
();
}
}
...
@@ -124,25 +123,25 @@ private:
...
@@ -124,25 +123,25 @@ private:
_file_helper
.
close
();
_file_helper
.
close
();
for
(
auto
i
=
_max_files
;
i
>
0
;
--
i
)
for
(
auto
i
=
_max_files
;
i
>
0
;
--
i
)
{
{
t
string
src
=
calc_filename
(
_base_filename
,
i
-
1
,
_extension
);
std
::
string
src
=
calc_filename
(
_base_filename
,
i
-
1
,
_extension
);
t
string
target
=
calc_filename
(
_base_filename
,
i
,
_extension
);
std
::
string
target
=
calc_filename
(
_base_filename
,
i
,
_extension
);
if
(
details
::
file_helper
::
file_exists
(
target
))
if
(
details
::
file_helper
::
file_exists
(
target
))
{
{
if
(
details
::
os
::
remove
(
target
.
c_str
())
!=
0
)
if
(
std
::
remove
(
target
.
c_str
())
!=
0
)
{
{
throw
spdlog_ex
(
"rotating_file_sink: failed removing
"
);
throw
spdlog_ex
(
"rotating_file_sink: failed removing
"
+
target
);
}
}
}
}
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
details
::
os
::
rename
(
src
.
c_str
(),
target
.
c_str
()))
if
(
details
::
file_helper
::
file_exists
(
src
)
&&
std
::
rename
(
src
.
c_str
(),
target
.
c_str
()))
{
{
throw
spdlog_ex
(
"rotating_file_sink: failed renaming
"
);
throw
spdlog_ex
(
"rotating_file_sink: failed renaming
"
+
src
+
" to "
+
target
);
}
}
}
}
_file_helper
.
reopen
(
true
);
_file_helper
.
reopen
(
true
);
}
}
t
string
_base_filename
;
std
::
string
_base_filename
;
t
string
_extension
;
std
::
string
_extension
;
std
::
size_t
_max_size
;
std
::
size_t
_max_size
;
std
::
size_t
_max_files
;
std
::
size_t
_max_files
;
std
::
size_t
_current_size
;
std
::
size_t
_current_size
;
...
@@ -153,16 +152,16 @@ typedef rotating_file_sink<std::mutex> rotating_file_sink_mt;
...
@@ -153,16 +152,16 @@ typedef rotating_file_sink<std::mutex> rotating_file_sink_mt;
typedef
rotating_file_sink
<
details
::
null_mutex
>
rotating_file_sink_st
;
typedef
rotating_file_sink
<
details
::
null_mutex
>
rotating_file_sink_st
;
/*
/*
* Rotating file sink based on date. rotates at midnight
* Rotating file sink based on date. rotates at midnight
*/
*/
template
<
class
Mutex
>
template
<
class
Mutex
>
class
daily_file_sink
:
public
base_sink
<
Mutex
>
class
daily_file_sink
:
public
base_sink
<
Mutex
>
{
{
public
:
public
:
//create daily file sink which rotates on given time
//create daily file sink which rotates on given time
daily_file_sink
(
daily_file_sink
(
const
t
string
&
base_filename
,
const
std
::
string
&
base_filename
,
const
t
string
&
extension
,
const
std
::
string
&
extension
,
int
rotation_hour
,
int
rotation_hour
,
int
rotation_minute
,
int
rotation_minute
,
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
bool
force_flush
=
false
)
:
_base_filename
(
base_filename
),
...
@@ -211,16 +210,16 @@ private:
...
@@ -211,16 +210,16 @@ private:
}
}
//Create filename for the form basename.YYYY-MM-DD.extension
//Create filename for the form basename.YYYY-MM-DD.extension
static
tstring
calc_filename
(
const
tstring
&
basename
,
const
t
string
&
extension
)
static
std
::
string
calc_filename
(
const
std
::
string
&
basename
,
const
std
::
string
&
extension
)
{
{
std
::
tm
tm
=
spdlog
::
details
::
os
::
localtime
();
std
::
tm
tm
=
spdlog
::
details
::
os
::
localtime
();
fmt
::
T
MemoryWriter
w
;
fmt
::
MemoryWriter
w
;
w
.
write
(
S
(
"{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.{}"
)
,
basename
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
extension
);
w
.
write
(
"{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.{}"
,
basename
,
tm
.
tm_year
+
1900
,
tm
.
tm_mon
+
1
,
tm
.
tm_mday
,
tm
.
tm_hour
,
tm
.
tm_min
,
extension
);
return
w
.
str
();
return
w
.
str
();
}
}
t
string
_base_filename
;
std
::
string
_base_filename
;
t
string
_extension
;
std
::
string
_extension
;
int
_rotation_h
;
int
_rotation_h
;
int
_rotation_m
;
int
_rotation_m
;
std
::
chrono
::
system_clock
::
time_point
_rotation_tp
;
std
::
chrono
::
system_clock
::
time_point
_rotation_tp
;
...
...
include/spdlog/spdlog.h
View file @
cadd181d
...
@@ -76,14 +76,14 @@ void set_sync_mode();
...
@@ -76,14 +76,14 @@ void set_sync_mode();
//
//
// Create and register multi/single threaded rotating file logger
// Create and register multi/single threaded rotating file logger
//
//
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
tstring
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
rotating_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filenameB
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
rotating_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
size_t
max_file_size
,
size_t
max_files
,
bool
force_flush
=
false
);
//
//
// Create file logger which creates new file on the given time (default in midnight):
// Create file logger which creates new file on the given time (default in midnight):
//
//
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_mt
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
t
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
std
::
shared_ptr
<
logger
>
daily_logger_st
(
const
std
::
string
&
logger_name
,
const
std
::
string
&
filename
,
int
hour
=
0
,
int
minute
=
0
,
bool
force_flush
=
false
);
//
//
...
...
include/spdlog/tweakme.h
View file @
cadd181d
...
@@ -72,9 +72,3 @@
...
@@ -72,9 +72,3 @@
// Note that upon creating a logger the registry is modified by spdlog..
// Note that upon creating a logger the registry is modified by spdlog..
// #define SPDLOG_NO_REGISTRY_MUTEX
// #define SPDLOG_NO_REGISTRY_MUTEX
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable usage of wchar_t for file names on Windows.
// #define SPDLOG_USE_WCHAR
///////////////////////////////////////////////////////////////////////////////
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