Skip to content

Commit

Permalink
Add a way to remove the HierarchyEventListener (#234)
Browse files Browse the repository at this point in the history
* Add a way to remove the HierarchyEventListener

See #233
  • Loading branch information
rm5248 authored Jul 28, 2023
1 parent f03eba4 commit de4bc7d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/cpp/hierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ void Hierarchy::addHierarchyEventListener(const spi::HierarchyEventListenerPtr&
}
}

void Hierarchy::removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener)
{
std::unique_lock<std::mutex> lock(m_priv->mutex);

auto found = std::find(m_priv->listeners.begin(), m_priv->listeners.end(), listener);
if(found != m_priv->listeners.end()){
m_priv->listeners.erase(found);
}
}

void Hierarchy::clear()
{
std::unique_lock<std::mutex> lock(m_priv->mutex);
Expand Down
7 changes: 7 additions & 0 deletions src/main/include/log4cxx/hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ class LOG4CXX_EXPORT Hierarchy : public spi::LoggerRepository

void addHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener) override;

/**
* Remove a previously added HierarchyEventListener.
*
* ABI TODO: Make virtual and add to LoggerRepository.
*/
void removeHierarchyEventListener(const spi::HierarchyEventListenerPtr& listener);

/**
* Call \c configurator if not yet configured.
*/
Expand Down

0 comments on commit de4bc7d

Please sign in to comment.