Exemplo n.º 1
0
void LoggingConfigurator::configureLoggers(AbstractConfiguration* pConfig)
{
    typedef std::map<std::string, AutoPtr<AbstractConfiguration> > LoggerMap;

    AbstractConfiguration::Keys loggers;
    pConfig->keys(loggers);
    // use a map to sort loggers by their name, ensuring initialization in correct order (parents before children)
    LoggerMap loggerMap;
    for (AbstractConfiguration::Keys::const_iterator it = loggers.begin(); it != loggers.end(); ++it)
    {
        AutoPtr<AbstractConfiguration> pLoggerConfig(pConfig->createView(*it));
        loggerMap[pLoggerConfig->getString("name", "")] = pLoggerConfig;
    }
    for (LoggerMap::iterator it = loggerMap.begin(); it != loggerMap.end(); ++it)
    {
        configureLogger(it->second);
    }
}
Exemplo n.º 2
0
bool f_hphp_log(CStrRef filename, CStrRef message) {
  if (!RuntimeOption::EnableApplicationLog) {
    return false;
  }

  FILE *f = NULL;
  {
    ReadLock lock(s_loggers_mutex);
    if (Logger::UseCronolog) {
      CronLoggerMap::iterator iter = s_cronLoggers.find(filename.data());
      if (iter != s_cronLoggers.end()) {
        f = iter->second.getOutputFile();
      }
    } else {
      LoggerMap::const_iterator iter = s_loggers.find(filename.data());
      if (iter != s_loggers.end()) {
        f = iter->second;
      }
    }
  }
  if (f == NULL) {
    WriteLock lock(s_loggers_mutex);
    if (Logger::UseCronolog) {
      CronLoggerMap::iterator iter = s_cronLoggers.find(filename.data());
      if (iter != s_cronLoggers.end()) {
        f = iter->second.getOutputFile();
      } else {
        Cronolog cl;
        if (strchr(filename.c_str(), '%')) {
          cl.m_template = filename;
        } else {
          cl.m_file = fopen(filename.data(), "a");
        }
        s_cronLoggers[filename.data()] = cl;
        f = cl.getOutputFile();
        if (f == NULL) {
          return false;
        }
      }
    } else {
      LoggerMap::const_iterator iter = s_loggers.find(filename.data());
      if (iter != s_loggers.end()) {
        f = iter->second;
      } else {
        if (filename.charAt(0) == '|') {
          f = popen(filename.data() + 1, "w");
        } else {
          f = fopen(filename.data(), "a");
        }
        if (f == NULL) {
          return false;
        }
        s_loggers[filename.data()] = f;
      }
    }
  }
  bool ret = (fwrite(message.data(), message.size(), 1, f) == 1);
  if (ret) {
    fflush(f);
  }
  return ret;
}
Exemplo n.º 3
0
namespace HPHP {
///////////////////////////////////////////////////////////////////////////////

static ReadWriteMutex s_loggers_mutex;
typedef std::map<std::string, FILE*> LoggerMap;
typedef std::map<std::string, Cronolog> CronLoggerMap;
static LoggerMap s_loggers;
static CronLoggerMap s_cronLoggers;

bool f_hphp_log(CStrRef filename, CStrRef message) {
  if (!RuntimeOption::EnableApplicationLog) {
    return false;
  }

  FILE *f = NULL;
  {
    ReadLock lock(s_loggers_mutex);
    if (Logger::UseCronolog) {
      CronLoggerMap::iterator iter = s_cronLoggers.find(filename.data());
      if (iter != s_cronLoggers.end()) {
        f = iter->second.getOutputFile();
      }
    } else {
      LoggerMap::const_iterator iter = s_loggers.find(filename.data());
      if (iter != s_loggers.end()) {
        f = iter->second;
      }
    }
  }
  if (f == NULL) {
    WriteLock lock(s_loggers_mutex);
    if (Logger::UseCronolog) {
      CronLoggerMap::iterator iter = s_cronLoggers.find(filename.data());
      if (iter != s_cronLoggers.end()) {
        f = iter->second.getOutputFile();
      } else {
        Cronolog cl;
        if (strchr(filename.c_str(), '%')) {
          cl.m_template = filename;
        } else {
          cl.m_file = fopen(filename.data(), "a");
        }
        s_cronLoggers[filename.data()] = cl;
        f = cl.getOutputFile();
        if (f == NULL) {
          return false;
        }
      }
    } else {
      LoggerMap::const_iterator iter = s_loggers.find(filename.data());
      if (iter != s_loggers.end()) {
        f = iter->second;
      } else {
        if (filename.charAt(0) == '|') {
          f = popen(filename.data() + 1, "w");
        } else {
          f = fopen(filename.data(), "a");
        }
        if (f == NULL) {
          return false;
        }
        s_loggers[filename.data()] = f;
      }
    }
  }
  bool ret = (fwrite(message.data(), message.size(), 1, f) == 1);
  if (ret) {
    fflush(f);
  }
  return ret;
}

void f_hphp_crash_log(CStrRef name, CStrRef value) {
  StackTraceNoHeap::AddExtraLogging(name.data(), value.data());
}

Variant f_hphp_output_global_state(bool serialize /* = true */) {
  Array r(get_global_state());
  if (serialize) {
    return f_serialize(r);
  } else {
    return r;
  }
}

///////////////////////////////////////////////////////////////////////////////
}