Exemple #1
0
int _log(enum LogLevel level, char* function, char* file, int line,  char* msg)
{
   struct timeval tv;
   gettimeofday(&tv, NULL);

   //case not init _fp_log
   if(NULL == _fp_log) {
      createLogFile();
   }

   //switch by size
   long fileLen=ftell(_fp_log);
   if(fileLen >= _kbSwitchLog * 1024) {
      printf("size of file is %ld, larger than %d, call createLogFile()\n", fileLen, _kbSwitchLog*1024);
      createLogFile();
   }

   //switch by time
   if(_curFileCreatedSeconds + _secondsSwitchLog <= tv.tv_sec) {
      printf("current time <%ld> is larger than <%ld + %d>, call createLogFile\n", tv.tv_sec, _curFileCreatedSeconds, _secondsSwitchLog);
      createLogFile();
   }

   if(level != LOG_DEBUG) {
      fprintf(_fp_log, "%ld %06ld %s %s %s %d %s\n", tv.tv_sec, tv.tv_usec, logLevelStr[level], function, file, line, msg);
      fflush(_fp_log);
   }
   //fprintf(stdout, "%ld %06ld %s %s %s %s %d\n", tv.tv_sec, tv.tv_usec, logLevelStr[level], msg, function, file, line);
   fprintf(stdout, "%ld %06ld %s %s\n", tv.tv_sec, tv.tv_usec, logLevelStr[level], msg);

   return LOG_SUCCESS;
}
Exemple #2
0
void FileLogAppender::truncate(size_t writtenSize) {
	date::year_month_day now(date::floor<date::days>(date::sys_days::clock::now()));
	date::year_month_day logStart(date::floor<date::days>(logStartDate_));

	if (logStart.day() != now.day()) {
		logging_.close();
		createLogFile();
		logStartDate_ = date::sys_days::clock::now();
	}

	if (static_cast<size_t>(logging_.tellp()) + writtenSize > limitLogSize_) {
		logging_.close();
		createLogFile();
	}
}
Exemple #3
0
void OSystem_SDL::init() {
	// Initialize SDL
	initSDL();

	// Enable unicode support if possible
	SDL_EnableUNICODE(1);

	// Disable OS cursor
	SDL_ShowCursor(SDL_DISABLE);

	if (!_logger)
		_logger = new Backends::Log::Log(this);

	if (_logger) {
		Common::WriteStream *logFile = createLogFile();
		if (logFile)
			_logger->open(logFile);
	}


	// Creates the early needed managers, if they don't exist yet
	// (we check for this to allow subclasses to provide their own).
	if (_mutexManager == 0)
		_mutexManager = new SdlMutexManager();

#if defined(USE_TASKBAR)
	if (_taskbarManager == 0)
		_taskbarManager = new Common::TaskbarManager();
#endif

}
Exemple #4
0
void OSystem_SDL::init() {
	// Initialize SDL
	initSDL();

	if (!_logger)
		_logger = new Backends::Log::Log(this);

	if (_logger) {
		Common::WriteStream *logFile = createLogFile();
		if (logFile)
			_logger->open(logFile);
	}


	// Creates the early needed managers, if they don't exist yet
	// (we check for this to allow subclasses to provide their own).
	if (_mutexManager == 0)
		_mutexManager = new SdlMutexManager();

	if (_timerManager == 0)
		_timerManager = new SdlTimerManager();

#if defined(USE_TASKBAR)
	if (_taskbarManager == 0)
		_taskbarManager = new Common::TaskbarManager();
#endif
}
Exemple #5
0
void OSystem_SDL::init() {
    // Initialize SDL
    initSDL();

    if (!_logger)
        _logger = new Backends::Log::Log(this);

    if (_logger) {
        Common::WriteStream *logFile = createLogFile();
        if (logFile)
            _logger->open(logFile);
    }


    // Creates the early needed managers, if they don't exist yet
    // (we check for this to allow subclasses to provide their own).
    if (_mutexManager == 0)
        _mutexManager = new SdlMutexManager();

    if (_timerManager == 0)
        _timerManager = new SdlTimerManager();

#ifdef USE_OPENGL
    // Setup a list with both SDL and OpenGL graphics modes
    setupGraphicsModes();
#endif
}
Exemple #6
0
void createLogFiles()
{
    extern lua_State *L;
    char *fn;
    char *station;
    char buf[32] = {0};

    fn = (char *)getTableElement(L, "logs", "logfile");
    createLogFile(fn);

    fn = (char *)getTableElement(L, "logs", "errfile");
    createLogFile(fn);

    fn = (char *)getTableElement(L, "logs", "err_details");
    createLogFile(fn);

    fn = (char *)getTableElement(L, "logs", "mbsnfile");
    createLogFile(fn);

    fn = (char *)getTableElement(L, "logs", "psnfile");
    createLogFile(fn);

    fn = (char *)getTableElement(L, "logs", "skufile");
    createLogFile(fn);

    station = (char *) getTableElement(L, "self", "STAT");
    sprintf( buf, "%slog", station);

    fn = (char *)getTableElement(L, "logs", buf);
    createLogFile(fn);

}
Exemple #7
0
void QInstallPage::initializePage()
{

    wizard()->button(QWizard::FinishButton)->setEnabled(false);

    screen->clear(); progressBar->reset(); progressBar->hide();

    createDirs(); installButton->setEnabled(true);

    createLogFile(installationDir);
}
void Profiler::logTimersToFile( bool p_timeStamp, bool p_printStatisticsFile, string p_fileName )
{
	vector<PerfTimer*> timersToLog;
	addLogTimersToVector(timersToLog);

	if( !timersToLog.empty() ){
		ofstream logFile;
		if( createLogFile( p_timeStamp, p_fileName, logFile ) ){
			logTimers( timersToLog, logFile );
			logFile.close();
		}

		ofstream statsFile;
		if( createLogFile( p_timeStamp, p_fileName+string("-STATS"), statsFile ) ){
			logTimerStats( timersToLog, statsFile );
			statsFile.close();
		}

		for( int i=0; i<timersToLog.size(); i++ ){
			timersToLog[i]->reset();
		}
	}
}
Exemple #9
0
int initLog(char* rootPathStoreLog, int secondsSwitchLog, int kbSwitchLog)
{
   if((NULL == rootPathStoreLog) ||
         (secondsSwitchLog <= 0) ||
         (kbSwitchLog <= 0))
   {
      return LOG_INVALID_INPUT_PARA;
   }
   memcpy((void*)_rootPathStoreLog, (void*)rootPathStoreLog, strlen(rootPathStoreLog));
   if(_rootPathStoreLog[strlen(_rootPathStoreLog)-1] == '/') {
      _rootPathStoreLog[strlen(_rootPathStoreLog)-1] = 0;
   }
   _secondsSwitchLog = secondsSwitchLog;
   _kbSwitchLog = kbSwitchLog;

   createLogFile();
   return LOG_SUCCESS;
}
void Program::loadSettings()
{
	std::wstring filePath = boost::str(boost::wformat(L"%1%\\audio.ini") % savePath);
	if (!boost::filesystem::exists(filePath))
	{
		std::fstream fileOut(filePath.c_str(), std::ios_base::out);
		fileOut.close();
	}
	CSimpleIniW ini(true, false, true);
	SI_Error error = ini.LoadFile(filePath.c_str());
	if (!error)
	{
		bool modified = false;
		const wchar_t *value[8];
		value[0] = ini.GetValue(L"settings", L"allow_radio_station_adjustment");
		value[1] = ini.GetValue(L"settings", L"connect_attempts");
		value[2] = ini.GetValue(L"settings", L"connect_delay");
		value[3] = ini.GetValue(L"settings", L"connect_timeout");
		value[4] = ini.GetValue(L"settings", L"enable_logging");
		value[5] = ini.GetValue(L"settings", L"network_timeout");
		value[6] = ini.GetValue(L"settings", L"stream_files_from_internet");
		value[7] = ini.GetValue(L"settings", L"transfer_files_from_server");
		if (value[0])
		{
			try
			{
				settings->allowRadioStationAdjustment = boost::lexical_cast<bool>(value[0]);
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"allow_radio_station_adjustment", boost::lexical_cast<std::wstring>(settings->allowRadioStationAdjustment).c_str());
			modified = true;
		}
		if (value[1])
		{
			try
			{
				settings->connectAttempts = boost::lexical_cast<unsigned int>(value[1]);
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"connect_attempts", boost::lexical_cast<std::wstring>(settings->connectAttempts).c_str());
			modified = true;
		}
		if (value[2])
		{
			try
			{
				settings->connectDelay = boost::lexical_cast<unsigned int>(value[2]) * 1000;
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"connect_delay", boost::lexical_cast<std::wstring>(settings->connectDelay / 1000).c_str());
			modified = true;
		}
		if (value[3])
		{
			try
			{
				settings->connectTimeout = boost::lexical_cast<unsigned int>(value[3]) * 1000;
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"connect_timeout", boost::lexical_cast<std::wstring>(settings->connectTimeout / 1000).c_str());
			modified = true;
		}
		if (value[4])
		{
			try
			{
				settings->enableLogging = boost::lexical_cast<bool>(value[4]);
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"enable_logging", boost::lexical_cast<std::wstring>(settings->enableLogging).c_str());
			modified = true;
		}
		if (value[5])
		{
			try
			{
				settings->networkTimeout = boost::lexical_cast<unsigned int>(value[5]) * 1000;
			}
			catch (boost::bad_lexical_cast &) {}
			if (settings->networkTimeout < 20000)
			{
				settings->networkTimeout = 20000;
			}
		}
		else
		{
			ini.SetValue(L"settings", L"network_timeout", boost::lexical_cast<std::wstring>(settings->networkTimeout / 1000).c_str());
			modified = true;
		}
		if (value[6])
		{
			try
			{
				settings->streamFiles = boost::lexical_cast<bool>(value[6]);
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"stream_files_from_internet", boost::lexical_cast<std::wstring>(settings->streamFiles).c_str());
			modified = true;
		}
		if (value[7])
		{
			try
			{
				settings->transferFiles = boost::lexical_cast<bool>(value[7]);
			}
			catch (boost::bad_lexical_cast &) {}
		}
		else
		{
			ini.SetValue(L"settings", L"transfer_files_from_server", boost::lexical_cast<std::wstring>(settings->transferFiles).c_str());
			modified = true;
		}
		if (modified)
		{
			ini.SaveFile(filePath.c_str());
		}
	}
	if (settings->enableLogging)
	{
		createLogFile();
	}
}
Exemple #11
0
void FileLogAppender::setLogDirectory(std::wstring const &directory) {
	logFilePath_ = directory;
	createLogFile();
}
Exemple #12
0
int main(int argc, char **argv) {

  int size, rank, rc, root = 0, nameLength = 20;

  MPI_Status status;
  MPI_File configFile = malloc(sizeof configFile);
  MPI_Info info;
  char *configFileName = "./configFile.txt";

  createLogFile();

  MPI_Init(&argc, &argv);
  
  initLogFile();

  MPI_Info_create(&info);

  MPI_Comm_size(MPI_COMM_WORLD, &size);
  MPI_Comm_rank(MPI_COMM_WORLD, &rank);

  printf("%d/%d started.\n", rank+1, size);

  char buf[nameLength + 1];

  rc = MPI_File_open(MPI_COMM_WORLD, configFileName,
                     MPI_MODE_RDONLY, info, &configFile);

  printf("%d/%d achieved the file_open result: %d.\n", rank+1, size, rc);

  // set the individual pointer to our position in the config file
  // master is the master of elevators
  rc = MPI_File_seek(configFile, rank * nameLength, MPI_SEEK_SET);
 
  rc = MPI_File_read(configFile, buf, nameLength, MPI_CHAR, &status);
  buf[nameLength] = '\0';
  int len = nameLength - 1;
  while ((len >= 0) && (buf[len] == ' ')) {
    buf[len] = '\0';
    len--;
  }

  rc = MPI_File_close(&configFile);

  char *ourname = buf;

  char str[50 + nameLength];
  printf(strcat (strcat (strcpy (str, "%d/%d has the name '"), ourname), "'.\n"), rank+1, size);

  //read in the file to be counted, line by line.
  FILE * fp;
  fp = fopen(argv[1], "r");

  if (fp == NULL) {
      printf("%d/%d did not find a document to count! Switching to assignment part 1.\n", rank+1, size);
    assgn = 1;
  } else {
    printf("%d/%d found a document to count. Switching to assignment part 2.\n", rank+1, size);
    assgn = 2;

      /*
      
      // general idea:

    char * line = NULL;
    size_t lineLen = 0;
    ssize_t read;
  
    dlist* list = NULL;
    dlist_create(10, &list);
    printf("size of list is %d\n", list->size);

    for (int c = 0; c < 15; c++) {
        char buf[6]; // long enough for test + num, e.g. test1
        sprintf(buf, "test%d", c);
      dlist_append(&list, buf);
    }

    char* thestring;

    printf("capacity is %d\n", list->capacity);
    for (int c = 0; c < 15; c++) {
      dlist_get(&list, c, &thestring);
      printf("string is: %s\n", thestring);
    }



    while ((read = getline(&line, &lineLen, fp)) != -1) {
      printf("Retrieved line of length %zu :\n", read);
      printf("%s", line);
    }
  
    if (line)
      free(line);

      */

    char * line = NULL;
    size_t lineLen = 0;
    ssize_t read;
  
    dlist_create(10, &list);

      // go through the lines in the file...

    int i = 0;

    while ((read = getline(&line, &lineLen, fp)) != -1) {
        i++;
        
        // ... and map them to the individual worker threads
        if (i % (size-1) == rank-1) {
        dlist_append(&list, line);
        }
    }
  
    if (line)
      free(line);
  }
  
  // we check whether or not we are the root process.
  if (rank == root) {
    master(rank);
  }
  else {
    worker(rank, ourname);
  }
 
  closeLogFile();
  
  printf("%d/%d ended.\n", rank+1, size);

  MPI_Finalize();
}
Exemple #13
0
void initialize(
    const string& _argv0,
    const Flags& flags,
    bool installFailureSignalHandler)
{
  static Once* initialized = new Once();

  if (initialized->once()) {
    return;
  }

  argv0 = _argv0;

  // Set glog's parameters through Google Flags variables.
  FLAGS_minloglevel = getMinLogLevel(flags.minloglevel);

  if (flags.log_dir.isSome()) {
    Try<Nothing> mkdir = os::mkdir(flags.log_dir.get());
    if (mkdir.isError()) {
      EXIT(1) << "Could not initialize logging: Failed to create directory "
              << flags.log_dir.get() << ": " << mkdir.error();
    }
    FLAGS_log_dir = flags.log_dir.get();
    // Do not log to stderr instead of log files.
    FLAGS_logtostderr = false;
  } else {
    // Log to stderr instead of log files.
    FLAGS_logtostderr = true;
  }

  // Log everything to stderr IN ADDITION to log files unless
  // otherwise specified.
  if (flags.quiet) {
    FLAGS_stderrthreshold = 3; // FATAL.

    // FLAGS_stderrthreshold is ignored when logging to stderr instead of log files.
    // Setting the minimum log level gets around this issue.
    if (FLAGS_logtostderr) {
      FLAGS_minloglevel = 3; // FATAL.
    }
  } else {
    FLAGS_stderrthreshold = FLAGS_minloglevel;
  }

  FLAGS_logbufsecs = flags.logbufsecs;

  google::InitGoogleLogging(argv0.c_str());
  if (flags.log_dir.isSome() && FLAGS_minloglevel != google::FATAL) {
    createLogFile(FLAGS_minloglevel);
  }

  VLOG(1) << "Logging to " <<
    (flags.log_dir.isSome() ? flags.log_dir.get() : "STDERR");

  if (installFailureSignalHandler) {
    // Handles SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, SIGTERM
    // by default.
    google::InstallFailureSignalHandler();

    // Set up our custom signal handlers.
    struct sigaction action;
    action.sa_handler = handler;

    // Do not block additional signals while in the handler.
    sigemptyset(&action.sa_mask);
    action.sa_flags = 0;

    // Set up the SIGPIPE signal handler to escalate to SIGABRT
    // in order to have the glog handler catch it and print all
    // of its lovely information.
    if (sigaction(SIGPIPE, &action, NULL) < 0) {
      PLOG(FATAL) << "Failed to set sigaction";
    }

    // We also do not want SIGTERM to dump a stacktrace, as this
    // can imply that we crashed, when we were in fact terminated
    // by user request.
    if (sigaction(SIGTERM, &action, NULL) < 0) {
      PLOG(FATAL) << "Failed to set sigaction";
    }
  }

  initialized->done();
}