Skip to content

Commit

Permalink
Merge pull request log4cplus#612 from wilx/master
Browse files Browse the repository at this point in the history
Merge.
  • Loading branch information
wilx authored Feb 11, 2024
2 parents dcae948 + b12944f commit 4336410
Show file tree
Hide file tree
Showing 13 changed files with 206 additions and 62 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/c-cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@ jobs:
cxx: 'g++-13'
prereq: |
sudo apt install libstdc++-13-dev g++-13 gcc-13
# Mac OS X is missing the <format> header or
# some of its funtions.
#- os: 'macos-13'
#- os: 'macos-14'
# cc: 'clang'
# cxx: 'clang++'
# prereq: |
# sudo xcode-select -s '/Applications/Xcode_15.1.app/Contents/Developer'
# sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer'

runs-on: ${{ matrix.config.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive
- name: install prerequisites
Expand Down
106 changes: 78 additions & 28 deletions include/log4cplus/boost/deviceappender.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@
#pragma once
#endif

#include <boost/utility/enable_if.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/not.hpp>
#include <memory>
#include <boost/iostreams/operations.hpp>
#include <boost/shared_ptr.hpp>
#include <log4cplus/appender.h>
#include <log4cplus/helpers/property.h>


namespace log4cplus
Expand All @@ -51,7 +50,7 @@ struct device_type_traits
{
typedef T & device_type;

static
static inline
device_type
unwrap (device_type x)
{
Expand All @@ -65,7 +64,21 @@ struct device_type_traits<boost::shared_ptr<T> >
{
typedef boost::shared_ptr<T> device_type;

static
static inline
T &
unwrap (device_type const & ptr)
{
return *ptr;
}
};


template <typename T>
struct device_type_traits<std::shared_ptr<T> >
{
typedef std::shared_ptr<T> device_type;

static inline
T &
unwrap (device_type const & ptr)
{
Expand All @@ -77,6 +90,12 @@ struct device_type_traits<boost::shared_ptr<T> >
} // namespace device_appender_detail


/**
* @brief This appender wraps Boost IOStreams' Device concept instance
* as underlying sink for the appender.
*
* @tparam Device Boost IOStreams' Device concept instance
*/
template <typename Device>
class DeviceAppender
: public Appender
Expand All @@ -97,36 +116,53 @@ public:
, close_flag (close_device)
{ }

template <typename D>
DeviceAppender (std::shared_ptr<D> const & d, bool close_device = true)
: device (d)
, close_flag (close_device)
{ }

template <typename D>
DeviceAppender (D & d, const helpers::Properties & props)
: Appender (props)
, device (d)
, close_flag (true)
{
if (props.exists (LOG4CPLUS_TEXT ("CloseDevice")))
close_flag = true;
else
close_flag = false;
props.getBool (close_flag, LOG4CPLUS_TEXT ("CloseDevice"));
}

template <typename D>
DeviceAppender (boost::shared_ptr<D> const & d,
const helpers::Properties & props)
: Appender (props)
, device (d)
, close_flag (true)
{
props.getBool (close_flag, LOG4CPLUS_TEXT ("CloseDevice"));
}

template <typename D>
DeviceAppender (std::shared_ptr<D> const & d,
const helpers::Properties & props)
: Appender (props)
, device (d)
, close_flag (true)
{
if (props.exists (LOG4CPLUS_TEXT ("CloseDevice")))
close_flag = true;
else
close_flag = false;
props.getBool (close_flag, LOG4CPLUS_TEXT ("CloseDevice"));
}

DeviceAppender (DeviceAppender const &) = delete;
DeviceAppender & operator = (DeviceAppender const &) = delete;

virtual
~DeviceAppender ()
{ }
{
destructorImpl ();
}

virtual
void
close ()
close () override
{
if (close_flag)
boost::iostreams::close (device_traits::unwrap (device));
Expand All @@ -135,7 +171,7 @@ public:
protected:
virtual
void
append (log4cplus::spi::InternalLoggingEvent const & event)
append (log4cplus::spi::InternalLoggingEvent const & event) override
{
tstring & str = formatEvent (event);
boost::iostreams::write (device_traits::unwrap (device),
Expand All @@ -144,10 +180,6 @@ protected:

device_type device;
bool close_flag;

private:
DeviceAppender (DeviceAppender const &);
DeviceAppender & operator = (DeviceAppender const &);
};


Expand All @@ -156,8 +188,7 @@ inline
SharedAppenderPtr
make_device_appender (T & d, bool close_device = true)
{
SharedAppenderPtr app (new DeviceAppender<T> (d, close_device));
return app;
return SharedAppenderPtr (new DeviceAppender<T> (d, close_device));
}


Expand All @@ -166,8 +197,7 @@ inline
SharedAppenderPtr
make_device_appender (T & d, const helpers::Properties & props)
{
SharedAppenderPtr app (new DeviceAppender<T> (d, props));
return app;
return SharedAppenderPtr (new DeviceAppender<T> (d, props));
}


Expand All @@ -177,9 +207,8 @@ SharedAppenderPtr
make_device_appender_sp (boost::shared_ptr<T> const & p,
bool close_device = true)
{
SharedAppenderPtr app (
return SharedAppenderPtr (
new DeviceAppender<boost::shared_ptr<T> > (p, close_device));
return app;
}


Expand All @@ -189,9 +218,30 @@ SharedAppenderPtr
make_device_appender_sp (boost::shared_ptr<T> const & p,
const helpers::Properties & props)
{
SharedAppenderPtr app (
return SharedAppenderPtr (
new DeviceAppender<boost::shared_ptr<T> > (p, props));
return app;
}


template <typename T>
inline
SharedAppenderPtr
make_device_appender_sp (std::shared_ptr<T> const & p,
bool close_device = true)
{
return SharedAppenderPtr (
new DeviceAppender<std::shared_ptr<T> > (p, close_device));
}


template <typename T>
inline
SharedAppenderPtr
make_device_appender_sp (std::shared_ptr<T> const & p,
const helpers::Properties & props)
{
return SharedAppenderPtr (
new DeviceAppender<std::shared_ptr<T> > (p, props));
}


Expand Down
4 changes: 3 additions & 1 deletion include/log4cplus/helpers/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,13 @@ namespace log4cplus {
SocketBuffer const * const * buffers);

template <typename... Args>
requires (sizeof... (Args) == 0
|| (std::is_same_v<std::remove_cvref_t<Args>, SocketBuffer> && ...))
static bool write(Socket & socket, Args &&... args)
{
SocketBuffer const * const buffers[sizeof... (args)] {
(&args)... };
return socket.write (sizeof... (args), buffers);
return socket.write (sizeof... (Args), buffers);
}
};

Expand Down
22 changes: 13 additions & 9 deletions include/log4cplus/helpers/stringhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ namespace log4cplus {
* tokenize(s, '.', back_insert_iterator<list<string> >(tokens));
* </pre>
*/
template <class StringType, class OutputIter>
template <typename StringType, typename OutputIter>
requires std::output_iterator<OutputIter, StringType>
inline
void
tokenize(const StringType& s, typename StringType::value_type c,
Expand Down Expand Up @@ -95,11 +96,11 @@ namespace log4cplus {
}


template <typename intType, typename stringType, bool isSigned>
template <std::integral intType, typename stringType, bool isSigned>
struct ConvertIntegerToStringHelper;


template <typename intType, typename charType>
template <std::integral intType, typename charType>
struct ConvertIntegerToStringHelper<intType, charType, true>
{
static inline
Expand Down Expand Up @@ -128,7 +129,7 @@ namespace log4cplus {
value = -value;
}

static
static constexpr
bool
is_negative (intType val)
{
Expand All @@ -137,7 +138,7 @@ namespace log4cplus {
};


template <typename intType, typename charType>
template <std::integral intType, typename charType>
struct ConvertIntegerToStringHelper<intType, charType, false>
{
static inline
Expand All @@ -147,7 +148,7 @@ namespace log4cplus {
// This will never be called for unsigned types.
}

static
static constexpr
bool
is_negative (intType)
{
Expand All @@ -156,7 +157,7 @@ namespace log4cplus {
};


template <class stringType, class intType>
template <class stringType, std::integral intType>
inline
void
convertIntegerToString (stringType & str, intType value)
Expand Down Expand Up @@ -203,7 +204,7 @@ namespace log4cplus {
}


template<class intType>
template<std::integral intType>
inline
tstring
convertIntegerToString (intType value)
Expand All @@ -214,7 +215,7 @@ namespace log4cplus {
}


template<class intType>
template<std::integral intType>
inline
std::string
convertIntegerToNarrowString (intType value)
Expand All @@ -227,6 +228,7 @@ namespace log4cplus {

//! Join a list of items into a string.
template <typename Iterator, typename Separator>
requires std::forward_iterator<Iterator>
inline
void
join_worker (tstring & result, Iterator & start, Iterator & last,
Expand All @@ -244,6 +246,7 @@ namespace log4cplus {

//! Join a list of items into a string.
template <typename Iterator>
requires std::forward_iterator<Iterator>
inline
void
join (tstring & result, Iterator start, Iterator last,
Expand All @@ -254,6 +257,7 @@ namespace log4cplus {

//! Join a list of items into a string.
template <typename Iterator>
requires std::forward_iterator<Iterator>
inline
void
join (tstring & result, Iterator start, Iterator last,
Expand Down
6 changes: 3 additions & 3 deletions include/log4cplus/tstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ struct tstring_hash
using is_transparent = void;

std::size_t
operator () (tchar const * str) const
operator () (tchar const * str) const noexcept
{
return std::hash<tstring_view>{} (str);
}

std::size_t
operator () (tstring_view str) const
operator () (tstring_view str) const noexcept
{
return std::hash<tstring_view>{} (str);
}

std::size_t
operator () (tstring const & str) const
operator () (tstring const & str) const noexcept
{
return std::hash<tstring>{} (str);
}
Expand Down
2 changes: 1 addition & 1 deletion src/filter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ CATCH_TEST_CASE ("Filter", "[filter]")
CATCH_SECTION ("function filter")
{
filter = new FunctionFilter (
[](InternalLoggingEvent const & ev) -> FilterResult {
[](InternalLoggingEvent const & ev) noexcept -> FilterResult {
return ev.getLogLevel () >= INFO_LOG_LEVEL ? ACCEPT : DENY;
});
CATCH_REQUIRE (filter->decide (info_ev) == ACCEPT);
Expand Down
1 change: 0 additions & 1 deletion src/mdc.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ CATCH_TEST_CASE ("MDC", "[MDC]")

CATCH_SECTION ("MDCGuard")
{
tcerr << LOG4CPLUS_TEXT ("MDCGuard\n");
{
mdc.clear ();
CATCH_REQUIRE (stacks_map.empty ());
Expand Down
Loading

0 comments on commit 4336410

Please sign in to comment.