qBittorrent
Logger Class Reference

#include <logger.h>

Inheritance diagram for Logger:
Collaboration diagram for Logger:

Signals

void newLogMessage (const Log::Msg &message)
 
void newLogPeer (const Log::Peer &peer)
 

Public Member Functions

void addMessage (const QString &message, const Log::MsgType &type=Log::NORMAL)
 
void addPeer (const QString &ip, bool blocked, const QString &reason={})
 
QVector< Log::MsggetMessages (int lastKnownId=-1) const
 
QVector< Log::PeergetPeers (int lastKnownId=-1) const
 

Static Public Member Functions

static void initInstance ()
 
static void freeInstance ()
 
static Loggerinstance ()
 

Private Member Functions

 Logger ()
 
 ~Logger ()=default
 

Private Attributes

boost::circular_buffer_space_optimized< Log::Msgm_messages
 
boost::circular_buffer_space_optimized< Log::Peerm_peers
 
QReadWriteLock m_lock
 
int m_msgCounter = 0
 
int m_peerCounter = 0
 

Static Private Attributes

static Loggerm_instance = nullptr
 

Detailed Description

Definition at line 72 of file logger.h.

Constructor & Destructor Documentation

◆ Logger()

Logger::Logger ( )
private

Definition at line 50 of file logger.cpp.

53 {
54 }
boost::circular_buffer_space_optimized< Log::Peer > m_peers
Definition: logger.h:97
boost::circular_buffer_space_optimized< Log::Msg > m_messages
Definition: logger.h:96
const int MAX_LOG_MESSAGES
Definition: logger.h:38

Referenced by initInstance().

Here is the caller graph for this function:

◆ ~Logger()

Logger::~Logger ( )
privatedefault

Member Function Documentation

◆ addMessage()

void Logger::addMessage ( const QString &  message,
const Log::MsgType type = Log::NORMAL 
)

◆ addPeer()

void Logger::addPeer ( const QString &  ip,
bool  blocked,
const QString &  reason = {} 
)

Definition at line 83 of file logger.cpp.

84 {
85  QWriteLocker locker(&m_lock);
86  const Log::Peer msg = {m_peerCounter++, blocked, QDateTime::currentMSecsSinceEpoch(), ip, reason};
87  m_peers.push_back(msg);
88  locker.unlock();
89 
90  emit newLogPeer(msg);
91 }
int m_peerCounter
Definition: logger.h:100
void newLogPeer(const Log::Peer &peer)

References m_lock, m_peerCounter, m_peers, and newLogPeer().

Referenced by BitTorrent::Session::handlePeerBanAlert(), and BitTorrent::Session::handlePeerBlockedAlert().

Here is the caller graph for this function:

◆ freeInstance()

void Logger::freeInstance ( )
static

Definition at line 67 of file logger.cpp.

68 {
69  delete m_instance;
70  m_instance = nullptr;
71 }
static Logger * m_instance
Definition: logger.h:95

References m_instance.

Referenced by Application::cleanup().

Here is the caller graph for this function:

◆ getMessages()

QVector< Log::Msg > Logger::getMessages ( int  lastKnownId = -1) const

Definition at line 93 of file logger.cpp.

94 {
95  const QReadLocker locker(&m_lock);
96 
97  const int diff = m_msgCounter - lastKnownId - 1;
98  const int size = static_cast<int>(m_messages.size());
99 
100  if ((lastKnownId == -1) || (diff >= size))
101  return loadFromBuffer(m_messages);
102 
103  if (diff <= 0)
104  return {};
105 
106  return loadFromBuffer(m_messages, (size - diff));
107 }
QVector< T > loadFromBuffer(const boost::circular_buffer_space_optimized< T > &src, const int offset=0)
Definition: logger.cpp:39

References anonymous_namespace{logger.cpp}::loadFromBuffer(), m_lock, m_messages, and m_msgCounter.

Referenced by FileLogger::FileLogger(), and LogController::mainAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPeers()

QVector< Log::Peer > Logger::getPeers ( int  lastKnownId = -1) const

Definition at line 109 of file logger.cpp.

110 {
111  const QReadLocker locker(&m_lock);
112 
113  const int diff = m_peerCounter - lastKnownId - 1;
114  const int size = static_cast<int>(m_peers.size());
115 
116  if ((lastKnownId == -1) || (diff >= size))
117  return loadFromBuffer(m_peers);
118 
119  if (diff <= 0)
120  return {};
121 
122  return loadFromBuffer(m_peers, (size - diff));
123 }

References anonymous_namespace{logger.cpp}::loadFromBuffer(), m_lock, m_peerCounter, and m_peers.

Referenced by LogController::peersAction().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initInstance()

void Logger::initInstance ( )
static

Definition at line 61 of file logger.cpp.

62 {
63  if (!m_instance)
64  m_instance = new Logger;
65 }
Logger()
Definition: logger.cpp:50

References Logger(), and m_instance.

Referenced by Application::Application().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ instance()

◆ newLogMessage

void Logger::newLogMessage ( const Log::Msg message)
signal

Referenced by addMessage(), and FileLogger::FileLogger().

Here is the caller graph for this function:

◆ newLogPeer

void Logger::newLogPeer ( const Log::Peer peer)
signal

Referenced by addPeer(), and LogPeerModel::LogPeerModel().

Here is the caller graph for this function:

Member Data Documentation

◆ m_instance

Logger * Logger::m_instance = nullptr
staticprivate

Definition at line 95 of file logger.h.

Referenced by freeInstance(), initInstance(), and instance().

◆ m_lock

QReadWriteLock Logger::m_lock
mutableprivate

Definition at line 98 of file logger.h.

Referenced by addMessage(), addPeer(), getMessages(), and getPeers().

◆ m_messages

boost::circular_buffer_space_optimized<Log::Msg> Logger::m_messages
private

Definition at line 96 of file logger.h.

Referenced by addMessage(), and getMessages().

◆ m_msgCounter

int Logger::m_msgCounter = 0
private

Definition at line 99 of file logger.h.

Referenced by addMessage(), and getMessages().

◆ m_peerCounter

int Logger::m_peerCounter = 0
private

Definition at line 100 of file logger.h.

Referenced by addPeer(), and getPeers().

◆ m_peers

boost::circular_buffer_space_optimized<Log::Peer> Logger::m_peers
private

Definition at line 97 of file logger.h.

Referenced by addPeer(), and getPeers().


The documentation for this class was generated from the following files: