From 79f6b5856b5c812b601f284310a3c37717ce7bab Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Mon, 15 Nov 2010 04:43:53 +0000 Subject: [PATCH] verbose logging fixes --- include/libtorrent/debug.hpp | 14 +++++++------- src/session_impl.cpp | 18 +++++++++++++----- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/include/libtorrent/debug.hpp b/include/libtorrent/debug.hpp index b930afca0..e45fe6eaa 100644 --- a/include/libtorrent/debug.hpp +++ b/include/libtorrent/debug.hpp @@ -69,19 +69,20 @@ namespace libtorrent error_code ec; if (!exists(dir)) create_directories(dir, ec); m_filename = combine_path(dir, filename); - m_truncate = !append; - *this << "\n\n\n*** starting log ***\n"; + + mutex::scoped_lock l(file_mutex); + open(!append); + log_file << "\n\n\n*** starting log ***\n"; } #if TORRENT_USE_IOSTREAM - void open() + void open(bool truncate) { if (open_filename == m_filename) return; log_file.close(); log_file.clear(); - log_file.open(m_filename.c_str(), m_truncate ? std::ios_base::trunc : std::ios_base::app); + log_file.open(m_filename.c_str(), truncate ? std::ios_base::trunc : std::ios_base::app); open_filename = m_filename; - m_truncate = false; if (!log_file.good()) fprintf(stderr, "Failed to open logfile %s: %s\n", m_filename.c_str(), strerror(errno)); } @@ -92,14 +93,13 @@ namespace libtorrent { #if TORRENT_USE_IOSTREAM mutex::scoped_lock l(file_mutex); - open(); + open(false); log_file << v; #endif return *this; } std::string m_filename; - bool m_truncate; }; } diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 36b37be23..a46430be6 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -595,13 +595,19 @@ namespace aux { #if defined TORRENT_VERBOSE_LOGGING || defined TORRENT_LOGGING || defined TORRENT_ERROR_LOGGING - (*m_logger) << "libtorrent configuration: " << TORRENT_CFG_STRING << "\n" - << "libtorrent version: " << LIBTORRENT_VERSION << "\n" - << "libtorrent revision: " << LIBTORRENT_REVISION << "\n\n"; + char tmp[300]; + snprintf(tmp, sizeof(tmp), "libtorrent configuration: %s\n" + "libtorrent version: %d\n" + "libtorrent revision: %d\n\n" + , TORRENT_CFG_STRING + , LIBTORRENT_VERSION + , LIBTORRENT_REVISION); + (*m_logger) << tmp; -#define PRINT_SIZEOF(x) (*m_logger) << "sizeof(" #x "): " << sizeof(x) << "\n"; -#define PRINT_OFFSETOF(x, y) (*m_logger) << " offsetof(" #x "," #y "): " << offsetof(x, y) << "\n"; +#define PRINT_SIZEOF(x) snprintf(tmp, sizeof(tmp), "sizeof(" #x ") = %d\n", int(sizeof(x))); (*m_logger) << tmp; +#define PRINT_OFFSETOF(x, y) snprintf(tmp, sizeof(tmp), " offsetof(" #x "," #y "): %d\n", int(offsetof(x, y))); \ + (*m_logger) << tmp; PRINT_SIZEOF(announce_entry) PRINT_OFFSETOF(announce_entry, url) @@ -632,6 +638,8 @@ namespace aux { PRINT_SIZEOF(bandwidth_channel) PRINT_SIZEOF(policy) + PRINT_SIZEOF(file_entry) + // PRINT_SIZEOF(stat_channel) // PRINT_OFFSETOF(stat_channel, m_counter) // PRINT_OFFSETOF(stat_channel, m_average)