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
93be7713
Commit
93be7713
authored
Nov 06, 2017
by
gabime
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
astyle
parent
6ab2f0e0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
237 additions
and
188 deletions
+237
-188
mpmc_bounded_q.h
include/spdlog/details/mpmc_bounded_q.h
+0
-0
os.h
include/spdlog/details/os.h
+0
-0
format.h
include/spdlog/fmt/bundled/format.h
+0
-0
ostream.h
include/spdlog/fmt/bundled/ostream.h
+56
-47
posix.h
include/spdlog/fmt/bundled/posix.h
+0
-0
printf.h
include/spdlog/fmt/bundled/printf.h
+0
-0
time.h
include/spdlog/fmt/bundled/time.h
+143
-103
spdlog.h
include/spdlog/spdlog.h
+4
-4
includes.h
tests/includes.h
+2
-2
test_macros.cpp
tests/test_macros.cpp
+28
-28
utils.cpp
tests/utils.cpp
+4
-4
No files found.
include/spdlog/details/mpmc_bounded_q.h
View file @
93be7713
This diff is collapsed.
Click to expand it.
include/spdlog/details/os.h
View file @
93be7713
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/format.h
View file @
93be7713
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/ostream.h
View file @
93be7713
...
...
@@ -13,57 +13,65 @@
#include "format.h"
#include <ostream>
namespace
fmt
{
namespace
fmt
{
namespace
internal
{
namespace
internal
{
template
<
class
Char
>
class
FormatBuf
:
public
std
::
basic_streambuf
<
Char
>
{
private
:
typedef
typename
std
::
basic_streambuf
<
Char
>::
int_type
int_type
;
typedef
typename
std
::
basic_streambuf
<
Char
>::
traits_type
traits_type
;
Buffer
<
Char
>
&
buffer_
;
public
:
FormatBuf
(
Buffer
<
Char
>
&
buffer
)
:
buffer_
(
buffer
)
{}
protected
:
// The put-area is actually always empty. This makes the implementation
// simpler and has the advantage that the streambuf and the buffer are always
// in sync and sputc never writes into uninitialized memory. The obvious
// disadvantage is that each call to sputc always results in a (virtual) call
// to overflow. There is no disadvantage here for sputn since this always
// results in a call to xsputn.
int_type
overflow
(
int_type
ch
=
traits_type
::
eof
())
FMT_OVERRIDE
{
if
(
!
traits_type
::
eq_int_type
(
ch
,
traits_type
::
eof
()))
buffer_
.
push_back
(
static_cast
<
Char
>
(
ch
));
return
ch
;
}
std
::
streamsize
xsputn
(
const
Char
*
s
,
std
::
streamsize
count
)
FMT_OVERRIDE
{
buffer_
.
append
(
s
,
s
+
count
);
return
count
;
}
class
FormatBuf
:
public
std
::
basic_streambuf
<
Char
>
{
private
:
typedef
typename
std
::
basic_streambuf
<
Char
>::
int_type
int_type
;
typedef
typename
std
::
basic_streambuf
<
Char
>::
traits_type
traits_type
;
Buffer
<
Char
>
&
buffer_
;
public
:
FormatBuf
(
Buffer
<
Char
>
&
buffer
)
:
buffer_
(
buffer
)
{}
protected
:
// The put-area is actually always empty. This makes the implementation
// simpler and has the advantage that the streambuf and the buffer are always
// in sync and sputc never writes into uninitialized memory. The obvious
// disadvantage is that each call to sputc always results in a (virtual) call
// to overflow. There is no disadvantage here for sputn since this always
// results in a call to xsputn.
int_type
overflow
(
int_type
ch
=
traits_type
::
eof
())
FMT_OVERRIDE
{
if
(
!
traits_type
::
eq_int_type
(
ch
,
traits_type
::
eof
()))
buffer_
.
push_back
(
static_cast
<
Char
>
(
ch
));
return
ch
;
}
std
::
streamsize
xsputn
(
const
Char
*
s
,
std
::
streamsize
count
)
FMT_OVERRIDE
{
buffer_
.
append
(
s
,
s
+
count
);
return
count
;
}
};
Yes
&
convert
(
std
::
ostream
&
);
struct
DummyStream
:
std
::
ostream
{
DummyStream
();
// Suppress a bogus warning in MSVC.
// Hide all operator<< overloads from std::ostream.
void
operator
<<
(
Null
<>
);
struct
DummyStream
:
std
::
ostream
{
DummyStream
();
// Suppress a bogus warning in MSVC.
// Hide all operator<< overloads from std::ostream.
void
operator
<<
(
Null
<>
);
};
No
&
operator
<<
(
std
::
ostream
&
,
int
);
template
<
typename
T
>
struct
ConvertToIntImpl
<
T
,
true
>
{
// Convert to int only if T doesn't have an overloaded operator<<.
enum
{
value
=
sizeof
(
convert
(
get
<
DummyStream
>
()
<<
get
<
T
>
()))
==
sizeof
(
No
)
};
struct
ConvertToIntImpl
<
T
,
true
>
{
// Convert to int only if T doesn't have an overloaded operator<<.
enum
{
value
=
sizeof
(
convert
(
get
<
DummyStream
>
()
<<
get
<
T
>
()))
==
sizeof
(
No
)
};
};
// Write the content of w to os.
...
...
@@ -73,16 +81,17 @@ FMT_API void write(std::ostream &os, Writer &w);
// Formats a value.
template
<
typename
Char
,
typename
ArgFormatter_
,
typename
T
>
void
format_arg
(
BasicFormatter
<
Char
,
ArgFormatter_
>
&
f
,
const
Char
*&
format_str
,
const
T
&
value
)
{
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer
;
const
Char
*&
format_str
,
const
T
&
value
)
{
internal
::
MemoryBuffer
<
Char
,
internal
::
INLINE_BUFFER_SIZE
>
buffer
;
internal
::
FormatBuf
<
Char
>
format_buf
(
buffer
);
std
::
basic_ostream
<
Char
>
output
(
&
format_buf
);
output
<<
value
;
internal
::
FormatBuf
<
Char
>
format_buf
(
buffer
);
std
::
basic_ostream
<
Char
>
output
(
&
format_buf
);
output
<<
value
;
BasicStringRef
<
Char
>
str
(
&
buffer
[
0
],
buffer
.
size
());
typedef
internal
::
MakeArg
<
BasicFormatter
<
Char
>
>
MakeArg
;
format_str
=
f
.
format
(
format_str
,
MakeArg
(
str
));
BasicStringRef
<
Char
>
str
(
&
buffer
[
0
],
buffer
.
size
());
typedef
internal
::
MakeArg
<
BasicFormatter
<
Char
>
>
MakeArg
;
format_str
=
f
.
format
(
format_str
,
MakeArg
(
str
));
}
/**
...
...
include/spdlog/fmt/bundled/posix.h
View file @
93be7713
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/printf.h
View file @
93be7713
This diff is collapsed.
Click to expand it.
include/spdlog/fmt/bundled/time.h
View file @
93be7713
...
...
@@ -19,120 +19,160 @@
# pragma warning(disable: 4996) // "deprecated" functions
#endif
namespace
fmt
{
namespace
fmt
{
template
<
typename
ArgFormatter
>
void
format_arg
(
BasicFormatter
<
char
,
ArgFormatter
>
&
f
,
const
char
*&
format_str
,
const
std
::
tm
&
tm
)
{
if
(
*
format_str
==
':'
)
++
format_str
;
const
char
*
end
=
format_str
;
while
(
*
end
&&
*
end
!=
'}'
)
++
end
;
if
(
*
end
!=
'}'
)
FMT_THROW
(
FormatError
(
"missing '}' in format string"
));
internal
::
MemoryBuffer
<
char
,
internal
::
INLINE_BUFFER_SIZE
>
format
;
format
.
append
(
format_str
,
end
+
1
);
format
[
format
.
size
()
-
1
]
=
'\0'
;
Buffer
<
char
>
&
buffer
=
f
.
writer
().
buffer
();
std
::
size_t
start
=
buffer
.
size
();
for
(;;)
{
std
::
size_t
size
=
buffer
.
capacity
()
-
start
;
std
::
size_t
count
=
std
::
strftime
(
&
buffer
[
start
],
size
,
&
format
[
0
],
&
tm
);
if
(
count
!=
0
)
{
buffer
.
resize
(
start
+
count
);
break
;
const
char
*&
format_str
,
const
std
::
tm
&
tm
)
{
if
(
*
format_str
==
':'
)
++
format_str
;
const
char
*
end
=
format_str
;
while
(
*
end
&&
*
end
!=
'}'
)
++
end
;
if
(
*
end
!=
'}'
)
FMT_THROW
(
FormatError
(
"missing '}' in format string"
));
internal
::
MemoryBuffer
<
char
,
internal
::
INLINE_BUFFER_SIZE
>
format
;
format
.
append
(
format_str
,
end
+
1
);
format
[
format
.
size
()
-
1
]
=
'\0'
;
Buffer
<
char
>
&
buffer
=
f
.
writer
().
buffer
();
std
::
size_t
start
=
buffer
.
size
();
for
(;;)
{
std
::
size_t
size
=
buffer
.
capacity
()
-
start
;
std
::
size_t
count
=
std
::
strftime
(
&
buffer
[
start
],
size
,
&
format
[
0
],
&
tm
);
if
(
count
!=
0
)
{
buffer
.
resize
(
start
+
count
);
break
;
}
if
(
size
>=
format
.
size
()
*
256
)
{
// If the buffer is 256 times larger than the format string, assume
// that `strftime` gives an empty result. There doesn't seem to be a
// better way to distinguish the two cases:
// https://github.com/fmtlib/fmt/issues/367
break
;
}
const
std
::
size_t
MIN_GROWTH
=
10
;
buffer
.
reserve
(
buffer
.
capacity
()
+
(
size
>
MIN_GROWTH
?
size
:
MIN_GROWTH
));
}
if
(
size
>=
format
.
size
()
*
256
)
{
// If the buffer is 256 times larger than the format string, assume
// that `strftime` gives an empty result. There doesn't seem to be a
// better way to distinguish the two cases:
// https://github.com/fmtlib/fmt/issues/367
break
;
}
const
std
::
size_t
MIN_GROWTH
=
10
;
buffer
.
reserve
(
buffer
.
capacity
()
+
(
size
>
MIN_GROWTH
?
size
:
MIN_GROWTH
));
}
format_str
=
end
+
1
;
format_str
=
end
+
1
;
}
namespace
internal
{
inline
Null
<>
localtime_r
(...)
{
return
Null
<>
();
}
inline
Null
<>
localtime_s
(...)
{
return
Null
<>
();
}
inline
Null
<>
gmtime_r
(...)
{
return
Null
<>
();
}
inline
Null
<>
gmtime_s
(...)
{
return
Null
<>
();
}
namespace
internal
{
inline
Null
<>
localtime_r
(...)
{
return
Null
<>
();
}
inline
Null
<>
localtime_s
(...)
{
return
Null
<>
();
}
inline
Null
<>
gmtime_r
(...)
{
return
Null
<>
();
}
inline
Null
<>
gmtime_s
(...)
{
return
Null
<>
();
}
}
// Thread-safe replacement for std::localtime
inline
std
::
tm
localtime
(
std
::
time_t
time
)
{
struct
LocalTime
{
std
::
time_t
time_
;
std
::
tm
tm_
;
LocalTime
(
std
::
time_t
t
)
:
time_
(
t
)
{}
bool
run
()
{
using
namespace
fmt
::
internal
;
return
handle
(
localtime_r
(
&
time_
,
&
tm_
));
}
bool
handle
(
std
::
tm
*
tm
)
{
return
tm
!=
FMT_NULL
;
}
bool
handle
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
return
fallback
(
localtime_s
(
&
tm_
,
&
time_
));
}
bool
fallback
(
int
res
)
{
return
res
==
0
;
}
bool
fallback
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
std
::
tm
*
tm
=
std
::
localtime
(
&
time_
);
if
(
tm
)
tm_
=
*
tm
;
return
tm
!=
FMT_NULL
;
}
};
LocalTime
lt
(
time
);
if
(
lt
.
run
())
return
lt
.
tm_
;
// Too big time values may be unsupported.
FMT_THROW
(
fmt
::
FormatError
(
"time_t value out of range"
));
return
std
::
tm
();
inline
std
::
tm
localtime
(
std
::
time_t
time
)
{
struct
LocalTime
{
std
::
time_t
time_
;
std
::
tm
tm_
;
LocalTime
(
std
::
time_t
t
)
:
time_
(
t
)
{}
bool
run
()
{
using
namespace
fmt
::
internal
;
return
handle
(
localtime_r
(
&
time_
,
&
tm_
));
}
bool
handle
(
std
::
tm
*
tm
)
{
return
tm
!=
FMT_NULL
;
}
bool
handle
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
return
fallback
(
localtime_s
(
&
tm_
,
&
time_
));
}
bool
fallback
(
int
res
)
{
return
res
==
0
;
}
bool
fallback
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
std
::
tm
*
tm
=
std
::
localtime
(
&
time_
);
if
(
tm
)
tm_
=
*
tm
;
return
tm
!=
FMT_NULL
;
}
};
LocalTime
lt
(
time
);
if
(
lt
.
run
())
return
lt
.
tm_
;
// Too big time values may be unsupported.
FMT_THROW
(
fmt
::
FormatError
(
"time_t value out of range"
));
return
std
::
tm
();
}
// Thread-safe replacement for std::gmtime
inline
std
::
tm
gmtime
(
std
::
time_t
time
)
{
struct
GMTime
{
std
::
time_t
time_
;
std
::
tm
tm_
;
GMTime
(
std
::
time_t
t
)
:
time_
(
t
)
{}
bool
run
()
{
using
namespace
fmt
::
internal
;
return
handle
(
gmtime_r
(
&
time_
,
&
tm_
));
}
bool
handle
(
std
::
tm
*
tm
)
{
return
tm
!=
FMT_NULL
;
}
bool
handle
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
return
fallback
(
gmtime_s
(
&
tm_
,
&
time_
));
}
bool
fallback
(
int
res
)
{
return
res
==
0
;
}
bool
fallback
(
internal
::
Null
<>
)
{
std
::
tm
*
tm
=
std
::
gmtime
(
&
time_
);
if
(
tm
!=
FMT_NULL
)
tm_
=
*
tm
;
return
tm
!=
FMT_NULL
;
}
};
GMTime
gt
(
time
);
if
(
gt
.
run
())
return
gt
.
tm_
;
// Too big time values may be unsupported.
FMT_THROW
(
fmt
::
FormatError
(
"time_t value out of range"
));
return
std
::
tm
();
inline
std
::
tm
gmtime
(
std
::
time_t
time
)
{
struct
GMTime
{
std
::
time_t
time_
;
std
::
tm
tm_
;
GMTime
(
std
::
time_t
t
)
:
time_
(
t
)
{}
bool
run
()
{
using
namespace
fmt
::
internal
;
return
handle
(
gmtime_r
(
&
time_
,
&
tm_
));
}
bool
handle
(
std
::
tm
*
tm
)
{
return
tm
!=
FMT_NULL
;
}
bool
handle
(
internal
::
Null
<>
)
{
using
namespace
fmt
::
internal
;
return
fallback
(
gmtime_s
(
&
tm_
,
&
time_
));
}
bool
fallback
(
int
res
)
{
return
res
==
0
;
}
bool
fallback
(
internal
::
Null
<>
)
{
std
::
tm
*
tm
=
std
::
gmtime
(
&
time_
);
if
(
tm
!=
FMT_NULL
)
tm_
=
*
tm
;
return
tm
!=
FMT_NULL
;
}
};
GMTime
gt
(
time
);
if
(
gt
.
run
())
return
gt
.
tm_
;
// Too big time values may be unsupported.
FMT_THROW
(
fmt
::
FormatError
(
"time_t value out of range"
));
return
std
::
tm
();
}
}
//namespace fmt
...
...
include/spdlog/spdlog.h
View file @
93be7713
...
...
@@ -169,11 +169,11 @@ void drop_all();
#define SPDLOG_STR_H(x) #x
#define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x)
#ifdef _MSC_VER
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[ " __FILE__ "(" SPDLOG_STR_HELPER(__LINE__) ") ] " __VA_ARGS__)
#else
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#define SPDLOG_TRACE(logger, ...) logger->trace("[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[ " __FILE__ ":" SPDLOG_STR_HELPER(__LINE__) " ] " __VA_ARGS__)
#endif
#else
#define SPDLOG_TRACE(logger, ...)
...
...
tests/includes.h
View file @
93be7713
...
...
@@ -10,8 +10,8 @@
#include "catch.hpp"
#include "utils.h"
#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON
#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON
#include "../include/spdlog/spdlog.h"
#include "../include/spdlog/sinks/null_sink.h"
...
...
tests/test_macros.cpp
View file @
93be7713
...
...
@@ -6,45 +6,45 @@
TEST_CASE
(
"debug and trace w/o format string"
,
"[macros]]"
)
{
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message 2"
);
logger
->
flush
();
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 2
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
SPDLOG_TRACE
(
logger
,
"Test message 1"
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message 2"
);
logger
->
flush
();
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 2
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
}
TEST_CASE
(
"debug and trace with format strings"
,
"[macros]]"
)
{
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
prepare_logdir
();
std
::
string
filename
=
"logs/simple_log"
;
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
auto
logger
=
spdlog
::
create
<
spdlog
::
sinks
::
simple_file_sink_mt
>
(
"logger"
,
filename
);
logger
->
set_pattern
(
"%v"
);
logger
->
set_level
(
spdlog
::
level
::
trace
);
#if !defined(SPDLOG_FMT_PRINTF)
SPDLOG_TRACE
(
logger
,
"Test message {}"
,
1
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message {}"
,
222
);
SPDLOG_TRACE
(
logger
,
"Test message {}"
,
1
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message {}"
,
222
);
#else
SPDLOG_TRACE
(
logger
,
"Test message %d"
,
1
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message %d"
,
222
);
SPDLOG_TRACE
(
logger
,
"Test message %d"
,
1
);
//SPDLOG_DEBUG(logger, "Test message 2");
SPDLOG_DEBUG
(
logger
,
"Test message %d"
,
222
);
#endif
logger
->
flush
();
logger
->
flush
();
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 222
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
REQUIRE
(
ends_with
(
file_contents
(
filename
),
"Test message 222
\n
"
));
REQUIRE
(
count_lines
(
filename
)
==
2
);
}
tests/utils.cpp
View file @
93be7713
...
...
@@ -49,8 +49,8 @@ std::size_t get_filesize(const std::string& filename)
// source: https://stackoverflow.com/a/2072890/192001
bool
ends_with
(
std
::
string
const
&
value
,
std
::
string
const
&
ending
)
{
if
(
ending
.
size
()
>
value
.
size
())
return
false
;
return
std
::
equal
(
ending
.
rbegin
(),
ending
.
rend
(),
value
.
rbegin
());
bool
ends_with
(
std
::
string
const
&
value
,
std
::
string
const
&
ending
)
{
if
(
ending
.
size
()
>
value
.
size
())
return
false
;
return
std
::
equal
(
ending
.
rbegin
(),
ending
.
rend
(),
value
.
rbegin
());
}
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