verbose logging fixes

This commit is contained in:
Arvid Norberg 2010-11-15 04:43:53 +00:00
parent 94a25a3953
commit 79f6b5856b
2 changed files with 20 additions and 12 deletions

View File

@ -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;
};
}

View File

@ -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)