From 01f70bfd8403159925a1a95b971761e16a04d702 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Thu, 18 Oct 2012 15:14:18 +0000 Subject: [PATCH] add session logging function --- include/libtorrent/aux_/session_impl.hpp | 2 ++ src/session_impl.cpp | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/libtorrent/aux_/session_impl.hpp b/include/libtorrent/aux_/session_impl.hpp index f3fd8b89e..974aad5dd 100644 --- a/include/libtorrent/aux_/session_impl.hpp +++ b/include/libtorrent/aux_/session_impl.hpp @@ -1116,6 +1116,8 @@ namespace libtorrent boost::shared_ptr create_log(std::string const& name , int instance, bool append = true); + void session_log(char const* fmt, ...) const; + // this list of tracker loggers serves as tracker_callbacks when // shutting down. This list is just here to keep them alive during // whe shutting down process diff --git a/src/session_impl.cpp b/src/session_impl.cpp index 12629b4ad..b44780b53 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -4765,6 +4765,21 @@ retry: // current options are file_logger, cout_logger and null_logger return boost::shared_ptr(new logger(m_logpath, name, instance, append)); } + + void session_impl::session_log(char const* fmt, ...) const + { + if (!m_logger) return; + + va_list v; + va_start(v, fmt); + + char usr[400]; + vsnprintf(usr, sizeof(usr), fmt, v); + va_end(v); + char buf[450]; + snprintf(buf, sizeof(buf), "%s: %s\n", time_now_string(), usr); + (*m_logger) << buf; + } #endif void session_impl::get_torrent_status(std::vector* ret