00001 #include "Logging.hpp"
00002 #include <sys/time.h>
00003 #include <iostream>
00004 #include <cassert>
00005 #include <cstring>
00006 #include <sstream>
00007 #include <locale>
00008 #include <ctime>
00009
00010 namespace aitools {
00011 namespace invertedindex {
00012
00013 clock_t
00014 Logging::clock()
00015 {
00016 return std::clock();
00017 }
00018
00019 void
00020 Logging::debug(const std::string& message)
00021 {
00022 assert(std::clog << timestamp() << "DEBUG " << message << std::endl);
00023 }
00024
00025 void
00026 Logging::debug(const std::string& key, unsigned value)
00027 {
00028 assert(std::clog << timestamp() << "DEBUG " << key
00029 << " : " << value << std::endl);
00030 }
00031
00032 void
00033 Logging::debug(const std::string& key, const std::string& value)
00034 {
00035 assert(std::clog << timestamp() << "DEBUG " << key
00036 << " : " << value << std::endl);
00037 }
00038
00039 void
00040 Logging::error(const std::string& message)
00041 {
00042 std::cerr << timestamp() << "ERROR " << message << std::endl;
00043 }
00044
00045 void
00046 Logging::log(const std::string& message)
00047 {
00048 std::clog << timestamp() << "LOG " << message << std::endl;
00049 }
00050
00051 time_t
00052 Logging::time()
00053 {
00054 return std::time(NULL);
00055 }
00056
00057 std::string
00058 Logging::timestamp()
00059 {
00060 time_t rawtime(std::time(NULL));
00061 struct tm* now(localtime(&rawtime));
00062 std::ostringstream oss;
00063 oss << '[';
00064 if (now->tm_hour < 10) oss << '0';
00065 oss << now->tm_hour << ':';
00066 if (now->tm_min < 10) oss << '0';
00067 oss << now->tm_min << ':';
00068 if (now->tm_sec < 10) oss << '0';
00069 oss << now->tm_sec << "] ";
00070 return oss.str();
00071 }
00072
00073 }
00074 }