mirror of https://github.com/gabime/spdlog.git
Merge remote-tracking branch 'upstream/master'
# Conflicts: # include/spdlog/details/format.cc # include/spdlog/sinks/stdout_sinks.hpull/51/head
commit
c8846db7cc
@ -0,0 +1,108 @@
|
||||
# Adapted from various sources, including:
|
||||
# - Louis Dionne's Hana: https://github.com/ldionne/hana
|
||||
# - Paul Fultz II's FIT: https://github.com/pfultz2/Fit
|
||||
# - Eric Niebler's range-v3: https://github.com/ericniebler/range-v3
|
||||
language: cpp
|
||||
|
||||
# Test matrix:
|
||||
# - Build matrix per compiler: C++11/C++14 + Debug/Release
|
||||
# - Optionally: AddressSanitizer (ASAN)
|
||||
# - Valgrind: all release builds are also tested with valgrind
|
||||
# - clang 3.4, 3.5, 3.6, trunk
|
||||
# - Note: 3.4 and trunk are tested with/without ASAN,
|
||||
# the rest is only tested with ASAN=On.
|
||||
# - gcc 4.9, 5.0
|
||||
#
|
||||
matrix:
|
||||
include:
|
||||
# Test clang-3.5: C++11/C++14, Buidd=Debug/Release, ASAN=On/Off
|
||||
- env: CLANG_VERSION=3.5 BUILD_TYPE=Debug CPP=11 ASAN=On LIBCXX=On
|
||||
os: linux
|
||||
addons: &clang35
|
||||
apt:
|
||||
packages:
|
||||
- clang-3.5
|
||||
- valgrind
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.5
|
||||
|
||||
|
||||
- env: CLANG_VERSION=3.5 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=On
|
||||
os: linux
|
||||
addons: *clang35
|
||||
|
||||
|
||||
|
||||
# Test gcc-4.8: C++11, Build=Debug/Release, ASAN=Off
|
||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off
|
||||
os: linux
|
||||
addons: &gcc48
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.8
|
||||
- valgrind
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- env: GCC_VERSION=4.8 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off
|
||||
os: linux
|
||||
addons: *gcc48
|
||||
|
||||
# Test gcc-4.9: C++11, Build=Debug/Release, ASAN=Off
|
||||
- env: GCC_VERSION=4.9 BUILD_TYPE=Debug CPP=11 ASAN=Off LIBCXX=Off
|
||||
os: linux
|
||||
addons: &gcc49
|
||||
apt:
|
||||
packages:
|
||||
- g++-4.9
|
||||
- valgrind
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
|
||||
- env: GCC_VERSION=4.9 BUILD_TYPE=Release CPP=11 ASAN=Off LIBCXX=Off
|
||||
os: linux
|
||||
addons: *gcc49
|
||||
|
||||
# Install dependencies
|
||||
before_install:
|
||||
- export CHECKOUT_PATH=`pwd`;
|
||||
- if [ -n "$GCC_VERSION" ]; then export CXX="g++-${GCC_VERSION}" CC="gcc-${GCC_VERSION}"; fi
|
||||
- if [ -n "$CLANG_VERSION" ]; then export CXX="clang++-${CLANG_VERSION}" CC="clang-${CLANG_VERSION}"; fi
|
||||
- if [ "$CLANG_VERSION" == "3.4" ]; then export CXX="/usr/local/clang-3.4/bin/clang++" CC="/usr/local/clang-3.4/bin/clang"; fi
|
||||
- which $CXX
|
||||
- which $CC
|
||||
- which valgrind
|
||||
- if [ -n "$CLANG_VERSION" ]; then sudo CXX=$CXX CC=$CC ./tests/install_libcxx.sh; fi
|
||||
|
||||
install:
|
||||
- cd $CHECKOUT_PATH
|
||||
|
||||
# Workaround for valgrind bug: https://bugs.kde.org/show_bug.cgi?id=326469.
|
||||
# It is fixed in valgrind 3.10 so this won't be necessary if someone
|
||||
# replaces the current valgrind (3.7) with valgrind-3.10
|
||||
- sed -i 's/march=native/msse4.2/' example/Makefile
|
||||
|
||||
- if [ ! -d build ]; then mkdir build; fi
|
||||
- export CXX_FLAGS=""
|
||||
- export CXX_LINKER_FLAGS=""
|
||||
- if [ -z "$BUILD_TYPE" ]; then export BUILD_TYPE=Release; fi
|
||||
- if [ "$ASAN" == "On"]; then export CXX_FLAGS="${CXX_FLAGS} -fsanitize=address,undefined,integer -fno-omit-frame-pointer -fno-sanitize=unsigned-integer-overflow"; fi
|
||||
- if [ -n "$CLANG_VERSION" ]; then CXX_FLAGS="${CXX_FLAGS} -D__extern_always_inline=inline"; fi
|
||||
- if [ "$LIBCXX" == "On" ]; then CXX_FLAGS="${CXX_FLAGS} -stdlib=libc++ -I/usr/include/c++/v1/"; fi
|
||||
- if [ "$LIBCXX" == "On" ]; then CXX_LINKER_FLAGS="${CXX_FLAGS} -L/usr/lib/ -lc++"; fi
|
||||
- CXX_FLAGS="${CXX_FLAGS} -std=c++${CPP}"
|
||||
|
||||
# Build examples
|
||||
- cd example
|
||||
- if [ "$BUILD_TYPE" == "Release" ]; then make rebuild CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example; fi
|
||||
- if [ "$BUILD_TYPE" == "Debug" ]; then make rebuild debug CXXFLAGS="${CXX_FLAGS} ${CXX_LINKER_FLAGS}" VERBOSE=1; export BIN=example-debug; fi
|
||||
|
||||
|
||||
script:
|
||||
- ./"${BIN}"
|
||||
- valgrind --trace-children=yes --leak-check=full ./"${BIN}"
|
||||
- cd $CHECKOUT_PATH/tests; make rebuild; ./tests
|
||||
|
||||
notifications:
|
||||
email: false
|
@ -1,235 +0,0 @@
|
||||
----------------------------------------------------------
|
||||
Single threaded benchmarks.. (1 thread, 1,000,000 lines)
|
||||
----------------------------------------------------------
|
||||
**************** boost-bench ****************
|
||||
|
||||
real 0m4.382s
|
||||
user 0m4.213s
|
||||
sys 0m0.048s
|
||||
|
||||
real 0m4.159s
|
||||
user 0m4.120s
|
||||
sys 0m0.040s
|
||||
|
||||
real 0m4.169s
|
||||
user 0m4.117s
|
||||
sys 0m0.052s
|
||||
**************** glog-bench ****************
|
||||
|
||||
real 0m1.082s
|
||||
user 0m0.944s
|
||||
sys 0m0.136s
|
||||
|
||||
real 0m1.079s
|
||||
user 0m0.977s
|
||||
sys 0m0.101s
|
||||
|
||||
real 0m1.066s
|
||||
user 0m0.951s
|
||||
sys 0m0.114s
|
||||
**************** easylogging-bench ****************
|
||||
|
||||
real 0m0.975s
|
||||
user 0m0.963s
|
||||
sys 0m0.012s
|
||||
|
||||
real 0m0.986s
|
||||
user 0m0.954s
|
||||
sys 0m0.033s
|
||||
|
||||
real 0m0.963s
|
||||
user 0m0.919s
|
||||
sys 0m0.044s
|
||||
**************** spdlog-bench ****************
|
||||
|
||||
real 0m0.302s
|
||||
user 0m0.285s
|
||||
sys 0m0.016s
|
||||
|
||||
real 0m0.311s
|
||||
user 0m0.287s
|
||||
sys 0m0.025s
|
||||
|
||||
real 0m0.308s
|
||||
user 0m0.276s
|
||||
sys 0m0.032s
|
||||
----------------------------------------------------------
|
||||
Multi threaded benchmarks.. (10 threads, 1,000,000 lines)
|
||||
----------------------------------------------------------
|
||||
**************** boost-bench-mt ****************
|
||||
|
||||
real 0m16.293s
|
||||
user 0m38.723s
|
||||
sys 0m8.469s
|
||||
|
||||
real 0m16.029s
|
||||
user 0m39.186s
|
||||
sys 0m8.413s
|
||||
|
||||
real 0m16.257s
|
||||
user 0m38.322s
|
||||
sys 0m7.880s
|
||||
**************** glog-bench-mt ****************
|
||||
|
||||
real 0m4.455s
|
||||
user 0m12.871s
|
||||
sys 0m13.508s
|
||||
|
||||
real 0m5.039s
|
||||
user 0m14.239s
|
||||
sys 0m15.900s
|
||||
|
||||
real 0m3.032s
|
||||
user 0m8.654s
|
||||
sys 0m9.473s
|
||||
**************** easylogging-bench-mt ****************
|
||||
|
||||
real 0m4.076s
|
||||
user 0m4.350s
|
||||
sys 0m2.861s
|
||||
|
||||
real 0m2.857s
|
||||
user 0m3.270s
|
||||
sys 0m1.744s
|
||||
|
||||
real 0m4.588s
|
||||
user 0m5.085s
|
||||
sys 0m3.058s
|
||||
**************** spdlog-bench-mt ****************
|
||||
|
||||
real 0m2.374s
|
||||
user 0m4.369s
|
||||
sys 0m10.426s
|
||||
|
||||
real 0m0.968s
|
||||
user 0m1.804s
|
||||
sys 0m4.186s
|
||||
|
||||
real 0m1.527s
|
||||
user 0m3.132s
|
||||
sys 0m6.427s
|
||||
----------------------------------------------------------
|
||||
Multi threaded benchmarks.. (100 threads, 1,000,000 lines)
|
||||
----------------------------------------------------------
|
||||
**************** boost-bench-mt ****************
|
||||
|
||||
real 0m15.623s
|
||||
user 0m39.283s
|
||||
sys 0m8.428s
|
||||
|
||||
real 0m15.008s
|
||||
user 0m36.851s
|
||||
sys 0m7.956s
|
||||
|
||||
real 0m15.478s
|
||||
user 0m38.873s
|
||||
sys 0m8.368s
|
||||
**************** glog-bench-mt ****************
|
||||
|
||||
real 0m1.139s
|
||||
user 0m3.003s
|
||||
sys 0m5.214s
|
||||
|
||||
real 0m1.167s
|
||||
user 0m3.004s
|
||||
sys 0m5.431s
|
||||
|
||||
real 0m1.159s
|
||||
user 0m2.909s
|
||||
sys 0m5.456s
|
||||
**************** easylogging-bench-mt ****************
|
||||
|
||||
real 0m4.510s
|
||||
user 0m4.565s
|
||||
sys 0m3.510s
|
||||
|
||||
real 0m8.841s
|
||||
user 0m8.363s
|
||||
sys 0m7.057s
|
||||
|
||||
real 0m5.638s
|
||||
user 0m5.531s
|
||||
sys 0m4.168s
|
||||
**************** spdlog-bench-mt ****************
|
||||
|
||||
real 0m0.497s
|
||||
user 0m0.951s
|
||||
sys 0m2.743s
|
||||
|
||||
real 0m0.502s
|
||||
user 0m0.940s
|
||||
sys 0m2.816s
|
||||
|
||||
real 0m0.504s
|
||||
user 0m0.911s
|
||||
sys 0m2.860s
|
||||
---------------------------------------------------------------
|
||||
Async, single threaded benchmark.. (1 thread, 1,000,000 lines)
|
||||
---------------------------------------------------------------
|
||||
**************** spdlog-async ****************
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 0.216366 seconds
|
||||
Rate = 4.62179e+06/sec
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 0.215076 seconds
|
||||
Rate = 4.64953e+06/sec
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 0.210712 seconds
|
||||
Rate = 4.74581e+06/sec
|
||||
**************** g2log-async ****************
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 1.85039 seconds
|
||||
Rate = 540428/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-214929.log
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 1.85434 seconds
|
||||
Rate = 539274/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-214935.log
|
||||
Total: 1000000
|
||||
Threads: 1
|
||||
Delta = 1.86829 seconds
|
||||
Rate = 535249/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-214941.log
|
||||
---------------------------------------------------------------
|
||||
Async, multi threaded benchmark.. (10 threads, 1,000,000 lines)
|
||||
---------------------------------------------------------------
|
||||
**************** spdlog-async ****************
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.175684 seconds
|
||||
Rate = 5.69204e+06/sec
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.173104 seconds
|
||||
Rate = 5.77688e+06/sec
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.173881 seconds
|
||||
Rate = 5.75106e+06/sec
|
||||
**************** g2log-async ****************
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.945252 seconds
|
||||
Rate = 1.05792e+06/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-214958.log
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.950362 seconds
|
||||
Rate = 1.05223e+06/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-215004.log
|
||||
Total: 1000000
|
||||
Threads: 10
|
||||
Delta = 0.943302 seconds
|
||||
Rate = 1.06011e+06/sec
|
||||
|
||||
Exiting, log location: logs/g2log-async.g2log.20141220-215011.log
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,74 @@
|
||||
/*************************************************************************/
|
||||
/* spdlog - an extremely fast and easy to use c++11 logging library. */
|
||||
/* Copyright (c) 2014 Gabi Melman. */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Edit this file to squeeze every last drop of performance out of spdlog.
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Under Linux, the much faster CLOCK_REALTIME_COARSE clock can be used.
|
||||
// This clock is less accurate - can be off by dozens of millis - depending on the kernel HZ.
|
||||
// Uncomment to use it instead of the regular (but slower) clock.
|
||||
// #define SPDLOG_CLOCK_COARSE
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if date/time logging is not needed.
|
||||
// This will prevent spdlog from quering the clock on each log call.
|
||||
// #define SPDLOG_NO_DATETIME
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if thread id logging is not needed (i.e. no %t in the log pattern).
|
||||
// This will prevent spdlog from quering the thread id on each log call.
|
||||
// #define SPDLOG_NO_THREAD_ID
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment if logger name logging is not needed.
|
||||
// This will prevent spdlog from copying the logger name on each log call.
|
||||
// #define SPDLOG_NO_NAME
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment to enable the SPDLOG_DEBUG/SPDLOG_TRACE macros.
|
||||
// #define SPDLOG_DEBUG_ON
|
||||
// #define SPDLOG_TRACE_ON
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Uncomment to avoid locking in the registry operations (spdlog::get(), spdlog::drop() spdlog::register()).
|
||||
// Use only if your code never modifes concurrently the registry.
|
||||
// Note that upon creating a logger the registry is modified by spdlog..
|
||||
// #define SPDLOG_NO_REGISTRY_MUTEX
|
||||
///////////////////////////////////////////////////////////////////////////////
|
@ -0,0 +1,22 @@
|
||||
CXX ?= g++
|
||||
CXXFLAGS = -Wall -pedantic -std=c++11 -pthread -O2
|
||||
LDPFALGS = -pthread
|
||||
|
||||
CPP_FILES := $(wildcard *.cpp)
|
||||
OBJ_FILES := $(addprefix ./,$(notdir $(CPP_FILES:.cpp=.o)))
|
||||
|
||||
|
||||
tests: $(OBJ_FILES)
|
||||
$(CXX) $(CXXFLAGS) $(LDPFALGS) -o $@ $^
|
||||
mkdir -p logs
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f tests *.o logs/*.txt
|
||||
|
||||
rebuild: clean tests
|
||||
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,132 @@
|
||||
#include "includes.h"
|
||||
|
||||
static std::string file_contents(const std::string& filename)
|
||||
{
|
||||
std::ifstream ifs(filename);
|
||||
if (!ifs)
|
||||
throw std::runtime_error("Failed open file ");
|
||||
return std::string((std::istreambuf_iterator<char>(ifs)),
|
||||
(std::istreambuf_iterator<char>()));
|
||||
|
||||
}
|
||||
|
||||
static std::size_t count_lines(const std::string& filename)
|
||||
{
|
||||
std::ifstream ifs(filename);
|
||||
if (!ifs)
|
||||
throw std::runtime_error("Failed open file ");
|
||||
|
||||
std::string line;
|
||||
size_t counter = 0;
|
||||
while(std::getline(ifs, line))
|
||||
counter++;
|
||||
return counter;
|
||||
}
|
||||
|
||||
std::ifstream::pos_type filesize(const std::string& filename)
|
||||
{
|
||||
std::ifstream ifs(filename, std::ifstream::ate | std::ifstream::binary);
|
||||
if (!ifs)
|
||||
throw std::runtime_error("Failed open file ");
|
||||
|
||||
return ifs.tellg();
|
||||
}
|
||||
|
||||
static void prepare_logdir()
|
||||
{
|
||||
spdlog::drop_all();
|
||||
#ifdef _WIN32
|
||||
auto rv = system("del /F /Q logs\\*");
|
||||
#else
|
||||
auto rv = system("rm -f logs/*");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("simple_file_logger", "[simple_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string filename = "logs/simple_log.txt";
|
||||
|
||||
auto logger = spdlog::create<spdlog::sinks::simple_file_sink_mt>("logger", filename);
|
||||
logger->set_pattern("%v");
|
||||
|
||||
|
||||
logger->info("Test message {}", 1);
|
||||
logger->info("Test message {}", 2);
|
||||
logger->flush();
|
||||
REQUIRE(file_contents(filename) == std::string("Test message 1\nTest message 2\n"));
|
||||
REQUIRE(count_lines(filename) == 2);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("rotating_file_logger1", "[rotating_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string basename = "logs/rotating_log";
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, 1024, 0, true);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
logger->info("Test message {}", i);
|
||||
|
||||
auto filename = basename + ".txt";
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
for (int i = 0; i < 1000; i++)
|
||||
logger->info("Test message {}", i);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("rotating_file_logger2", "[rotating_logger]]")
|
||||
{
|
||||
prepare_logdir();
|
||||
std::string basename = "logs/rotating_log";
|
||||
auto logger = spdlog::rotating_logger_mt("logger", basename, 1024, 1, false);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
logger->info("Test message {}", i);
|
||||
|
||||
logger->flush();
|
||||
auto filename = basename + ".txt";
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
for (int i = 0; i < 1000; i++)
|
||||
logger->info("Test message {}", i);
|
||||
|
||||
logger->flush();
|
||||
REQUIRE(filesize(filename) <= 1024);
|
||||
auto filename1 = basename + ".1.txt";
|
||||
REQUIRE(filesize(filename1) <= 1024);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("daily_logger", "[daily_logger]]")
|
||||
{
|
||||
|
||||
prepare_logdir();
|
||||
//calculate filename (time based)
|
||||
std::string basename = "logs/daily_log";
|
||||
std::tm tm = spdlog::details::os::localtime();
|
||||
fmt::MemoryWriter w;
|
||||
w.write("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}.txt", basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min);
|
||||
|
||||
auto logger = spdlog::daily_logger_mt("logger", basename, 0, 0, true);
|
||||
for (int i = 0; i < 10; ++i)
|
||||
logger->info("Test message {}", i);
|
||||
|
||||
auto filename = w.str();
|
||||
REQUIRE(count_lines(filename) == 10);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,90 @@
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
template<class T>
|
||||
std::string log_info(const T& what, spdlog::level::level_enum logger_level = spdlog::level::info)
|
||||
{
|
||||
|
||||
std::ostringstream oss;
|
||||
auto oss_sink = std::make_shared<spdlog::sinks::ostream_sink_mt>(oss);
|
||||
|
||||
spdlog::logger oss_logger("oss", oss_sink);
|
||||
oss_logger.set_level(logger_level);
|
||||
oss_logger.set_pattern("%v");
|
||||
oss_logger.info() << what;
|
||||
|
||||
//strip last eol and return the logged string
|
||||
auto eol_size = strlen(spdlog::details::os::eol());
|
||||
return oss.str().substr(0, oss.str().length() - eol_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//User defined class with operator<<
|
||||
struct some_logged_class
|
||||
{
|
||||
some_logged_class(const std::string val) :value(val) {};
|
||||
std::string value;
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& os, const some_logged_class& c)
|
||||
{
|
||||
return os << c.value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_CASE("basic_logging ", "[basic_logging]")
|
||||
{
|
||||
//const char
|
||||
REQUIRE(log_info("Hello") == "Hello");
|
||||
REQUIRE(log_info("") == "");
|
||||
|
||||
//std::string
|
||||
REQUIRE(log_info(std::string("Hello")) == "Hello");
|
||||
REQUIRE(log_info(std::string()) == std::string());
|
||||
|
||||
//Numbers
|
||||
REQUIRE(log_info(5) == "5");
|
||||
REQUIRE(log_info(5.6) == "5.6");
|
||||
|
||||
//User defined class
|
||||
REQUIRE(log_info(some_logged_class("some_val")) == "some_val");
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("log_levels", "[log_levels]")
|
||||
{
|
||||
REQUIRE(log_info("Hello", spdlog::level::err) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::critical) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::emerg) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::alert) == "");
|
||||
REQUIRE(log_info("Hello", spdlog::level::info) == "Hello");
|
||||
REQUIRE(log_info("Hello", spdlog::level::debug) == "Hello");
|
||||
REQUIRE(log_info("Hello", spdlog::level::trace) == "Hello");
|
||||
}
|
||||
|
||||
TEST_CASE("invalid_format", "[format]")
|
||||
{
|
||||
|
||||
using namespace spdlog::sinks;
|
||||
spdlog::logger null_logger("null_logger", std::make_shared<null_sink_st>());
|
||||
REQUIRE_THROWS_AS(
|
||||
null_logger.info("{} {}", "first"),
|
||||
spdlog::spdlog_ex);
|
||||
|
||||
REQUIRE_THROWS_AS(
|
||||
null_logger.info("{0:f}", "aads"),
|
||||
spdlog::spdlog_ex);
|
||||
|
||||
REQUIRE_THROWS_AS(
|
||||
null_logger.info("{0:kk}", 123),
|
||||
spdlog::spdlog_ex);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <ostream>
|
||||
#include <chrono>
|
||||
#include <exception>
|
||||
|
||||
#include "catch.hpp"
|
||||
#include "../include/spdlog/spdlog.h"
|
||||
#include "../include/spdlog/sinks/null_sink.h"
|
@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
# Install libc++ under travis
|
||||
|
||||
svn --quiet co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
|
||||
mkdir libcxx/build
|
||||
(cd libcxx/build && cmake .. -DLIBCXX_CXX_ABI=libstdc++ -DLIBCXX_CXX_ABI_INCLUDE_PATHS="/usr/include/c++/4.6;/usr/include/c++/4.6/x86_64-linux-gnu")
|
||||
make -C libcxx/build cxx -j2
|
||||
sudo cp libcxx/build/lib/libc++.so.1.0 /usr/lib/
|
||||
sudo cp -r libcxx/build/include/c++/v1 /usr/include/c++/v1/
|
||||
sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so
|
||||
sudo ln -sf /usr/lib/libc++.so.1.0 /usr/lib/libc++.so.1
|
@ -0,0 +1,2 @@
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
@ -0,0 +1,53 @@
|
||||
#include "includes.h"
|
||||
|
||||
static const char *logger_name = "null_logger";
|
||||
|
||||
TEST_CASE("register_drop", "[registry]")
|
||||
{
|
||||
spdlog::drop_all();
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(logger_name);
|
||||
REQUIRE(spdlog::get(logger_name)!=nullptr);
|
||||
//Throw if registring existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("explicit register" "[registry]")
|
||||
{
|
||||
spdlog::drop_all();
|
||||
auto logger = std::make_shared<spdlog::logger>(logger_name, std::make_shared<spdlog::sinks::null_sink_st>());
|
||||
spdlog::register_logger(logger);
|
||||
REQUIRE(spdlog::get(logger_name) != nullptr);
|
||||
//Throw if registring existing name
|
||||
REQUIRE_THROWS_AS(spdlog::create<spdlog::sinks::null_sink_mt>(logger_name), spdlog::spdlog_ex);
|
||||
}
|
||||
|
||||
TEST_CASE("drop" "[registry]")
|
||||
{
|
||||
spdlog::drop_all();
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(logger_name);
|
||||
spdlog::drop(logger_name);
|
||||
REQUIRE_FALSE(spdlog::get(logger_name));
|
||||
}
|
||||
|
||||
TEST_CASE("drop_all" "[registry]")
|
||||
{
|
||||
spdlog::drop_all();
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(logger_name);
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>("name2");
|
||||
spdlog::drop_all();
|
||||
REQUIRE_FALSE(spdlog::get(logger_name));
|
||||
REQUIRE_FALSE(spdlog::get("name2"));
|
||||
}
|
||||
|
||||
|
||||
TEST_CASE("drop non existing" "[registry]")
|
||||
{
|
||||
spdlog::drop_all();
|
||||
spdlog::create<spdlog::sinks::null_sink_mt>(logger_name);
|
||||
spdlog::drop("some_name");
|
||||
REQUIRE_FALSE(spdlog::get("some_name"));
|
||||
REQUIRE(spdlog::get(logger_name));
|
||||
spdlog::drop_all();
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="file_log.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="format.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="registry.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="includes.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="catch.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue