Beispiel #1
0
// this should not throw exception since it is called often in a 
// catch block to log an exception.
void Log::log(ModuleId module, Level level, const std::exception &ex) 
    throw()
{
    if(!isLevelEnabled(module, level))
	return;

    // Print the exception information
    log(module, level, "Exception encountered: %s.", ex.what());
    return;
}
Beispiel #2
0
// this should not throw exception since it is called often in a 
// catch block to log an error resulting from an exception.
void Log::log(ModuleId module, Level level, const InternalException &ex) 
    throw()
{
    if(!isLevelEnabled(module, level))
	return;

    am_status_t statusCode = ex.getStatusCode();
    const char *status_desc = am_status_to_string(statusCode);
    // Print the exception information
    log(module, level, "Exception InternalException thrown "
	"with message: \"%s\" and status message: %s", 
	ex.getMessage(), status_desc);
    return;
}
Beispiel #3
0
ELogger::Level ELoggerConfig::log(ELogEvent& event) {
	if (isLevelEnabled(event.getLevel())) {
		for (int i = 0; i < appenders.size(); i++) {
			appenders.get(i)->append(event);
		}
	}

	if (getAdditivity()) {
		sp<ELoggerConfig> parent = configuration->getParentLoggerConfig(getName());
		if (parent != null) {
			parent->log(event);
		}
	}

	return getLevel();
}
Beispiel #4
0
  void GadgetronLogger::log(GadgetronLogLevel LEVEL, const char* filename, int lineno, const char* cformatting, ...)
  {
    //Check if we should log this message
    if (!isLevelEnabled(LEVEL)) return;

    const char* fmt = cformatting;
    std::string fmt_str;
    bool append_cformatting_needed = false; //Will be set to true if we add any additional labels

    if (isOutputOptionEnabled(GADGETRON_LOG_PRINT_DATETIME)) {
      time_t rawtime;
      struct tm * timeinfo;

      time ( &rawtime );
      timeinfo = localtime ( &rawtime );
      
      //Time the format YYYY-MM-DD HH:MM:SS
      char timestr[22];sprintf(timestr, "%d-%02d-%02d %02d:%02d:%02d ",
			       timeinfo->tm_year+1900, timeinfo->tm_mon+1, timeinfo->tm_mday,
			       timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);

      fmt_str += std::string(timestr);
      append_cformatting_needed = true;
    }

    if (isOutputOptionEnabled(GADGETRON_LOG_PRINT_LEVEL)) {
      switch (LEVEL) {
      case GADGETRON_LOG_LEVEL_DEBUG:
	fmt_str += "DEBUG ";
	break;
      case GADGETRON_LOG_LEVEL_INFO:
	fmt_str += "INFO ";
	break;
      case GADGETRON_LOG_LEVEL_WARNING:
	fmt_str += "WARNING ";
	break;
      case GADGETRON_LOG_LEVEL_ERROR:
	fmt_str += "ERROR ";
	break;
      default:
	;
      }
      append_cformatting_needed = true;
    }

    if (isOutputOptionEnabled(GADGETRON_LOG_PRINT_FILELOC)) {
      if (!isOutputOptionEnabled(GADGETRON_LOG_PRINT_FOLDER)) {
	const char* base_start = strrchr(filename,'/');
	if (!base_start) {
	  base_start = strrchr(filename,'\\'); //Maybe using backslashes
	}
	if (base_start) {
	  base_start++;
	  fmt_str += std::string("[") + std::string(base_start);
	} else {
	  std::string("[") + std::string(filename);
	}
      } else {
	fmt_str += std::string("[") + std::string(filename);
      }
      char linenostr[8];sprintf(linenostr, "%d", lineno);
      fmt_str += std::string(":") + std::string(linenostr);
      fmt_str += std::string("] ");
      append_cformatting_needed = true;
    }

    if (append_cformatting_needed) {
      fmt_str += std::string(cformatting); 
      fmt = fmt_str.c_str();      
    }

    va_list args;
    va_start (args, cformatting);
    vprintf(fmt, args);
    va_end (args);
    fflush(stdout);
  }