prefix_ senf::log::time_type senf::scheduler::LogTimeSource::operator()()
const
{
- return now();
+ return senf::scheduler::now();
}
///////////////////////////////////////////////////////////////////////////
{
if (address.address().multicast())
handle_.facet<senf::INet4MulticastSocketProtocol>().mcAddMembership(address.address());
- SENF_LOG(("UDP Console server started at " << address));
+ SENF_LOG(("UDP Console server started at " << address ));
}
prefix_ senf::console::UDPServer::UDPServer(senf::INet6SocketAddress const & address)
{
if (address.address().multicast())
handle_.facet<senf::INet6MulticastSocketProtocol>().mcAddMembership(address.address());
- SENF_LOG(("UDP Console server started at " << address));
+ SENF_LOG(("UDP Console server started at " << address ));
}
prefix_ senf::console::UDPServer & senf::console::UDPServer::replies(bool enable)
catch (Executor::ExitException &) {
// Ignored
}
+ catch (ExceptionMixin & ex) {
+ stream << ex.message() << '\n';
+ SENF_LOG((senf::log::IMPORTANT)("Error: " << ex.message()));
+ SENF_LOG((senf::log::NOTICE)(ex.backtrace()));
+ }
catch (std::exception & ex) {
- std::string msg (ex.what());
- std::string::size_type i (msg.find("-- \n"));
- if (i != std::string::npos)
- msg = msg.substr(i+4);
- stream << msg << std::endl;
+ stream << ex.what() << '\n';
+ SENF_LOG((senf::log::IMPORTANT)("Error: " << ex.what()));
}
if (replies_ && (emptyReplies_ || ! stream.str().empty())) {
if (target_)
std::stringstream ss;
ss << "\nException at\n";
formatBacktrace(ss, entries, nEntries);
- ss << "-- \n" << message_;
+ ss << "-- \n";
+ excLen_ = ss.str().size();
+ ss << what_;
what_ = ss.str();
}
#endif
// senf::ExceptionMixin
prefix_ senf::ExceptionMixin::ExceptionMixin(std::string const & description)
- : what_(description),
- message_(description)
+ : what_(description)
{
#ifdef SENF_DEBUG
addBacktrace();
#endif
}
-prefix_ std::string const & senf::ExceptionMixin::message()
+prefix_ std::string senf::ExceptionMixin::message()
const
{
+#ifdef SENF_DEBUG
+ return what_.substr(excLen_);
+#else
return message_;
+#endif
+}
+
+prefix_ std::string senf::ExceptionMixin::backtrace()
+ const
+{
+#ifdef SENF_DEBUG
+ return what_.substr(0,excLen_-4);
+#else
+ return "";
+#endif
}
prefix_ void senf::ExceptionMixin::append(std::string text)
{
- message_ += text;
what_ += text;
}
class ExceptionMixin
{
public:
- std::string const & message() const; ///< get exception description
+ std::string message() const; ///< get exception description
+ std::string backtrace() const; ///< Return backtrace (if available)
void append(std::string text); ///< Extend exception description
/**< Adds \a text to the description text. */
string. This should probably be a string constant
describing the exception for most derived
exceptions. */
+
std::string what_;
private:
#ifdef SENF_DEBUG
void addBacktrace();
+ std::string::size_type excLen_;
#endif
- std::string message_;
};
/** \brief Extensible exception base-class
: public senf::singleton<TimeSourceManager>
{
public:
- TimeSourceManager();
-
using senf::singleton<TimeSourceManager>::instance;
time_type now();
void timeSource(std::auto_ptr<TimeSource> source);
private:
+ TimeSourceManager();
boost::scoped_ptr<TimeSource> timeSource_;
+
+ friend class senf::singleton<TimeSourceManager>;
};
}}}
dumper(*i);
}
+template <class Iterator>
+prefix_ std::string senf::hexdumpQuote(Iterator i, Iterator i_end)
+{
+ std::string s;
+ for (; i != i_end; ++i)
+ s.push_back(*i >= ' ' && *i <= 126 ? *i : '.');
+ return s;
+}
+
///////////////////////////////cc.e////////////////////////////////////////
#undef prefix_
//#include "hexdump.mpp"
namespace senf {
- /** \brief Write range [ i, i_end ) to output stream in hexadecimal format
- */
+ /** \brief Write range [ i, i_end ) to output stream in hexadecimal format */
template <class Iterator>
void hexdump(Iterator i, Iterator i_end, std::ostream & stream, unsigned block_size=16);
+
+ /** \brief Return quoted iterator range */
+ template <class Iterator>
+ std::string hexdumpQuote(Iterator i, Iterator i_end);
}
///////////////////////////////hh.e////////////////////////////////////////