Archive / / / log.cpp
2007-09-19 22:50:33 UTC
previous next
#include <boost/thread.hpp> #include <boost/date_time/posix_time/posix_time.hpp> #include <string> #include <fstream> // TODO: Include compiler option so that this header is ONLY included // in a debug configuration -- it is not portable and not needed in releases // Make sure the same is done for the call to pthread_self() below #include <pthread.h> #include "log.h" using namespace boost::posix_time; using namespace std; ofstream log::_log_file; boost::mutex log::_mutex; void log::init() { boost::mutex::scoped_lock lock(_mutex); _log_file.open("nova-server.log", ios::out | ios::app); } void log::close() { boost::mutex::scoped_lock lock(_mutex); _log_file.close(); } void log::info(string message) { boost::mutex::scoped_lock lock(_mutex); _log_file << "[" << to_simple_string(microsec_clock::local_time()) << " - info] [" << (unsigned long)pthread_self() << "] " << message << endl; } void log::error(string message) { boost::mutex::scoped_lock lock(_mutex); _log_file << "[" << to_simple_string(microsec_clock::local_time()) << " - error] [" << (unsigned long)pthread_self() << "] " << message << endl; } void log::debug(string message) { boost::mutex::scoped_lock lock(_mutex); _log_file << "[" << to_simple_string(microsec_clock::local_time()) << " - debug] [" << (unsigned long)pthread_self() << "] " << message << endl; }