Exemple #1
0
    void PrivateConsoleLogHandler::coloredLog(const qi::LogLevel verb,
                    const qi::os::timeval date,
                    const char *category,
                    const char *msg,
                    const char *file,
                    const char *fct,
                    const int   line)
    {
      int context = qi::log::context();

      boost::mutex::scoped_lock scopedLock(_mutex, boost::defer_lock_t());
      if (_useLock)
        scopedLock.lock();

      if (context & qi::LogContextAttr_Verbosity) {
        header(verb);
      }
      if (context & qi::LogContextAttr_ShortVerbosity) {
        header(verb, false);
      }

      if (context & qi::LogContextAttr_Date)
        printf("%s ", qi::detail::dateToString(date).c_str());

      if (context & qi::LogContextAttr_Tid) {
        int tidColor = intToColor(qi::os::gettid());
        textColorBG(tidColor);
        textColorFG(InvertConsoleColor[tidColor]);
        printf("%s", qi::detail::tidToString().c_str());
        textColorAttr(reset);
        printf(" ");
      }

      if (context & qi::LogContextAttr_Category) {
        textColorFG(stringToColor(category));
        printf("%s: ", category);
        textColorAttr(qi::log::PrivateConsoleLogHandler::reset);
      }
      if (context & qi::LogContextAttr_File) {
        printf("%s", file);
        if (line != 0)
          printf("(%i)", line);
        printf(" ");
      }
      if (context & qi::LogContextAttr_Function)
        printf("%s() ", fct);
      if (context & qi::LogContextAttr_Return)
        printf("\n");
      std::string ss = msg;
      ss.reserve(qi::detail::rtrim(msg));
      printf("%s\n", ss.c_str());
    }
 void PrivateConsoleLogHandler::header(const qi::LogLevel verb, bool verbose) const
 {
   // display log level
   textColorAttr(reset);
   textColorFG(colorForHeader(verb));
   printf("%s ", logLevelToString(verb, verbose));
   textColorAttr(reset);
 }
 void PrivateConsoleLogHandler::header(const LogLevel verb) const
 {
   //display log level
   textColorAttr(reset);
   if (verb == fatal)
     textColorFG(magenta);
   if (verb == error)
     textColorFG(red);
   if (verb == warning)
     textColorFG(yellow);
   if (verb == info)
     textColorAttr(reset);
   if (verb == verbose)
     textColorAttr(dim);
   if (verb == debug)
     textColorAttr(dim);
   printf("%s ", logLevelToString(verb));
   textColorAttr(reset);
 }
 void PrivateConsoleLogHandler::textColorAttr(char attr) const
 {
   textColorFG(attr);
   return;
 }