oasys::Logger Class Reference

#include <Logger.h>

Inheritance diagram for oasys::Logger:

dtn::BluetoothConvergenceLayer::Connection dtn::BundleActions dtn::BundleEventHandler dtn::BundleList dtn::BundlePayload dtn::CLConnection dtn::Contact dtn::ConvergenceLayer dtn::CustodyTimer dtn::DTNServer dtn::FileConvergenceLayer::Scanner dtn::FragmentManager dtn::GlobalStore dtn::InterfaceTable dtn::Link dtn::LinkScheduleEstimator dtn::LinkStateGraph dtn::MysqlSQLImplementation dtn::PostgresSQLImplementation dtn::Registration dtn::RegistrationTable dtn::RouteTable dtn::SQLStore dtnsim::Connectivity dtnsim::GlueNode dtnsim::SimContact dtnsim::Simulator dtnsim::TrAgent dtntunnel::DTNTunnel dtntunnel::IPTunnel dtntunnel::TCPTunnel::Connection dtntunnel::UDPTunnel::Listener oasys::BerkeleyDBIterator oasys::BerkeleyDBStore::DeadlockTimer oasys::BerkeleyDBTable oasys::BluetoothInquiry oasys::BluetoothServiceDiscoveryClient oasys::BluetoothServiceRegistration oasys::BluetoothSocket oasys::BufferedInput oasys::BufferedOutput oasys::DurableObjectCache< _DataType > oasys::DurableObjectCache< _BaseType > oasys::DurableObjectCache< oasys::SerializableObject > oasys::DurableStore oasys::DurableStoreImpl oasys::ExpatXMLParser oasys::FdIOClient oasys::FileSystemTable oasys::InitSequencer oasys::InternalKeyDurableTable< _ShimType, _KeyType, _DataType > oasys::IPSocket oasys::Lock oasys::MemoryIterator oasys::MemoryTable oasys::Notifier oasys::OnOffNotifier oasys::OpenFdCache< _Key, _CloseFcn > oasys::RateLimitedSocket oasys::SMTP oasys::TclCommand oasys::TclCommandInterp oasys::TimerSystem oasys::TokenBucket List of all members.

Detailed Description

Many objects will, at constructor time, format a log target and then use it throughout the code implementation -- the Logger class encapsulates this common behavior.

It therefore exports a set of functions (set_logpath, logpathf, logpath_appendf) to manipulate the logging path post-construction.

To support logging on a class basis instead of on a hierarchical basis, the Logger also takes the name of the class in the constructor. Since, by convention, paths start with '/' and classes cannot, this allows independent logging control by class name or by logging path.

For example:

 class LoggerTest : public Logger {
 public:
   LoggerTest() : Logger("LoggerTest", "/logger/test")
   {
       logf(LOG_DEBUG, "initializing");                  // no path needed
       logf("/logger/test" LOG_DEBUG, "intiializing"); // but can be given

       log_debug("loggertest initializing");           // macros work
       __log_debug("/logger/test", "initializing");    // but this case needs
                                                       // to be __log_debug
       set_logpath("/path");
       logpath_appendf("/a"); // logpath is "/path/a"
       logpath_appendf("/b"); // logpath is "/path/b"
   }
 };

Definition at line 82 of file Logger.h.

Public Member Functions

 Logger (const char *classname, const char *fmt,...)
 Constructor that initializes the logpath with a printf style format string.
 Logger (const char *classname, const std::string &logpath)
 Constructor that initializes to a constant std::string.
void logpathf (const char *fmt,...)
 Format function for logpath_.
void logpath_appendf (const char *fmt,...)
 Format function that appends to the end of the base path instead of overwriting.
void set_logpath (const char *logpath)
 Assignment function.
bool log_enabled (log_level_t level) const
 Wrapper around the base __log_enabled function that uses the logpath_ instance.
bool __log_enabled (log_level_t level, const char *path) const
 As described in Log.h, the log_debug style macros call log_enabled(level, path) before calling __logf.
int vlogf (log_level_t level, const char *fmt, va_list args) const
 Wrapper around vlogf that uses the logpath_ instance.
int logf (log_level_t level, const char *fmt,...) const
 Wrapper around logf that uses the logpath_ instance.
int logf (const char *logpath, log_level_t level, const char *fmt,...) const
 Yet another wrapper that just passes the log path straight through, ignoring the logpath_ instance altogether.
int __logf (log_level_t level, const char *fmt,...) const
 Wrapper around __logf, used by the log_debug style macros.
int log_multiline (log_level_t level, const char *msg) const
 And finally, one for log_multiline.
const char * logpath ()
 
Returns:
current logpath


Protected Attributes

const char * classname_
char logpath_ [LOG_MAX_PATHLEN]
size_t baselen_


Constructor & Destructor Documentation

Logger::Logger ( const char *  classname,
const char *  fmt,
  ... 
) [inline]

Constructor that initializes the logpath with a printf style format string.

Definition at line 218 of file Logger.h.

References baselen_, and logpath_.

oasys::Logger::Logger ( const char *  classname,
const std::string &  logpath 
) [inline]

Constructor that initializes to a constant std::string.

Definition at line 93 of file Logger.h.

References set_logpath().


Member Function Documentation

void Logger::logpathf ( const char *  fmt,
  ... 
) [inline]

Format function for logpath_.

Definition at line 230 of file Logger.h.

Referenced by dtn::AdminRegistration::AdminRegistration(), oasys::BluetoothSocket::BluetoothSocket(), dtn::BundleRouter::BundleRouter(), dtn::TCPConvergenceLayer::Connection::Connection(), dtn::BluetoothConvergenceLayer::Connection::Connection(), dtn::UDPConvergenceLayer::Sender::init(), dtn::BundlePayload::init(), dtn::BundlePayload::init_from_store(), dtn::UDPConvergenceLayer::interface_up(), dtn::TCPConvergenceLayer::interface_up(), dtn::BluetoothConvergenceLayer::interface_up(), dtn::LoggingRegistration::LoggingRegistration(), dtn::LinkStateRouter::LSRegistration::LSRegistration(), oasys::Mutex::Mutex(), dtnsim::Node::Node(), oasys::OnOffNotifier::OnOffNotifier(), dtn::Registration::serialize(), dtn::Link::serialize(), dtnsim::SimRegistration::SimRegistration(), oasys::SMTP::SMTP(), oasys::SMTPServer::SMTPServer(), dtn::TcaRouter::TcaRouter(), and dtn::TclRegistration::TclRegistration().

void Logger::logpath_appendf ( const char *  fmt,
  ... 
) [inline]

Format function that appends to the end of the base path instead of overwriting.

For example:

   set_logpath("/path");
   logpath_appendf("/a"); // logpath is "/path/a"
   logpath_appendf("/b"); // logpath is "/path/b"

Definition at line 240 of file Logger.h.

Referenced by dtn::BluetoothConvergenceLayer::Connection::Connection(), oasys::IPSocket::init_socket(), oasys::BluetoothSocket::init_socket(), oasys::Notifier::Notifier(), and oasys::OnOffNotifier::OnOffNotifier().

void oasys::Logger::set_logpath ( const char *  logpath  )  [inline]

Assignment function.

Definition at line 121 of file Logger.h.

References baselen_, and logpath_.

Referenced by Logger(), and dtn::BluetoothConvergenceLayer::NeighborDiscovery::NeighborDiscovery().

bool oasys::Logger::log_enabled ( log_level_t  level  )  const [inline]

Wrapper around the base __log_enabled function that uses the logpath_ instance.

Also, all Logger instances store the class name of the implementation, and logging can be enabled/disabled on that target as well, so we check the class name as well.

Definition at line 140 of file Logger.h.

References oasys::__log_enabled(), classname_, and logpath_.

Referenced by dtn::BundleDaemon::handle_bundle_received().

bool oasys::Logger::__log_enabled ( log_level_t  level,
const char *  path 
) const [inline]

As described in Log.h, the log_debug style macros call log_enabled(level, path) before calling __logf.

In the case of the Logger, the path parameter isn't really the path, but is actually the format string, so we actually call log_enabled on the logpath_ instance.

Also, all Logger instances store the class name of the implementation, and logging can be enabled/disabled on that target as well, so we check it.

Definition at line 157 of file Logger.h.

References oasys::__log_enabled(), classname_, and logpath_.

int oasys::Logger::vlogf ( log_level_t  level,
const char *  fmt,
va_list  args 
) const [inline]

Wrapper around vlogf that uses the logpath_ instance.

Definition at line 168 of file Logger.h.

References classname_, oasys::Log::instance(), logpath_, and oasys::Log::vlogf().

int Logger::logf ( log_level_t  level,
const char *  fmt,
  ... 
) const [inline]

Wrapper around logf that uses the logpath_ instance.

Definition at line 250 of file Logger.h.

References oasys::vlogf().

Referenced by oasys::TCPServer::accept(), oasys::BluetoothServer::accept(), oasys::RefCountedObject::add_ref(), oasys::IPSocket::async_connect_result(), oasys::BluetoothSocket::async_connect_result(), oasys::IPSocket::bind(), oasys::BluetoothSocket::bind(), oasys::IPSocket::close(), oasys::BluetoothSocket::close(), oasys::IPSocket::configure(), oasys::BluetoothSocket::configure(), dtn::Link::create_link(), oasys::RefCountedObject::del_ref(), oasys::LogCommand::exec(), oasys::BufferedInput::get_char(), dtnsim::TrAgent::init(), oasys::IPSocket::init_socket(), oasys::BluetoothSocket::init_socket(), dtn::TCPConvergenceLayer::interface_up(), oasys::BufferedInput::internal_read(), oasys::TCPServer::listen(), oasys::BluetoothServer::listen(), oasys::RefCountedObject::no_more_refs(), oasys::IPClient::read(), oasys::BufferedInput::read_some_bytes(), oasys::IPSocket::recvfrom(), oasys::TCPServerThread::run(), oasys::BluetoothServerThread::run(), oasys::BluetoothSocket::set_proto(), oasys::IPSocket::set_state(), oasys::BluetoothSocket::set_state(), oasys::IPSocket::shutdown(), and oasys::BluetoothSocket::shutdown().

int Logger::logf ( const char *  logpath,
log_level_t  level,
const char *  fmt,
  ... 
) const [inline]

Yet another wrapper that just passes the log path straight through, ignoring the logpath_ instance altogether.

This means a derived class doesn't need to explicitly qualify logf.

Definition at line 272 of file Logger.h.

int Logger::__logf ( log_level_t  level,
const char *  fmt,
  ... 
) const [inline]

Wrapper around __logf, used by the log_debug style macros.

(See Log.h for a full explanation of the need for __logf)

Definition at line 261 of file Logger.h.

References oasys::vlogf().

int oasys::Logger::log_multiline ( log_level_t  level,
const char *  msg 
) const [inline]

And finally, one for log_multiline.

Definition at line 200 of file Logger.h.

References classname_, oasys::Log::instance(), oasys::Log::log_multiline(), and logpath_.

Referenced by dtn::LoggingRegistration::deliver_bundle(), dtn::BundleDaemon::handle_bundle_received(), dtn::BluetoothConvergenceLayer::Connection::recv_bundle(), and dtn::BluetoothConvergenceLayer::Connection::send_announce().

const char* oasys::Logger::logpath (  )  [inline]

Returns:
current logpath

Definition at line 209 of file Logger.h.

References logpath_.

Referenced by dtn::TCPConvergenceLayer::Connection::Connection(), dtn::BluetoothConvergenceLayer::NeighborDiscovery::NeighborDiscovery(), and dtn::DTNServer::parse_conf_file().


Member Data Documentation

const char* oasys::Logger::classname_ [protected]

Definition at line 212 of file Logger.h.

Referenced by __log_enabled(), log_enabled(), log_multiline(), and vlogf().

char oasys::Logger::logpath_[LOG_MAX_PATHLEN] [protected]

Definition at line 213 of file Logger.h.

Referenced by __log_enabled(), dtn::APIRegistration::APIRegistration(), dtn::BlockingBundleList::BlockingBundleList(), oasys::FileIOClient::close(), dtn::TCPConvergenceLayer::Connection::Connection(), dtn::BluetoothConvergenceLayer::Connection::Connection(), oasys::DurableStore::create_store(), dtn::BundleDaemon::do_init(), oasys::BerkeleyDBStore::get_meta_table(), oasys::IPClient::get_nonblocking(), oasys::FdIOClient::get_nonblocking(), oasys::BluetoothClient::get_nonblocking(), oasys::MemoryStore::get_table(), oasys::FileSystemStore::get_table(), oasys::BerkeleyDBStore::get_table(), dtn::GlobalStore::GlobalStore(), dtn::UDPConvergenceLayer::Sender::init(), oasys::FileSystemStore::init(), dtn::BundlePayload::init(), oasys::BerkeleyDBStore::init(), oasys::BluetoothInquiry::inquire(), dtn::UDPConvergenceLayer::interface_up(), dtn::TCPConvergenceLayer::interface_up(), dtn::BluetoothConvergenceLayer::interface_up(), oasys::MemoryTable::itr(), oasys::Mutex::lock(), log_enabled(), log_multiline(), Logger(), logpath(), oasys::FileIOClient::lseek(), oasys::FileIOClient::lstat(), oasys::FileIOClient::mkstemp(), oasys::BluetoothInquiry::next(), oasys::Notifier::Notifier(), oasys::OnOffNotifier::OnOffNotifier(), oasys::FileIOClient::open(), oasys::IPSocket::poll_sockfd(), oasys::BluetoothSocket::poll_sockfd(), oasys::IPClient::read(), oasys::FdIOClient::read(), oasys::BluetoothClient::read(), oasys::IPClient::readall(), oasys::FdIOClient::readall(), oasys::BluetoothClient::readall(), oasys::IPClient::readv(), oasys::FdIOClient::readv(), oasys::BluetoothClient::readv(), oasys::IPClient::readvall(), oasys::FdIOClient::readvall(), oasys::BluetoothClient::readvall(), oasys::IPSocket::recv(), oasys::BluetoothSocket::recv(), oasys::IPSocket::recvfrom(), oasys::IPSocket::recvmsg(), oasys::FileIOClient::reopen(), dtntunnel::TCPTunnel::Connection::run(), dtn::CLConnection::run(), oasys::IPSocket::send(), oasys::BluetoothSocket::send(), dtn::FileConvergenceLayer::send_bundle(), dtn::BluetoothConvergenceLayer::Connection::send_loop(), oasys::IPSocket::sendmsg(), oasys::IPSocket::sendto(), oasys::BluetoothInquiry::set_hci_device_name(), set_logpath(), oasys::IPClient::set_nonblocking(), oasys::FdIOClient::set_nonblocking(), oasys::BluetoothClient::set_nonblocking(), oasys::FileIOClient::stat(), dtn::TclRegistration::TclRegistration(), oasys::TCPClient::timeout_connect(), oasys::IPClient::timeout_read(), oasys::FdIOClient::timeout_read(), oasys::BluetoothClient::timeout_read(), oasys::IPClient::timeout_readall(), oasys::FdIOClient::timeout_readall(), oasys::BluetoothClient::timeout_readall(), oasys::IPClient::timeout_readv(), oasys::FdIOClient::timeout_readv(), oasys::BluetoothClient::timeout_readv(), oasys::IPClient::timeout_readvall(), oasys::FdIOClient::timeout_readvall(), oasys::BluetoothClient::timeout_readvall(), oasys::IPClient::timeout_write(), oasys::FdIOClient::timeout_write(), oasys::BluetoothClient::timeout_write(), oasys::IPClient::timeout_writeall(), oasys::FdIOClient::timeout_writeall(), oasys::BluetoothClient::timeout_writeall(), oasys::IPClient::timeout_writev(), oasys::FdIOClient::timeout_writev(), oasys::BluetoothClient::timeout_writev(), oasys::IPClient::timeout_writevall(), oasys::FdIOClient::timeout_writevall(), oasys::BluetoothClient::timeout_writevall(), oasys::FileIOClient::truncate(), oasys::Mutex::try_lock(), oasys::FileIOClient::unlink(), oasys::Mutex::unlock(), vlogf(), oasys::OnOffNotifier::wait(), oasys::Notifier::wait(), dtn::APIClient::wait_for_bundle(), oasys::IPClient::write(), oasys::FdIOClient::write(), oasys::BluetoothClient::write(), oasys::IPClient::writeall(), oasys::FdIOClient::writeall(), oasys::BluetoothClient::writeall(), oasys::IPClient::writev(), oasys::FdIOClient::writev(), oasys::BluetoothClient::writev(), oasys::IPClient::writevall(), oasys::FdIOClient::writevall(), oasys::BluetoothClient::writevall(), and oasys::Mutex::~Mutex().

size_t oasys::Logger::baselen_ [protected]

Definition at line 214 of file Logger.h.

Referenced by Logger(), and set_logpath().


The documentation for this class was generated from the following file:
Generated on Fri Dec 22 14:48:06 2006 for DTN Reference Implementation by  doxygen 1.5.1