format more log messages in alert constructors

This commit is contained in:
arvidn 2016-06-28 18:52:51 -04:00
parent 55d8b0625f
commit 08aebd2729
5 changed files with 33 additions and 54 deletions

View File

@ -2092,6 +2092,7 @@ namespace libtorrent
{
// internal
log_alert(aux::stack_allocator& alloc, char const* log);
log_alert(aux::stack_allocator& alloc, char const* fmt, va_list v);
TORRENT_DEFINE_ALERT(log_alert, 79)
@ -2114,7 +2115,7 @@ namespace libtorrent
{
// internal
torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, char const* log);
, char const* fmt, va_list v);
TORRENT_DEFINE_ALERT(torrent_log_alert, 80)
@ -2146,10 +2147,6 @@ namespace libtorrent
};
// internal
peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi
, peer_log_alert::direction_t dir
, char const* event, char const* log);
peer_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi
, peer_log_alert::direction_t dir
@ -2301,7 +2298,7 @@ namespace libtorrent
};
dht_log_alert(aux::stack_allocator& alloc
, dht_module_t m, char const* msg);
, dht_module_t m, char const* fmt, va_list v);
static const int static_category = alert::dht_log_notification;
TORRENT_DEFINE_ALERT(dht_log_alert, 85)

View File

@ -1659,6 +1659,10 @@ namespace libtorrent {
: m_alloc(alloc)
, m_str_idx(alloc.copy_string(log))
{}
log_alert::log_alert(aux::stack_allocator& alloc, char const* fmt, va_list v)
: m_alloc(alloc)
, m_str_idx(alloc.format_string(fmt, v))
{}
char const* log_alert::msg() const
{
@ -1671,9 +1675,9 @@ namespace libtorrent {
}
torrent_log_alert::torrent_log_alert(aux::stack_allocator& alloc, torrent_handle const& h
, char const* log)
, char const* fmt, va_list v)
: torrent_alert(alloc, h)
, m_str_idx(alloc.copy_string(log))
, m_str_idx(alloc.format_string(fmt, v))
{}
char const* torrent_log_alert::msg() const
@ -1686,19 +1690,6 @@ namespace libtorrent {
return torrent_alert::message() + ": " + msg();
}
peer_log_alert::peer_log_alert(aux::stack_allocator& alloc
, torrent_handle const& h
, tcp::endpoint const& i
, peer_id const& pi
, direction_t dir
, char const* event
, char const* log)
: peer_alert(alloc, h, i, pi)
, event_type(event)
, direction(dir)
, m_str_idx(alloc.copy_string(log))
{}
peer_log_alert::peer_log_alert(aux::stack_allocator& alloc
, torrent_handle const& h
, tcp::endpoint const& i, peer_id const& pi
@ -1866,10 +1857,10 @@ namespace libtorrent {
}
dht_log_alert::dht_log_alert(aux::stack_allocator& alloc
, dht_log_alert::dht_module_t m, const char* msg)
, dht_log_alert::dht_module_t m, const char* fmt, va_list v)
: module(m)
, m_alloc(alloc)
, m_msg_idx(alloc.copy_string(msg))
, m_msg_idx(alloc.format_string(fmt, v))
{}
char const* dht_log_alert::log_message() const

View File

@ -34,21 +34,7 @@ POSSIBILITY OF SUCH DAMAGE.
#include <functional>
#include <cstdint>
#if TORRENT_USE_ASSERTS
#include <set>
#endif
#ifdef TORRENT_USE_OPENSSL
#include <openssl/rand.h>
#endif
#ifndef TORRENT_DISABLE_LOGGING
#include <cstdarg> // for va_start, va_end
#include <cstdio> // for vsnprintf
#include "libtorrent/socket_io.hpp"
#include "libtorrent/hex.hpp" // to_hex
#endif
#include "libtorrent/config.hpp"
#include "libtorrent/peer_connection.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/entry.hpp"
@ -79,6 +65,21 @@ POSSIBILITY OF SUCH DAMAGE.
#include "libtorrent/close_reason.hpp"
#include "libtorrent/aux_/time.hpp"
#if TORRENT_USE_ASSERTS
#include <set>
#endif
#ifdef TORRENT_USE_OPENSSL
#include <openssl/rand.h>
#endif
#ifndef TORRENT_DISABLE_LOGGING
#include <cstdarg> // for va_start, va_end
#include <cstdio> // for vsnprintf
#include "libtorrent/socket_io.hpp"
#include "libtorrent/hex.hpp" // to_hex
#endif
//#define TORRENT_CORRUPT_DATA
using boost::shared_ptr;

View File

@ -4443,10 +4443,7 @@ namespace aux {
void session_impl::session_vlog(char const* fmt, va_list& v) const
{
if (!m_alerts.should_post<log_alert>()) return;
char buf[1024];
vsnprintf(buf, sizeof(buf), fmt, v);
m_alerts.emplace_alert<log_alert>(buf);
m_alerts.emplace_alert<log_alert>(fmt, v);
}
#endif
@ -6593,10 +6590,9 @@ namespace aux {
va_list v;
va_start(v, fmt);
char buf[1024];
std::vsnprintf(buf, sizeof(buf), fmt, v);
m_alerts.emplace_alert<dht_log_alert>(
static_cast<dht_log_alert::dht_module_t>(m), fmt, v);
va_end(v);
m_alerts.emplace_alert<dht_log_alert>(static_cast<dht_log_alert::dht_module_t>(m), buf);
}
void session_impl::log_packet(message_direction_t dir, char const* pkt, int len
@ -6938,10 +6934,8 @@ namespace aux {
{
va_list v;
va_start(v, fmt);
char usr[1024];
vsnprintf(usr, sizeof(usr), fmt, v);
m_ses.session_vlog(fmt, v);
va_end(v);
m_ses.session_log("%s", usr);
}
#endif // TORRENT_DISABLE_LOGGING
}}

View File

@ -11310,13 +11310,9 @@ namespace libtorrent
va_list v;
va_start(v, fmt);
char buf[400];
vsnprintf(buf, sizeof(buf), fmt, v);
va_end(v);
alerts().emplace_alert<torrent_log_alert>(
const_cast<torrent*>(this)->get_handle(), buf);
const_cast<torrent*>(this)->get_handle(), fmt, v);
va_end(v);
}
#endif