Repository: nifi-minifi-cpp Updated Branches: refs/heads/master 7ecdafa98 -> 8389c8aa8
http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.cc ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.cc b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.cc new file mode 100644 index 0000000..bcb67fe --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.cc @@ -0,0 +1,43 @@ +/* + Formatting library for C++ - std::ostream support + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +#include "ostream.h" + +namespace fmt { + +namespace { +// Write the content of w to os. +void write(std::ostream &os, Writer &w) { + const char *data = w.data(); + typedef internal::MakeUnsigned<std::streamsize>::Type UnsignedStreamSize; + UnsignedStreamSize size = w.size(); + UnsignedStreamSize max_size = + internal::to_unsigned((std::numeric_limits<std::streamsize>::max)()); + do { + UnsignedStreamSize n = size <= max_size ? size : max_size; + os.write(data, static_cast<std::streamsize>(n)); + data += n; + size -= n; + } while (size != 0); +} +} + +FMT_FUNC void print(std::ostream &os, CStringRef format_str, ArgList args) { + MemoryWriter w; + w.write(format_str, args); + write(os, w); +} + +FMT_FUNC int fprintf(std::ostream &os, CStringRef format, ArgList args) { + MemoryWriter w; + printf(w, format, args); + write(os, w); + return static_cast<int>(w.size()); +} +} // namespace fmt http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.h b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.h new file mode 100644 index 0000000..c52646d --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/ostream.h @@ -0,0 +1,126 @@ +/* + Formatting library for C++ - std::ostream support + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +#ifndef FMT_OSTREAM_H_ +#define FMT_OSTREAM_H_ + +#include "format.h" +#include <ostream> + +namespace fmt +{ + +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_; + Char *start_; + +public: + FormatBuf(Buffer<Char> &buffer) : buffer_(buffer), start_(&buffer[0]) + { + this->setp(start_, start_ + buffer_.capacity()); + } + + int_type overflow(int_type ch = traits_type::eof()) + { + if (!traits_type::eq_int_type(ch, traits_type::eof())) + { + size_t buf_size = size(); + buffer_.resize(buf_size); + buffer_.reserve(buf_size * 2); + + start_ = &buffer_[0]; + start_[buf_size] = traits_type::to_char_type(ch); + this->setp(start_+ buf_size + 1, start_ + buf_size * 2); + } + return ch; + } + + size_t size() const + { + return to_unsigned(this->pptr() - start_); + } +}; + +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<>); +}; + +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) + }; +}; +} // namespace internal + +// Formats a value. +template <typename Char, typename ArgFormatter, typename T> +void format(BasicFormatter<Char, ArgFormatter> &f, + 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; + + BasicStringRef<Char> str(&buffer[0], format_buf.size()); + typedef internal::MakeArg< BasicFormatter<Char> > MakeArg; + format_str = f.format(format_str, MakeArg(str)); +} + +/** + \rst + Prints formatted data to the stream *os*. + + **Example**:: + + print(cerr, "Don't {}!", "panic"); + \endrst + */ +FMT_API void print(std::ostream &os, CStringRef format_str, ArgList args); +FMT_VARIADIC(void, print, std::ostream &, CStringRef) + +/** + \rst + Prints formatted data to the stream *os*. + + **Example**:: + + fprintf(cerr, "Don't %s!", "panic"); + \endrst + */ +FMT_API int fprintf(std::ostream &os, CStringRef format_str, ArgList args); +FMT_VARIADIC(int, fprintf, std::ostream &, CStringRef) +} // namespace fmt + +#ifdef FMT_HEADER_ONLY +# include "ostream.cc" +#endif + +#endif // FMT_OSTREAM_H_ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.cc ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.cc b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.cc new file mode 100644 index 0000000..76eb7f0 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.cc @@ -0,0 +1,238 @@ +/* + A C++ interface to POSIX functions. + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +// Disable bogus MSVC warnings. +#ifndef _CRT_SECURE_NO_WARNINGS +# define _CRT_SECURE_NO_WARNINGS +#endif + +#include "posix.h" + +#include <limits.h> +#include <sys/types.h> +#include <sys/stat.h> + +#ifndef _WIN32 +# include <unistd.h> +#else +# include <windows.h> +# include <io.h> + +# define O_CREAT _O_CREAT +# define O_TRUNC _O_TRUNC + +# ifndef S_IRUSR +# define S_IRUSR _S_IREAD +# endif + +# ifndef S_IWUSR +# define S_IWUSR _S_IWRITE +# endif + +# ifdef __MINGW32__ +# define _SH_DENYNO 0x40 +# endif + +#endif // _WIN32 + +#ifdef fileno +# undef fileno +#endif + +namespace { +#ifdef _WIN32 +// Return type of read and write functions. +typedef int RWResult; + +// On Windows the count argument to read and write is unsigned, so convert +// it from size_t preventing integer overflow. +inline unsigned convert_rwcount(std::size_t count) { + return count <= UINT_MAX ? static_cast<unsigned>(count) : UINT_MAX; +} +#else +// Return type of read and write functions. +typedef ssize_t RWResult; + +inline std::size_t convert_rwcount(std::size_t count) { return count; } +#endif +} + +fmt::BufferedFile::~BufferedFile() FMT_NOEXCEPT { + if (file_ && FMT_SYSTEM(fclose(file_)) != 0) + fmt::report_system_error(errno, "cannot close file"); +} + +fmt::BufferedFile::BufferedFile( + fmt::CStringRef filename, fmt::CStringRef mode) { + FMT_RETRY_VAL(file_, FMT_SYSTEM(fopen(filename.c_str(), mode.c_str())), 0); + if (!file_) + FMT_THROW(SystemError(errno, "cannot open file {}", filename)); +} + +void fmt::BufferedFile::close() { + if (!file_) + return; + int result = FMT_SYSTEM(fclose(file_)); + file_ = 0; + if (result != 0) + FMT_THROW(SystemError(errno, "cannot close file")); +} + +// A macro used to prevent expansion of fileno on broken versions of MinGW. +#define FMT_ARGS + +int fmt::BufferedFile::fileno() const { + int fd = FMT_POSIX_CALL(fileno FMT_ARGS(file_)); + if (fd == -1) + FMT_THROW(SystemError(errno, "cannot get file descriptor")); + return fd; +} + +fmt::File::File(fmt::CStringRef path, int oflag) { + int mode = S_IRUSR | S_IWUSR; +#if defined(_WIN32) && !defined(__MINGW32__) + fd_ = -1; + FMT_POSIX_CALL(sopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, mode)); +#else + FMT_RETRY(fd_, FMT_POSIX_CALL(open(path.c_str(), oflag, mode))); +#endif + if (fd_ == -1) + FMT_THROW(SystemError(errno, "cannot open file {}", path)); +} + +fmt::File::~File() FMT_NOEXCEPT { + // Don't retry close in case of EINTR! + // See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html + if (fd_ != -1 && FMT_POSIX_CALL(close(fd_)) != 0) + fmt::report_system_error(errno, "cannot close file"); +} + +void fmt::File::close() { + if (fd_ == -1) + return; + // Don't retry close in case of EINTR! + // See http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-09/3000.html + int result = FMT_POSIX_CALL(close(fd_)); + fd_ = -1; + if (result != 0) + FMT_THROW(SystemError(errno, "cannot close file")); +} + +fmt::LongLong fmt::File::size() const { +#ifdef _WIN32 + // Use GetFileSize instead of GetFileSizeEx for the case when _WIN32_WINNT + // is less than 0x0500 as is the case with some default MinGW builds. + // Both functions support large file sizes. + DWORD size_upper = 0; + HANDLE handle = reinterpret_cast<HANDLE>(_get_osfhandle(fd_)); + DWORD size_lower = FMT_SYSTEM(GetFileSize(handle, &size_upper)); + if (size_lower == INVALID_FILE_SIZE) { + DWORD error = GetLastError(); + if (error != NO_ERROR) + FMT_THROW(WindowsError(GetLastError(), "cannot get file size")); + } + fmt::ULongLong long_size = size_upper; + return (long_size << sizeof(DWORD) * CHAR_BIT) | size_lower; +#else + typedef struct stat Stat; + Stat file_stat = Stat(); + if (FMT_POSIX_CALL(fstat(fd_, &file_stat)) == -1) + FMT_THROW(SystemError(errno, "cannot get file attributes")); + FMT_STATIC_ASSERT(sizeof(fmt::LongLong) >= sizeof(file_stat.st_size), + "return type of File::size is not large enough"); + return file_stat.st_size; +#endif +} + +std::size_t fmt::File::read(void *buffer, std::size_t count) { + RWResult result = 0; + FMT_RETRY(result, FMT_POSIX_CALL(read(fd_, buffer, convert_rwcount(count)))); + if (result < 0) + FMT_THROW(SystemError(errno, "cannot read from file")); + return internal::to_unsigned(result); +} + +std::size_t fmt::File::write(const void *buffer, std::size_t count) { + RWResult result = 0; + FMT_RETRY(result, FMT_POSIX_CALL(write(fd_, buffer, convert_rwcount(count)))); + if (result < 0) + FMT_THROW(SystemError(errno, "cannot write to file")); + return internal::to_unsigned(result); +} + +fmt::File fmt::File::dup(int fd) { + // Don't retry as dup doesn't return EINTR. + // http://pubs.opengroup.org/onlinepubs/009695399/functions/dup.html + int new_fd = FMT_POSIX_CALL(dup(fd)); + if (new_fd == -1) + FMT_THROW(SystemError(errno, "cannot duplicate file descriptor {}", fd)); + return File(new_fd); +} + +void fmt::File::dup2(int fd) { + int result = 0; + FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); + if (result == -1) { + FMT_THROW(SystemError(errno, + "cannot duplicate file descriptor {} to {}", fd_, fd)); + } +} + +void fmt::File::dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT { + int result = 0; + FMT_RETRY(result, FMT_POSIX_CALL(dup2(fd_, fd))); + if (result == -1) + ec = ErrorCode(errno); +} + +void fmt::File::pipe(File &read_end, File &write_end) { + // Close the descriptors first to make sure that assignments don't throw + // and there are no leaks. + read_end.close(); + write_end.close(); + int fds[2] = {}; +#ifdef _WIN32 + // Make the default pipe capacity same as on Linux 2.6.11+. + enum { DEFAULT_CAPACITY = 65536 }; + int result = FMT_POSIX_CALL(pipe(fds, DEFAULT_CAPACITY, _O_BINARY)); +#else + // Don't retry as the pipe function doesn't return EINTR. + // http://pubs.opengroup.org/onlinepubs/009696799/functions/pipe.html + int result = FMT_POSIX_CALL(pipe(fds)); +#endif + if (result != 0) + FMT_THROW(SystemError(errno, "cannot create pipe")); + // The following assignments don't throw because read_fd and write_fd + // are closed. + read_end = File(fds[0]); + write_end = File(fds[1]); +} + +fmt::BufferedFile fmt::File::fdopen(const char *mode) { + // Don't retry as fdopen doesn't return EINTR. + FILE *f = FMT_POSIX_CALL(fdopen(fd_, mode)); + if (!f) + FMT_THROW(SystemError(errno, "cannot associate stream with file descriptor")); + BufferedFile file(f); + fd_ = -1; + return file; +} + +long fmt::getpagesize() { +#ifdef _WIN32 + SYSTEM_INFO si; + GetSystemInfo(&si); + return si.dwPageSize; +#else + long size = FMT_POSIX_CALL(sysconf(_SC_PAGESIZE)); + if (size < 0) + FMT_THROW(SystemError(errno, "cannot get memory page size")); + return size; +#endif +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.h b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.h new file mode 100644 index 0000000..859fcaa --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/posix.h @@ -0,0 +1,443 @@ +/* + A C++ interface to POSIX functions. + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +#ifndef FMT_POSIX_H_ +#define FMT_POSIX_H_ + +#if defined(__MINGW32__) || defined(__CYGWIN__) +// Workaround MinGW bug https://sourceforge.net/p/mingw/bugs/2024/. +# undef __STRICT_ANSI__ +#endif + +#include <errno.h> +#include <fcntl.h> // for O_RDONLY +#include <locale.h> // for locale_t +#include <stdio.h> +#include <stdlib.h> // for strtod_l + +#include <cstddef> + +#if defined __APPLE__ || defined(__FreeBSD__) +# include <xlocale.h> // for LC_NUMERIC_MASK on OS X +#endif + +#include "format.h" + +#ifndef FMT_POSIX +# if defined(_WIN32) && !defined(__MINGW32__) +// Fix warnings about deprecated symbols. +# define FMT_POSIX(call) _##call +# else +# define FMT_POSIX(call) call +# endif +#endif + +// Calls to system functions are wrapped in FMT_SYSTEM for testability. +#ifdef FMT_SYSTEM +# define FMT_POSIX_CALL(call) FMT_SYSTEM(call) +#else +# define FMT_SYSTEM(call) call +# ifdef _WIN32 +// Fix warnings about deprecated symbols. +# define FMT_POSIX_CALL(call) ::_##call +# else +# define FMT_POSIX_CALL(call) ::call +# endif +#endif + +#if FMT_GCC_VERSION >= 407 +# define FMT_UNUSED __attribute__((unused)) +#else +# define FMT_UNUSED +#endif + +#ifndef FMT_USE_STATIC_ASSERT +# define FMT_USE_STATIC_ASSERT 0 +#endif + +#if FMT_USE_STATIC_ASSERT || FMT_HAS_FEATURE(cxx_static_assert) || \ + (FMT_GCC_VERSION >= 403 && FMT_HAS_GXX_CXX11) || _MSC_VER >= 1600 +# define FMT_STATIC_ASSERT(cond, message) static_assert(cond, message) +#else +# define FMT_CONCAT_(a, b) FMT_CONCAT(a, b) +# define FMT_STATIC_ASSERT(cond, message) \ + typedef int FMT_CONCAT_(Assert, __LINE__)[(cond) ? 1 : -1] FMT_UNUSED +#endif + +// Retries the expression while it evaluates to error_result and errno +// equals to EINTR. +#ifndef _WIN32 +# define FMT_RETRY_VAL(result, expression, error_result) \ + do { \ + result = (expression); \ + } while (result == error_result && errno == EINTR) +#else +# define FMT_RETRY_VAL(result, expression, error_result) result = (expression) +#endif + +#define FMT_RETRY(result, expression) FMT_RETRY_VAL(result, expression, -1) + +namespace fmt +{ + +// An error code. +class ErrorCode +{ +private: + int value_; + +public: +explicit ErrorCode(int value = 0) FMT_NOEXCEPT : + value_(value) {} + + int get() const FMT_NOEXCEPT + { + return value_; + } +}; + +// A buffered file. +class BufferedFile +{ +private: + FILE *file_; + + friend class File; + + explicit BufferedFile(FILE *f) : file_(f) {} + +public: + // Constructs a BufferedFile object which doesn't represent any file. +BufferedFile() FMT_NOEXCEPT : + file_(0) {} + + // Destroys the object closing the file it represents if any. + ~BufferedFile() FMT_NOEXCEPT; + +#if !FMT_USE_RVALUE_REFERENCES + // Emulate a move constructor and a move assignment operator if rvalue + // references are not supported. + +private: + // A proxy object to emulate a move constructor. + // It is private to make it impossible call operator Proxy directly. + struct Proxy + { + FILE *file; + }; + +public: + // A "move constructor" for moving from a temporary. +BufferedFile(Proxy p) FMT_NOEXCEPT : + file_(p.file) {} + + // A "move constructor" for moving from an lvalue. +BufferedFile(BufferedFile &f) FMT_NOEXCEPT : + file_(f.file_) + { + f.file_ = 0; + } + + // A "move assignment operator" for moving from a temporary. + BufferedFile &operator=(Proxy p) + { + close(); + file_ = p.file; + return *this; + } + + // A "move assignment operator" for moving from an lvalue. + BufferedFile &operator=(BufferedFile &other) + { + close(); + file_ = other.file_; + other.file_ = 0; + return *this; + } + + // Returns a proxy object for moving from a temporary: + // BufferedFile file = BufferedFile(...); + operator Proxy() FMT_NOEXCEPT + { + Proxy p = {file_}; + file_ = 0; + return p; + } + +#else +private: + FMT_DISALLOW_COPY_AND_ASSIGN(BufferedFile); + +public: +BufferedFile(BufferedFile &&other) FMT_NOEXCEPT : + file_(other.file_) + { + other.file_ = 0; + } + + BufferedFile& operator=(BufferedFile &&other) + { + close(); + file_ = other.file_; + other.file_ = 0; + return *this; + } +#endif + + // Opens a file. + BufferedFile(CStringRef filename, CStringRef mode); + + // Closes the file. + void close(); + + // Returns the pointer to a FILE object representing this file. + FILE *get() const FMT_NOEXCEPT + { + return file_; + } + + // We place parentheses around fileno to workaround a bug in some versions + // of MinGW that define fileno as a macro. + int (fileno)() const; + + void print(CStringRef format_str, const ArgList &args) + { + fmt::print(file_, format_str, args); + } + FMT_VARIADIC(void, print, CStringRef) +}; + +// A file. Closed file is represented by a File object with descriptor -1. +// Methods that are not declared with FMT_NOEXCEPT may throw +// fmt::SystemError in case of failure. Note that some errors such as +// closing the file multiple times will cause a crash on Windows rather +// than an exception. You can get standard behavior by overriding the +// invalid parameter handler with _set_invalid_parameter_handler. +class File +{ +private: + int fd_; // File descriptor. + + // Constructs a File object with a given descriptor. + explicit File(int fd) : fd_(fd) {} + +public: + // Possible values for the oflag argument to the constructor. + enum + { + RDONLY = FMT_POSIX(O_RDONLY), // Open for reading only. + WRONLY = FMT_POSIX(O_WRONLY), // Open for writing only. + RDWR = FMT_POSIX(O_RDWR) // Open for reading and writing. + }; + + // Constructs a File object which doesn't represent any file. +File() FMT_NOEXCEPT : + fd_(-1) {} + + // Opens a file and constructs a File object representing this file. + File(CStringRef path, int oflag); + +#if !FMT_USE_RVALUE_REFERENCES + // Emulate a move constructor and a move assignment operator if rvalue + // references are not supported. + +private: + // A proxy object to emulate a move constructor. + // It is private to make it impossible call operator Proxy directly. + struct Proxy + { + int fd; + }; + +public: + // A "move constructor" for moving from a temporary. +File(Proxy p) FMT_NOEXCEPT : + fd_(p.fd) {} + + // A "move constructor" for moving from an lvalue. +File(File &other) FMT_NOEXCEPT : + fd_(other.fd_) + { + other.fd_ = -1; + } + + // A "move assignment operator" for moving from a temporary. + File &operator=(Proxy p) + { + close(); + fd_ = p.fd; + return *this; + } + + // A "move assignment operator" for moving from an lvalue. + File &operator=(File &other) + { + close(); + fd_ = other.fd_; + other.fd_ = -1; + return *this; + } + + // Returns a proxy object for moving from a temporary: + // File file = File(...); + operator Proxy() FMT_NOEXCEPT + { + Proxy p = {fd_}; + fd_ = -1; + return p; + } + +#else +private: + FMT_DISALLOW_COPY_AND_ASSIGN(File); + +public: +File(File &&other) FMT_NOEXCEPT : + fd_(other.fd_) + { + other.fd_ = -1; + } + + File& operator=(File &&other) + { + close(); + fd_ = other.fd_; + other.fd_ = -1; + return *this; + } +#endif + + // Destroys the object closing the file it represents if any. + ~File() FMT_NOEXCEPT; + + // Returns the file descriptor. + int descriptor() const FMT_NOEXCEPT + { + return fd_; + } + + // Closes the file. + void close(); + + // Returns the file size. The size has signed type for consistency with + // stat::st_size. + LongLong size() const; + + // Attempts to read count bytes from the file into the specified buffer. + std::size_t read(void *buffer, std::size_t count); + + // Attempts to write count bytes from the specified buffer to the file. + std::size_t write(const void *buffer, std::size_t count); + + // Duplicates a file descriptor with the dup function and returns + // the duplicate as a file object. + static File dup(int fd); + + // Makes fd be the copy of this file descriptor, closing fd first if + // necessary. + void dup2(int fd); + + // Makes fd be the copy of this file descriptor, closing fd first if + // necessary. + void dup2(int fd, ErrorCode &ec) FMT_NOEXCEPT; + + // Creates a pipe setting up read_end and write_end file objects for reading + // and writing respectively. + static void pipe(File &read_end, File &write_end); + + // Creates a BufferedFile object associated with this file and detaches + // this File object from the file. + BufferedFile fdopen(const char *mode); +}; + +// Returns the memory page size. +long getpagesize(); + +#if (defined(LC_NUMERIC_MASK) || defined(_MSC_VER)) && \ + !defined(__ANDROID__) && !defined(__CYGWIN__) +# define FMT_LOCALE +#endif + +#ifdef FMT_LOCALE +// A "C" numeric locale. +class Locale +{ +private: +# ifdef _MSC_VER + typedef _locale_t locale_t; + + enum { LC_NUMERIC_MASK = LC_NUMERIC }; + + static locale_t newlocale(int category_mask, const char *locale, locale_t) + { + return _create_locale(category_mask, locale); + } + + static void freelocale(locale_t locale) + { + _free_locale(locale); + } + + static double strtod_l(const char *nptr, char **endptr, _locale_t locale) + { + return _strtod_l(nptr, endptr, locale); + } +# endif + + locale_t locale_; + + FMT_DISALLOW_COPY_AND_ASSIGN(Locale); + +public: + typedef locale_t Type; + + Locale() : locale_(newlocale(LC_NUMERIC_MASK, "C", NULL)) + { + if (!locale_) + FMT_THROW(fmt::SystemError(errno, "cannot create locale")); + } + ~Locale() + { + freelocale(locale_); + } + + Type get() const + { + return locale_; + } + + // Converts string to floating-point number and advances str past the end + // of the parsed input. + double strtod(const char *&str) const + { + char *end = 0; + double result = strtod_l(str, &end, locale_); + str = end; + return result; + } +}; +#endif // FMT_LOCALE +} // namespace fmt + +#if !FMT_USE_RVALUE_REFERENCES +namespace std +{ +// For compatibility with C++98. +inline fmt::BufferedFile &move(fmt::BufferedFile &f) +{ + return f; +} +inline fmt::File &move(fmt::File &f) +{ + return f; +} +} +#endif + +#endif // FMT_POSIX_H_ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/time.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/time.h b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/time.h new file mode 100644 index 0000000..10c6cfc --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/bundled/time.h @@ -0,0 +1,58 @@ +/* + Formatting library for C++ - time formatting + + Copyright (c) 2012 - 2016, Victor Zverovich + All rights reserved. + + For the license information refer to format.h. + */ + +#ifndef FMT_TIME_H_ +#define FMT_TIME_H_ + +#include "format.h" +#include <ctime> + +namespace fmt +{ +template <typename ArgFormatter> +void format(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; + } + 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; +} +} + +#endif // FMT_TIME_H_ http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/fmt.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/fmt.h b/thirdparty/spdlog-20170710/include/spdlog/fmt/fmt.h new file mode 100644 index 0000000..a4ee467 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/fmt.h @@ -0,0 +1,28 @@ +// +// Copyright(c) 2016 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +// +// Include a bundled header-only copy of fmtlib or an external one. +// By default spdlog include its own copy. +// + +#if !defined(SPDLOG_FMT_EXTERNAL) + +#ifndef FMT_HEADER_ONLY +#define FMT_HEADER_ONLY +#endif +#ifndef FMT_USE_WINDOWS_H +#define FMT_USE_WINDOWS_H 0 +#endif +#include "spdlog/fmt/bundled/format.h" + +#else //external fmtlib + +#include <fmt/format.h> + +#endif + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/fmt/ostr.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/fmt/ostr.h b/thirdparty/spdlog-20170710/include/spdlog/fmt/ostr.h new file mode 100644 index 0000000..49b5e98 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/fmt/ostr.h @@ -0,0 +1,17 @@ +// +// Copyright(c) 2016 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +// include external or bundled copy of fmtlib's ostream support +// +#if !defined(SPDLOG_FMT_EXTERNAL) +#include "spdlog/fmt/fmt.h" +#include "spdlog/fmt/bundled/ostream.h" +#else +#include <fmt/ostream.h> +#endif + + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/formatter.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/formatter.h b/thirdparty/spdlog-20170710/include/spdlog/formatter.h new file mode 100644 index 0000000..6bba902 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/formatter.h @@ -0,0 +1,47 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/details/log_msg.h" + +#include <vector> +#include <string> +#include <memory> + +namespace spdlog +{ +namespace details +{ +class flag_formatter; +} + +class formatter +{ +public: + virtual ~formatter() {} + virtual void format(details::log_msg& msg) = 0; +}; + +class pattern_formatter SPDLOG_FINAL : public formatter +{ + +public: + explicit pattern_formatter(const std::string& pattern, pattern_time_type pattern_time = pattern_time_type::local); + pattern_formatter(const pattern_formatter&) = delete; + pattern_formatter& operator=(const pattern_formatter&) = delete; + void format(details::log_msg& msg) override; +private: + const std::string _pattern; + const pattern_time_type _pattern_time; + std::vector<std::unique_ptr<details::flag_formatter>> _formatters; + std::tm get_time(details::log_msg& msg); + void handle_flag(char flag); + void compile_pattern(const std::string& pattern); +}; +} + +#include "spdlog/details/pattern_formatter_impl.h" + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/logger.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/logger.h b/thirdparty/spdlog-20170710/include/spdlog/logger.h new file mode 100644 index 0000000..642208e --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/logger.h @@ -0,0 +1,132 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +// Thread safe logger (except for set_pattern(..), set_formatter(..) and set_error_handler()) +// Has name, log level, vector of std::shared sink pointers and formatter +// Upon each log write the logger: +// 1. Checks if its log level is enough to log the message +// 2. Format the message using the formatter function +// 3. Pass the formatted message to its sinks to performa the actual logging + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/common.h" + +#include <vector> +#include <memory> +#include <string> + +namespace spdlog +{ + +class logger +{ +public: + logger(const std::string& logger_name, sink_ptr single_sink); + logger(const std::string& name, sinks_init_list); + template<class It> + logger(const std::string& name, const It& begin, const It& end); + + virtual ~logger(); + logger(const logger&) = delete; + logger& operator=(const logger&) = delete; + + + template <typename... Args> void log(level::level_enum lvl, const char* fmt, const Args&... args); + template <typename... Args> void log(level::level_enum lvl, const char* msg); + template <typename Arg1, typename... Args> void trace(const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void debug(const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void info(const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void warn(const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void error(const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void critical(const char* fmt, const Arg1&, const Args&... args); + + template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const char* fmt, const Args&... args); + template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const char* msg); + template <typename Arg1, typename... Args> void trace_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void debug_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void info_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void warn_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void error_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + template <typename Arg1, typename... Args> void critical_if(const bool flag, const char* fmt, const Arg1&, const Args&... args); + +#ifdef SPDLOG_WCHAR_TO_UTF8_SUPPORT + template <typename... Args> void log(level::level_enum lvl, const wchar_t* msg); + template <typename... Args> void log(level::level_enum lvl, const wchar_t* fmt, const Args&... args); + template <typename... Args> void trace(const wchar_t* fmt, const Args&... args); + template <typename... Args> void debug(const wchar_t* fmt, const Args&... args); + template <typename... Args> void info(const wchar_t* fmt, const Args&... args); + template <typename... Args> void warn(const wchar_t* fmt, const Args&... args); + template <typename... Args> void error(const wchar_t* fmt, const Args&... args); + template <typename... Args> void critical(const wchar_t* fmt, const Args&... args); + + template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const wchar_t* msg); + template <typename... Args> void log_if(const bool flag, level::level_enum lvl, const wchar_t* fmt, const Args&... args); + template <typename... Args> void trace_if(const bool flag, const wchar_t* fmt, const Args&... args); + template <typename... Args> void debug_if(const bool flag, const wchar_t* fmt, const Args&... args); + template <typename... Args> void info_if(const bool flag, const wchar_t* fmt, const Args&... args); + template <typename... Args> void warn_if(const bool flag, const wchar_t* fmt, const Args&... args); + template <typename... Args> void error_if(const bool flag, const wchar_t* fmt, const Args&... args); + template <typename... Args> void critical_if(const bool flag, const wchar_t* fmt, const Args&... args); +#endif // SPDLOG_WCHAR_TO_UTF8_SUPPORT + + template <typename T> void log(level::level_enum lvl, const T&); + template <typename T> void trace(const T&); + template <typename T> void debug(const T&); + template <typename T> void info(const T&); + template <typename T> void warn(const T&); + template <typename T> void error(const T&); + template <typename T> void critical(const T&); + + template <typename T> void log_if(const bool flag, level::level_enum lvl, const T&); + template <typename T> void trace_if(const bool flag, const T&); + template <typename T> void debug_if(const bool flag, const T&); + template <typename T> void info_if(const bool flag, const T&); + template <typename T> void warn_if(const bool flag, const T&); + template <typename T> void error_if(const bool flag, const T&); + template <typename T> void critical_if(const bool flag, const T&); + + bool should_log(level::level_enum) const; + void set_level(level::level_enum); + level::level_enum level() const; + const std::string& name() const; + void set_pattern(const std::string&, pattern_time_type = pattern_time_type::local); + void set_formatter(formatter_ptr); + + // automatically call flush() if message level >= log_level + void flush_on(level::level_enum log_level); + + virtual void flush(); + + const std::vector<sink_ptr>& sinks() const; + + // error handler + virtual void set_error_handler(log_err_handler); + virtual log_err_handler error_handler(); + +protected: + virtual void _sink_it(details::log_msg&); + virtual void _set_pattern(const std::string&, pattern_time_type); + virtual void _set_formatter(formatter_ptr); + + // default error handler: print the error to stderr with the max rate of 1 message/minute + virtual void _default_err_handler(const std::string &msg); + + // return true if the given message level should trigger a flush + bool _should_flush_on(const details::log_msg&); + + const std::string _name; + std::vector<sink_ptr> _sinks; + formatter_ptr _formatter; + spdlog::level_t _level; + spdlog::level_t _flush_level; + log_err_handler _err_handler; + std::atomic<time_t> _last_err_time; + std::atomic<size_t> _msg_counter; +}; +} + +#include "spdlog/details/logger_impl.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/android_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/android_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/android_sink.h new file mode 100644 index 0000000..239f2d2 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/android_sink.h @@ -0,0 +1,90 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#if defined(__ANDROID__) + +#include "spdlog/sinks/sink.h" + +#include <mutex> +#include <string> +#include <android/log.h> +#include <thread> +#include <chrono> + +#if !defined(SPDLOG_ANDROID_RETRIES) +#define SPDLOG_ANDROID_RETRIES 2 +#endif + +namespace spdlog +{ +namespace sinks +{ + +/* +* Android sink (logging using __android_log_write) +* __android_log_write is thread-safe. No lock is needed. +*/ +class android_sink : public sink +{ +public: + explicit android_sink(const std::string& tag = "spdlog", bool use_raw_msg = false): _tag(tag), _use_raw_msg(use_raw_msg) {} + + void log(const details::log_msg& msg) override + { + const android_LogPriority priority = convert_to_android(msg.level); + const char *msg_output = (_use_raw_msg ? msg.raw.c_str() : msg.formatted.c_str()); + + // See system/core/liblog/logger_write.c for explanation of return value + int ret = __android_log_write(priority, _tag.c_str(), msg_output); + int retry_count = 0; + while ((ret == -11/*EAGAIN*/) && (retry_count < SPDLOG_ANDROID_RETRIES)) + { + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + ret = __android_log_write(priority, _tag.c_str(), msg_output); + retry_count++; + } + + if (ret < 0) + { + throw spdlog_ex("__android_log_write() failed", ret); + } + } + + void flush() override + { + } + +private: + static android_LogPriority convert_to_android(spdlog::level::level_enum level) + { + switch(level) + { + case spdlog::level::trace: + return ANDROID_LOG_VERBOSE; + case spdlog::level::debug: + return ANDROID_LOG_DEBUG; + case spdlog::level::info: + return ANDROID_LOG_INFO; + case spdlog::level::warn: + return ANDROID_LOG_WARN; + case spdlog::level::err: + return ANDROID_LOG_ERROR; + case spdlog::level::critical: + return ANDROID_LOG_FATAL; + default: + return ANDROID_LOG_DEFAULT; + } + } + + std::string _tag; + bool _use_raw_msg; +}; + +} +} + +#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/ansicolor_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/ansicolor_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/ansicolor_sink.h new file mode 100644 index 0000000..56fd3fd --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/ansicolor_sink.h @@ -0,0 +1,133 @@ +// +// Copyright(c) 2017 spdlog authors. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/common.h" +#include "spdlog/details/os.h" + +#include <string> +#include <map> + +namespace spdlog +{ +namespace sinks +{ + +/** + * This sink prefixes the output with an ANSI escape sequence color code depending on the severity + * of the message. + * If no color terminal detected, omit the escape codes. + */ +template <class Mutex> +class ansicolor_sink: public base_sink<Mutex> +{ +public: + ansicolor_sink(FILE* file): target_file_(file) + { + should_do_colors_ = details::os::in_terminal(file) && details::os::is_color_terminal(); + colors_[level::trace] = cyan; + colors_[level::debug] = cyan; + colors_[level::info] = reset; + colors_[level::warn] = yellow + bold; + colors_[level::err] = red + bold; + colors_[level::critical] = bold + on_red; + colors_[level::off] = reset; + } + virtual ~ansicolor_sink() + { + _flush(); + } + + void set_color(level::level_enum color_level, const std::string& color) + { + std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); + colors_[color_level] = color; + } + + /// Formatting codes + const std::string reset = "\033[00m"; + const std::string bold = "\033[1m"; + const std::string dark = "\033[2m"; + const std::string underline = "\033[4m"; + const std::string blink = "\033[5m"; + const std::string reverse = "\033[7m"; + const std::string concealed = "\033[8m"; + + // Foreground colors + const std::string grey = "\033[30m"; + const std::string red = "\033[31m"; + const std::string green = "\033[32m"; + const std::string yellow = "\033[33m"; + const std::string blue = "\033[34m"; + const std::string magenta = "\033[35m"; + const std::string cyan = "\033[36m"; + const std::string white = "\033[37m"; + + /// Background colors + const std::string on_grey = "\033[40m"; + const std::string on_red = "\033[41m"; + const std::string on_green = "\033[42m"; + const std::string on_yellow = "\033[43m"; + const std::string on_blue = "\033[44m"; + const std::string on_magenta = "\033[45m"; + const std::string on_cyan = "\033[46m"; + const std::string on_white = "\033[47m"; + +protected: + virtual void _sink_it(const details::log_msg& msg) override + { + // Wrap the originally formatted message in color codes. + // If color is not supported in the terminal, log as is instead. + if (should_do_colors_) + { + const std::string& prefix = colors_[msg.level]; + fwrite(prefix.data(), sizeof(char), prefix.size(), target_file_); + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), target_file_); + fwrite(reset.data(), sizeof(char), reset.size(), target_file_); + } + else + { + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), target_file_); + } + _flush(); + } + + void _flush() override + { + fflush(target_file_); + } + FILE* target_file_; + bool should_do_colors_; + std::map<level::level_enum, std::string> colors_; +}; + + +template<class Mutex> +class ansicolor_stdout_sink: public ansicolor_sink<Mutex> +{ +public: + ansicolor_stdout_sink(): ansicolor_sink<Mutex>(stdout) + {} +}; + +template<class Mutex> +class ansicolor_stderr_sink: public ansicolor_sink<Mutex> +{ +public: + ansicolor_stderr_sink(): ansicolor_sink<Mutex>(stderr) + {} +}; + +typedef ansicolor_stdout_sink<std::mutex> ansicolor_stdout_sink_mt; +typedef ansicolor_stdout_sink<details::null_mutex> ansicolor_stdout_sink_st; + +typedef ansicolor_stderr_sink<std::mutex> ansicolor_stderr_sink_mt; +typedef ansicolor_stderr_sink<details::null_mutex> ansicolor_stderr_sink_st; + +} // namespace sinks +} // namespace spdlog + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/base_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/base_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/base_sink.h new file mode 100644 index 0000000..926f493 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/base_sink.h @@ -0,0 +1,50 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once +// +// base sink templated over a mutex (either dummy or real) +// concrete implementation should only override the _sink_it method. +// all locking is taken care of here so no locking needed by the implementers.. +// + +#include "spdlog/sinks/sink.h" +#include "spdlog/formatter.h" +#include "spdlog/common.h" +#include "spdlog/details/log_msg.h" + +#include <mutex> + +namespace spdlog +{ +namespace sinks +{ +template<class Mutex> +class base_sink:public sink +{ +public: + base_sink():_mutex() {} + virtual ~base_sink() = default; + + base_sink(const base_sink&) = delete; + base_sink& operator=(const base_sink&) = delete; + + void log(const details::log_msg& msg) SPDLOG_FINAL override + { + std::lock_guard<Mutex> lock(_mutex); + _sink_it(msg); + } + void flush() SPDLOG_FINAL override + { + _flush(); + } + +protected: + virtual void _sink_it(const details::log_msg& msg) = 0; + virtual void _flush() = 0; + Mutex _mutex; +}; +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/dist_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/dist_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/dist_sink.h new file mode 100644 index 0000000..4d4b6b6 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/dist_sink.h @@ -0,0 +1,73 @@ +// +// Copyright (c) 2015 David Schury, Gabi Melman +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/details/log_msg.h" +#include "spdlog/details/null_mutex.h" +#include "spdlog/sinks/base_sink.h" +#include "spdlog/sinks/sink.h" + +#include <algorithm> +#include <mutex> +#include <memory> +#include <vector> + +// Distribution sink (mux). Stores a vector of sinks which get called when log is called + +namespace spdlog +{ +namespace sinks +{ +template<class Mutex> +class dist_sink: public base_sink<Mutex> +{ +public: + explicit dist_sink() :_sinks() {} + dist_sink(const dist_sink&) = delete; + dist_sink& operator=(const dist_sink&) = delete; + virtual ~dist_sink() = default; + +protected: + std::vector<std::shared_ptr<sink>> _sinks; + + void _sink_it(const details::log_msg& msg) override + { + for (auto &sink : _sinks) + { + if( sink->should_log( msg.level)) + { + sink->log(msg); + } + } + } + + void _flush() override + { + std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); + for (auto &sink : _sinks) + sink->flush(); + } + +public: + + + void add_sink(std::shared_ptr<sink> sink) + { + std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); + _sinks.push_back(sink); + } + + void remove_sink(std::shared_ptr<sink> sink) + { + std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); + _sinks.erase(std::remove(_sinks.begin(), _sinks.end(), sink), _sinks.end()); + } +}; + +typedef dist_sink<std::mutex> dist_sink_mt; +typedef dist_sink<details::null_mutex> dist_sink_st; +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/file_sinks.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/file_sinks.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/file_sinks.h new file mode 100644 index 0000000..421acc8 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/file_sinks.h @@ -0,0 +1,242 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/details/null_mutex.h" +#include "spdlog/details/file_helper.h" +#include "spdlog/fmt/fmt.h" + +#include <algorithm> +#include <chrono> +#include <cstdio> +#include <ctime> +#include <mutex> +#include <string> +#include <cerrno> + +namespace spdlog +{ +namespace sinks +{ +/* + * Trivial file sink with single file as target + */ +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) + { + _file_helper.open(filename, truncate); + } + + void set_force_flush(bool force_flush) + { + _force_flush = force_flush; + } + +protected: + void _sink_it(const details::log_msg& msg) override + { + _file_helper.write(msg); + if(_force_flush) + _file_helper.flush(); + } + void _flush() override + { + _file_helper.flush(); + } +private: + details::file_helper _file_helper; + bool _force_flush; +}; + +typedef simple_file_sink<std::mutex> simple_file_sink_mt; +typedef simple_file_sink<details::null_mutex> simple_file_sink_st; + +/* + * Rotating file sink based on size + */ +template<class Mutex> +class rotating_file_sink SPDLOG_FINAL : public base_sink < Mutex > +{ +public: + rotating_file_sink(const filename_t &base_filename, + std::size_t max_size, std::size_t max_files) : + _base_filename(base_filename), + _max_size(max_size), + _max_files(max_files), + _current_size(0), + _file_helper() + { + _file_helper.open(calc_filename(_base_filename, 0)); + _current_size = _file_helper.size(); //expensive. called only once + } + + +protected: + void _sink_it(const details::log_msg& msg) override + { + _current_size += msg.formatted.size(); + if (_current_size > _max_size) + { + _rotate(); + _current_size = msg.formatted.size(); + } + _file_helper.write(msg); + } + + void _flush() override + { + _file_helper.flush(); + } + +private: + static filename_t calc_filename(const filename_t& filename, std::size_t index) + { + std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::MemoryWriter, fmt::WMemoryWriter>::type w; + if (index) + w.write(SPDLOG_FILENAME_T("{}.{}"), filename, index); + else + w.write(SPDLOG_FILENAME_T("{}"), filename); + return w.str(); + } + + // Rotate files: + // log.txt -> log.txt.1 + // log.txt.1 -> log.txt.2 + // log.txt.2 -> log.txt.3 + // lo3.txt.3 -> delete + + void _rotate() + { + using details::os::filename_to_str; + _file_helper.close(); + for (auto i = _max_files; i > 0; --i) + { + filename_t src = calc_filename(_base_filename, i - 1); + filename_t target = calc_filename(_base_filename, i); + + if (details::file_helper::file_exists(target)) + { + if (details::os::remove(target) != 0) + { + throw spdlog_ex("rotating_file_sink: failed removing " + filename_to_str(target), errno); + } + } + if (details::file_helper::file_exists(src) && details::os::rename(src, target)) + { + throw spdlog_ex("rotating_file_sink: failed renaming " + filename_to_str(src) + " to " + filename_to_str(target), errno); + } + } + _file_helper.reopen(true); + } + filename_t _base_filename; + std::size_t _max_size; + std::size_t _max_files; + std::size_t _current_size; + details::file_helper _file_helper; +}; + +typedef rotating_file_sink<std::mutex> rotating_file_sink_mt; +typedef rotating_file_sink<details::null_mutex>rotating_file_sink_st; + +/* + * Default generator of daily log file names. + */ +struct default_daily_file_name_calculator +{ + // Create filename for the form basename.YYYY-MM-DD_hh-mm + static filename_t calc_filename(const filename_t& basename) + { + std::tm tm = spdlog::details::os::localtime(); + std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::MemoryWriter, fmt::WMemoryWriter>::type w; + w.write(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}_{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min); + return w.str(); + } +}; + +/* + * Generator of daily log file names in format basename.YYYY-MM-DD + */ +struct dateonly_daily_file_name_calculator +{ + // Create filename for the form basename.YYYY-MM-DD + static filename_t calc_filename(const filename_t& basename) + { + std::tm tm = spdlog::details::os::localtime(); + std::conditional<std::is_same<filename_t::value_type, char>::value, fmt::MemoryWriter, fmt::WMemoryWriter>::type w; + w.write(SPDLOG_FILENAME_T("{}_{:04d}-{:02d}-{:02d}"), basename, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + 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: + //create daily file sink which rotates on given time + daily_file_sink( + const filename_t& base_filename, + int rotation_hour, + int rotation_minute) : _base_filename(base_filename), + _rotation_h(rotation_hour), + _rotation_m(rotation_minute) + { + if (rotation_hour < 0 || rotation_hour > 23 || rotation_minute < 0 || rotation_minute > 59) + throw spdlog_ex("daily_file_sink: Invalid rotation time in ctor"); + _rotation_tp = _next_rotation_tp(); + _file_helper.open(FileNameCalc::calc_filename(_base_filename)); + } + + +protected: + void _sink_it(const details::log_msg& msg) override + { + if (std::chrono::system_clock::now() >= _rotation_tp) + { + _file_helper.open(FileNameCalc::calc_filename(_base_filename)); + _rotation_tp = _next_rotation_tp(); + } + _file_helper.write(msg); + } + + void _flush() override + { + _file_helper.flush(); + } + +private: + std::chrono::system_clock::time_point _next_rotation_tp() + { + auto now = std::chrono::system_clock::now(); + time_t tnow = std::chrono::system_clock::to_time_t(now); + tm date = spdlog::details::os::localtime(tnow); + date.tm_hour = _rotation_h; + date.tm_min = _rotation_m; + date.tm_sec = 0; + auto rotation_time = std::chrono::system_clock::from_time_t(std::mktime(&date)); + if (rotation_time > now) + return rotation_time; + else + return std::chrono::system_clock::time_point(rotation_time + std::chrono::hours(24)); + } + + filename_t _base_filename; + int _rotation_h; + int _rotation_m; + std::chrono::system_clock::time_point _rotation_tp; + details::file_helper _file_helper; +}; + +typedef daily_file_sink<std::mutex> daily_file_sink_mt; +typedef daily_file_sink<details::null_mutex> daily_file_sink_st; +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/msvc_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/msvc_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/msvc_sink.h new file mode 100644 index 0000000..68b0255 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/msvc_sink.h @@ -0,0 +1,51 @@ +// +// Copyright(c) 2016 Alexander Dalshov. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#if defined(_MSC_VER) + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/details/null_mutex.h" + +#include <WinBase.h> + +#include <mutex> +#include <string> + +namespace spdlog +{ +namespace sinks +{ +/* +* MSVC sink (logging using OutputDebugStringA) +*/ +template<class Mutex> +class msvc_sink : public base_sink < Mutex > +{ +public: + explicit msvc_sink() + { + } + + + +protected: + void _sink_it(const details::log_msg& msg) override + { + OutputDebugStringA(msg.formatted.c_str()); + } + + void _flush() override + {} +}; + +typedef msvc_sink<std::mutex> msvc_sink_mt; +typedef msvc_sink<details::null_mutex> msvc_sink_st; + +} +} + +#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/null_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/null_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/null_sink.h new file mode 100644 index 0000000..ed4b5e4 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/null_sink.h @@ -0,0 +1,34 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/details/null_mutex.h" + +#include <mutex> + +namespace spdlog +{ +namespace sinks +{ + +template <class Mutex> +class null_sink : public base_sink < Mutex > +{ +protected: + void _sink_it(const details::log_msg&) override + {} + + void _flush() override + {} + +}; +typedef null_sink<details::null_mutex> null_sink_st; +typedef null_sink<details::null_mutex> null_sink_mt; + +} +} + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/ostream_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/ostream_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/ostream_sink.h new file mode 100644 index 0000000..f056107 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/ostream_sink.h @@ -0,0 +1,47 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/details/null_mutex.h" +#include "spdlog/sinks/base_sink.h" + +#include <ostream> +#include <mutex> + +namespace spdlog +{ +namespace sinks +{ +template<class Mutex> +class ostream_sink: public base_sink<Mutex> +{ +public: + explicit ostream_sink(std::ostream& os, bool force_flush=false) :_ostream(os), _force_flush(force_flush) {} + ostream_sink(const ostream_sink&) = delete; + ostream_sink& operator=(const ostream_sink&) = delete; + virtual ~ostream_sink() = default; + +protected: + void _sink_it(const details::log_msg& msg) override + { + _ostream.write(msg.formatted.data(), msg.formatted.size()); + if (_force_flush) + _ostream.flush(); + } + + void _flush() override + { + _ostream.flush(); + } + + std::ostream& _ostream; + bool _force_flush; +}; + +typedef ostream_sink<std::mutex> ostream_sink_mt; +typedef ostream_sink<details::null_mutex> ostream_sink_st; +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/sink.h new file mode 100644 index 0000000..0974f33 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/sink.h @@ -0,0 +1,53 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + + +#pragma once + +#include "spdlog/details/log_msg.h" + +namespace spdlog +{ +namespace sinks +{ +class sink +{ +public: + sink() + { + _level = level::trace; + } + + virtual ~sink() {} + virtual void log(const details::log_msg& msg) = 0; + virtual void flush() = 0; + + bool should_log(level::level_enum msg_level) const; + void set_level(level::level_enum log_level); + level::level_enum level() const; + +private: + level_t _level; + +}; + +inline bool sink::should_log(level::level_enum msg_level) const +{ + return msg_level >= _level.load(std::memory_order_relaxed); +} + +inline void sink::set_level(level::level_enum log_level) +{ + _level.store(log_level); +} + +inline level::level_enum sink::level() const +{ + return static_cast<spdlog::level::level_enum>(_level.load(std::memory_order_relaxed)); +} + +} +} + http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/stdout_sinks.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/stdout_sinks.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/stdout_sinks.h new file mode 100644 index 0000000..dcdcc7c --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/stdout_sinks.h @@ -0,0 +1,77 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/details/null_mutex.h" +#include "spdlog/sinks/base_sink.h" + +#include <cstdio> +#include <memory> +#include <mutex> + +namespace spdlog +{ +namespace sinks +{ + +template <class Mutex> +class stdout_sink SPDLOG_FINAL : public base_sink<Mutex> +{ + using MyType = stdout_sink<Mutex>; +public: + stdout_sink() + {} + static std::shared_ptr<MyType> instance() + { + static std::shared_ptr<MyType> instance = std::make_shared<MyType>(); + return instance; + } +protected: + void _sink_it(const details::log_msg& msg) override + { + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stdout); + _flush(); + } + + void _flush() override + { + fflush(stdout); + } +}; + +typedef stdout_sink<details::null_mutex> stdout_sink_st; +typedef stdout_sink<std::mutex> stdout_sink_mt; + + +template <class Mutex> +class stderr_sink SPDLOG_FINAL : public base_sink<Mutex> +{ + using MyType = stderr_sink<Mutex>; +public: + stderr_sink() + {} + static std::shared_ptr<MyType> instance() + { + static std::shared_ptr<MyType> instance = std::make_shared<MyType>(); + return instance; + } +protected: + void _sink_it(const details::log_msg& msg) override + { + fwrite(msg.formatted.data(), sizeof(char), msg.formatted.size(), stderr); + _flush(); + } + + void _flush() override + { + fflush(stderr); + } +}; + +typedef stderr_sink<std::mutex> stderr_sink_mt; +typedef stderr_sink<details::null_mutex> stderr_sink_st; +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/syslog_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/syslog_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/syslog_sink.h new file mode 100644 index 0000000..0b509c4 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/syslog_sink.h @@ -0,0 +1,81 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/common.h" + +#ifdef SPDLOG_ENABLE_SYSLOG + +#include "spdlog/sinks/sink.h" +#include "spdlog/details/log_msg.h" + +#include <array> +#include <string> +#include <syslog.h> + + +namespace spdlog +{ +namespace sinks +{ +/** + * Sink that write to syslog using the `syscall()` library call. + * + * Locking is not needed, as `syslog()` itself is thread-safe. + */ +class syslog_sink : public sink +{ +public: + // + syslog_sink(const std::string& ident = "", int syslog_option=0, int syslog_facility=LOG_USER): + _ident(ident) + { + _priorities[static_cast<int>(level::trace)] = LOG_DEBUG; + _priorities[static_cast<int>(level::debug)] = LOG_DEBUG; + _priorities[static_cast<int>(level::info)] = LOG_INFO; + _priorities[static_cast<int>(level::warn)] = LOG_WARNING; + _priorities[static_cast<int>(level::err)] = LOG_ERR; + _priorities[static_cast<int>(level::critical)] = LOG_CRIT; + _priorities[static_cast<int>(level::off)] = LOG_INFO; + + //set ident to be program name if empty + ::openlog(_ident.empty()? nullptr:_ident.c_str(), syslog_option, syslog_facility); + } + ~syslog_sink() + { + ::closelog(); + } + + syslog_sink(const syslog_sink&) = delete; + syslog_sink& operator=(const syslog_sink&) = delete; + + void log(const details::log_msg &msg) override + { + ::syslog(syslog_prio_from_level(msg), "%s", msg.raw.str().c_str()); + } + + void flush() override + { + } + + +private: + std::array<int, 7> _priorities; + //must store the ident because the man says openlog might use the pointer as is and not a string copy + const std::string _ident; + + // + // Simply maps spdlog's log level to syslog priority level. + // + int syslog_prio_from_level(const details::log_msg &msg) const + { + return _priorities[static_cast<int>(msg.level)]; + } +}; +} +} + +#endif http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/sinks/wincolor_sink.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/sinks/wincolor_sink.h b/thirdparty/spdlog-20170710/include/spdlog/sinks/wincolor_sink.h new file mode 100644 index 0000000..6611124 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/sinks/wincolor_sink.h @@ -0,0 +1,117 @@ +// +// Copyright(c) 2016 spdlog +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +#include "spdlog/sinks/base_sink.h" +#include "spdlog/details/null_mutex.h" +#include "spdlog/common.h" + +#include <mutex> +#include <string> +#include <map> +#include <wincon.h> + +namespace spdlog +{ +namespace sinks +{ +/* + * Windows color console sink. Uses WriteConsoleA to write to the console with colors + */ +template<class Mutex> +class wincolor_sink: public base_sink<Mutex> +{ +public: + const WORD BOLD = FOREGROUND_INTENSITY; + const WORD RED = FOREGROUND_RED; + const WORD CYAN = FOREGROUND_GREEN | FOREGROUND_BLUE; + const WORD WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; + const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN; + + wincolor_sink(HANDLE std_handle): out_handle_(std_handle) + { + colors_[level::trace] = CYAN; + colors_[level::debug] = CYAN; + colors_[level::info] = WHITE | BOLD; + colors_[level::warn] = YELLOW | BOLD; + colors_[level::err] = RED | BOLD; // red bold + colors_[level::critical] = BACKGROUND_RED | WHITE | BOLD; // white bold on red background + colors_[level::off] = 0; + } + + virtual ~wincolor_sink() + { + this->flush(); + } + + wincolor_sink(const wincolor_sink& other) = delete; + wincolor_sink& operator=(const wincolor_sink& other) = delete; + +protected: + virtual void _sink_it(const details::log_msg& msg) override + { + auto color = colors_[msg.level]; + auto orig_attribs = set_console_attribs(color); + WriteConsoleA(out_handle_, msg.formatted.data(), static_cast<DWORD>(msg.formatted.size()), nullptr, nullptr); + SetConsoleTextAttribute(out_handle_, orig_attribs); //reset to orig colors + } + + virtual void _flush() override + { + // windows console always flushed? + } + + // change the color for the given level + void set_color(level::level_enum level, WORD color) + { + std::lock_guard<Mutex> lock(base_sink<Mutex>::_mutex); + colors_[level] = color; + } + +private: + HANDLE out_handle_; + std::map<level::level_enum, WORD> colors_; + + // set color and return the orig console attributes (for resetting later) + WORD set_console_attribs(WORD attribs) + { + CONSOLE_SCREEN_BUFFER_INFO orig_buffer_info; + GetConsoleScreenBufferInfo(out_handle_, &orig_buffer_info); + SetConsoleTextAttribute(out_handle_, attribs); + return orig_buffer_info.wAttributes; //return orig attribs + } +}; + +// +// windows color console to stdout +// +template<class Mutex> +class wincolor_stdout_sink: public wincolor_sink<Mutex> +{ +public: + wincolor_stdout_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_OUTPUT_HANDLE)) + {} +}; + +typedef wincolor_stdout_sink<std::mutex> wincolor_stdout_sink_mt; +typedef wincolor_stdout_sink<details::null_mutex> wincolor_stdout_sink_st; + +// +// windows color console to stderr +// +template<class Mutex> +class wincolor_stderr_sink: public wincolor_sink<Mutex> +{ +public: + wincolor_stderr_sink() : wincolor_sink<Mutex>(GetStdHandle(STD_ERROR_HANDLE)) + {} +}; + +typedef wincolor_stderr_sink<std::mutex> wincolor_stderr_sink_mt; +typedef wincolor_stderr_sink<details::null_mutex> wincolor_stderr_sink_st; + +} +} http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/spdlog.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/spdlog.h b/thirdparty/spdlog-20170710/include/spdlog/spdlog.h new file mode 100644 index 0000000..fb4ea59 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/spdlog.h @@ -0,0 +1,187 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// +// spdlog main header file. +// see example.cpp for usage example + +#pragma once + +#define SPDLOG_VERSION "0.13.0" + +#include "spdlog/tweakme.h" +#include "spdlog/common.h" +#include "spdlog/logger.h" + +#include <memory> +#include <functional> +#include <chrono> +#include <string> + +namespace spdlog +{ + +// +// Return an existing logger or nullptr if a logger with such name doesn't exist. +// example: spdlog::get("my_logger")->info("hello {}", "world"); +// +std::shared_ptr<logger> get(const std::string& name); + + +// +// Set global formatting +// example: spdlog::set_pattern("%Y-%m-%d %H:%M:%S.%e %l : %v"); +// +void set_pattern(const std::string& format_string); +void set_formatter(formatter_ptr f); + +// +// Set global logging level for +// +void set_level(level::level_enum log_level); + +// +// Set global error handler +// +void set_error_handler(log_err_handler); + +// +// Turn on async mode (off by default) and set the queue size for each async_logger. +// effective only for loggers created after this call. +// queue_size: size of queue (must be power of 2): +// Each logger will pre-allocate a dedicated queue with queue_size entries upon construction. +// +// async_overflow_policy (optional, block_retry by default): +// async_overflow_policy::block_retry - if queue is full, block until queue has room for the new log entry. +// async_overflow_policy::discard_log_msg - never block and discard any new messages when queue overflows. +// +// worker_warmup_cb (optional): +// callback function that will be called in worker thread upon start (can be used to init stuff like thread affinity) +// +// worker_teardown_cb (optional): +// callback function that will be called in worker thread upon exit +// +void set_async_mode(size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function<void()>& worker_warmup_cb = nullptr, const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(), const std::function<void()>& worker_teardown_cb = nullptr); + +// Turn off async mode +void set_sync_mode(); + + +// +// Create and register multi/single threaded basic file logger. +// Basic logger simply writes to given file without any limitatons or rotations. +// +std::shared_ptr<logger> basic_logger_mt(const std::string& logger_name, const filename_t& filename, bool truncate = false); +std::shared_ptr<logger> basic_logger_st(const std::string& logger_name, const filename_t& filename, bool truncate = false); + +// +// Create and register multi/single threaded rotating file logger +// +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); +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); + +// +// 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 filename_t& filename, int hour=0, int minute=0); +std::shared_ptr<logger> daily_logger_st(const std::string& logger_name, const filename_t& filename, int hour=0, int minute=0); + +// +// Create and register stdout/stderr loggers +// +std::shared_ptr<logger> stdout_logger_mt(const std::string& logger_name); +std::shared_ptr<logger> stdout_logger_st(const std::string& logger_name); +std::shared_ptr<logger> stderr_logger_mt(const std::string& logger_name); +std::shared_ptr<logger> stderr_logger_st(const std::string& logger_name); +// +// Create and register colored stdout/stderr loggers +// +std::shared_ptr<logger> stdout_color_mt(const std::string& logger_name); +std::shared_ptr<logger> stdout_color_st(const std::string& logger_name); +std::shared_ptr<logger> stderr_color_mt(const std::string& logger_name); +std::shared_ptr<logger> stderr_color_st(const std::string& logger_name); + + +// +// Create and register a syslog logger +// +#ifdef SPDLOG_ENABLE_SYSLOG +std::shared_ptr<logger> syslog_logger(const std::string& logger_name, const std::string& ident = "", int syslog_option = 0); +#endif + +#if defined(__ANDROID__) +std::shared_ptr<logger> android_logger(const std::string& logger_name, const std::string& tag = "spdlog"); +#endif + +// Create and register a logger with a single sink +std::shared_ptr<logger> create(const std::string& logger_name, const sink_ptr& sink); + +// Create and register a logger with multiple sinks +std::shared_ptr<logger> create(const std::string& logger_name, sinks_init_list sinks); +template<class It> +std::shared_ptr<logger> create(const std::string& logger_name, const It& sinks_begin, const It& sinks_end); + + +// Create and register a logger with templated sink type +// Example: +// spdlog::create<daily_file_sink_st>("mylog", "dailylog_filename"); +template <typename Sink, typename... Args> +std::shared_ptr<spdlog::logger> create(const std::string& logger_name, Args...); + +// Create and register an async logger with a single sink +std::shared_ptr<logger> create_async(const std::string& logger_name, const sink_ptr& sink, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function<void()>& worker_warmup_cb = nullptr, const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(), const std::function<void()>& worker_teardown_cb = nullptr); + +// Create and register an async logger with multiple sinks +std::shared_ptr<logger> create_async(const std::string& logger_name, sinks_init_list sinks, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function<void()>& worker_warmup_cb = nullptr, const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(), const std::function<void()>& worker_teardown_cb = nullptr); +template<class It> +std::shared_ptr<logger> create_async(const std::string& logger_name, const It& sinks_begin, const It& sinks_end, size_t queue_size, const async_overflow_policy overflow_policy = async_overflow_policy::block_retry, const std::function<void()>& worker_warmup_cb = nullptr, const std::chrono::milliseconds& flush_interval_ms = std::chrono::milliseconds::zero(), const std::function<void()>& worker_teardown_cb = nullptr); + +// Register the given logger with the given name +void register_logger(std::shared_ptr<logger> logger); + +// Apply a user defined function on all registered loggers +// Example: +// spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) {l->flush();}); +void apply_all(std::function<void(std::shared_ptr<logger>)> fun); + +// Drop the reference to the given logger +void drop(const std::string &name); + +// Drop all references from the registry +void drop_all(); + + +/////////////////////////////////////////////////////////////////////////////// +// +// Trace & Debug can be switched on/off at compile time for zero cost debug statements. +// Uncomment SPDLOG_DEBUG_ON/SPDLOG_TRACE_ON in teakme.h to enable. +// SPDLOG_TRACE(..) will also print current file and line. +// +// Example: +// spdlog::set_level(spdlog::level::trace); +// SPDLOG_TRACE(my_logger, "some trace message"); +// SPDLOG_TRACE(my_logger, "another trace message {} {}", 1, 2); +// SPDLOG_DEBUG(my_logger, "some debug message {} {}", 3, 4); +// SPDLOG_DEBUG_IF(my_logger, true, "some debug message {} {}", 3, 4); +/////////////////////////////////////////////////////////////////////////////// + +#ifdef SPDLOG_TRACE_ON +#define SPDLOG_STR_H(x) #x +#define SPDLOG_STR_HELPER(x) SPDLOG_STR_H(x) +#define SPDLOG_TRACE(logger, ...) logger->trace("[" __FILE__ " line #" SPDLOG_STR_HELPER(__LINE__) "] " __VA_ARGS__) +#define SPDLOG_TRACE_IF(logger, flag, ...) logger->trace_if(flag, "[" __FILE__ " line #" SPDLOG_STR_HELPER(__LINE__) "] " __VA_ARGS__) +#else +#define SPDLOG_TRACE(logger, ...) +#endif + +#ifdef SPDLOG_DEBUG_ON +#define SPDLOG_DEBUG(logger, ...) logger->debug(__VA_ARGS__) +#define SPDLOG_DEBUG_IF(logger, flag, ...) logger->debug_if(flag, __VA_ARGS__) +#else +#define SPDLOG_DEBUG(logger, ...) +#endif + +} + + +#include "spdlog/details/spdlog_impl.h" http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/8389c8aa/thirdparty/spdlog-20170710/include/spdlog/tweakme.h ---------------------------------------------------------------------- diff --git a/thirdparty/spdlog-20170710/include/spdlog/tweakme.h b/thirdparty/spdlog-20170710/include/spdlog/tweakme.h new file mode 100644 index 0000000..d1b63c0 --- /dev/null +++ b/thirdparty/spdlog-20170710/include/spdlog/tweakme.h @@ -0,0 +1,134 @@ +// +// Copyright(c) 2015 Gabi Melman. +// Distributed under the MIT License (http://opensource.org/licenses/MIT) +// + +#pragma once + +/////////////////////////////////////////////////////////////////////////////// +// +// Edit this file to squeeze more performance, and to customize supported features +// +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// 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 clock. +// +// #define SPDLOG_CLOCK_COARSE +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment if date/time logging is not needed and never appear in the log pattern. +// This will prevent spdlog from quering the clock on each log call. +// +// WARNING: If the log pattern contains any date/time while this flag is on, the result is undefined. +// You must set new pattern(spdlog::set_pattern(..") without any date/time in it +// +// #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. +// +// WARNING: If the log pattern contains thread id (i.e, %t) while this flag is on, the result is undefined. +// +// #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 +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to avoid spdlog's usage of atomic log levels +// Use only if your code never modifies a logger's log levels concurrently by different threads. +// +// #define SPDLOG_NO_ATOMIC_LEVELS +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable usage of wchar_t for file names on Windows. +// +// #define SPDLOG_WCHAR_FILENAMES +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to override default eol ("\n" or "\r\n" under Linux/Windows) +// +// #define SPDLOG_EOL ";-)\n" +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to use your own copy of the fmt library instead of spdlog's copy. +// In this case spdlog will try to include <fmt/format.h> so set your -I flag accordingly. +// +// #define SPDLOG_FMT_EXTERNAL +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable syslog (disabled by default) +// +// #define SPDLOG_ENABLE_SYSLOG +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable wchar_t support (convert to utf8) +// +// #define SPDLOG_WCHAR_TO_UTF8_SUPPORT +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to prevent child processes from inheriting log file descriptors +// +// #define SPDLOG_PREVENT_CHILD_FD +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to mark some types as final, allowing more optimizations in release +// mode with recent compilers. See GCC's documentation for -Wsuggest-final-types +// for instance. +// +// #define SPDLOG_FINAL final +/////////////////////////////////////////////////////////////////////////////// + + +/////////////////////////////////////////////////////////////////////////////// +// Uncomment to enable message counting feature. Adds %i logger pattern that +// prints log message sequence id. +// +// #define SPDLOG_ENABLE_MESSAGE_COUNTER +///////////////////////////////////////////////////////////////////////////////