00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TORRENT_DEBUG_HPP_INCLUDED
00034 #define TORRENT_DEBUG_HPP_INCLUDED
00035
00036 #include <string>
00037 #include <fstream>
00038 #include <iostream>
00039
00040 #ifdef _MSC_VER
00041 #pragma warning(push, 1)
00042 #endif
00043
00044 #include <boost/lexical_cast.hpp>
00045 #include <boost/filesystem/fstream.hpp>
00046 #include <boost/filesystem/convenience.hpp>
00047
00048 #ifdef _MSC_VER
00049 #pragma warning(pop)
00050 #endif
00051
00052
00053 namespace libtorrent
00054 {
00055
00056
00057 #ifdef TORRENT_PROFILE
00058
00059 void add_checkpoint(std::string const& str);
00060 void print_checkpoints();
00061 #define TORRENT_CHECKPOINT(str) libtorrent::add_checkpoint(str)
00062 #else
00063 #define TORRENT_CHECKPOINT(str) void(0)
00064 #endif
00065
00066
00067
00068 struct logger
00069 {
00070 logger(boost::filesystem::path const& filename, int instance, bool append = true)
00071 {
00072 using namespace boost::filesystem;
00073 path dir(complete("libtorrent_logs" + boost::lexical_cast<std::string>(instance)));
00074 if (!exists(dir)) create_directories(dir);
00075 m_file.open(dir / filename, std::ios_base::out | (append ? std::ios_base::app : std::ios_base::out));
00076 *this << "\n\n\n*** starting log ***\n";
00077 }
00078
00079 template <class T>
00080 logger& operator<<(T const& v)
00081 {
00082 m_file << v;
00083 m_file.flush();
00084 return *this;
00085 }
00086
00087 boost::filesystem::ofstream m_file;
00088 };
00089
00090 }
00091
00092 #endif // TORRENT_DEBUG_HPP_INCLUDED