void StdOutputRedirector::checkForFileWrapAround() { if (_myMaximumFileSize > 0) { if (_myStartTime == -1) { _myStartTime = (long long)asl::Time().millis(); } long long myDelta = asl::Time().millis() - _myStartTime; if (myDelta > (_myFileSizeCheckFrequInSec * 1000)) { long myCurrentSize = getFileSize(_myOutputFilename); if (myCurrentSize >= _myMaximumFileSize) { _myOutputStreamOut.close(); // remove old archive if (_myLogInOneFileFlag && _myRemoveOldArchiveFlag && _myOldArchiveFilename != "" && fileExists(_myOldArchiveFilename)) { deleteFile(_myOldArchiveFilename); } // rename current log to archive version string myNewFilename = removeExtension(_myOutputFilename) + "logarchive_" + getCurrentTimeString() + (".log"); #ifdef _WIN32 MoveFileEx(_myOutputFilename.c_str(), myNewFilename.c_str(), MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH); #else rename(_myOutputFilename.c_str(), myNewFilename.c_str()); #endif _myOldArchiveFilename = myNewFilename; redirect(); } _myStartTime = (long long)asl::Time().millis(); } } }
bool Trace::dump(TraceLevel level, const char* file, int line, const char* buf, int buflen, const char* format, ...) { if(m_enabled == false || level < LEVEL_ERROR || level > m_level) return false; std::va_list ap; va_start(ap, format); char msgbuf[8156]; std::vsnprintf(msgbuf, sizeof (msgbuf), format, ap); va_end(ap); char srcbuf[256]; std::snprintf(srcbuf, sizeof (srcbuf), " {%s:%d}", file, line); assert(level >= 0 && level < LVSTR.size()); const auto msg = getCurrentTimeString() + LVSTR[level] + msgbuf + srcbuf + "\n" + dumpString(buf, buflen, 16) + "\n"; std::size_t n{0}; { std::lock_guard<std::mutex> lock{m_mutex}; if(m_file != nullptr) n = std::fwrite(msg.c_str(), sizeof (char), msg.size(), m_file); } return (n >= msg.size()); }
void StdOutputRedirector::init(const Arguments & theArguments) { if (theArguments.haveOption("--std-logfile")) { const char * myEnv = ::getenv(LOG_WRAPAROUND_FILESIZE); if (myEnv) { string mylogFileSize(myEnv); _myMaximumFileSize = asl::as<long>(mylogFileSize); } myEnv = ::getenv(LOG_CREATE_ON_EACH_RUN); if (myEnv) { string myTmpStr(myEnv); _myLogInOneFileFlag = !(strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_REMOVE_OLD_ARCHIVE); if (myEnv) { string myTmpStr(myEnv); _myRemoveOldArchiveFlag = (strcmp(toLowerCase(myTmpStr).c_str(), "true") == 0); } myEnv = ::getenv(LOG_WRAPAROUND_CHECK_SEC); if (myEnv) { string myTmpStr(myEnv); _myFileSizeCheckFrequInSec = asl::as<long>(myTmpStr); } std::string myFilenameWithTimestamp = expandString(theArguments.getOptionArgument("--std-logfile"), _myOutputFilename); if (!_myLogInOneFileFlag) { _myOutputFilename = myFilenameWithTimestamp; } // for syncing c like stderr & c++ cerr // default is true, not syncing is supposted to be faster, so maybe we should disable it //ios_base::sync_with_stdio(false); redirect(); // write a timestamp cout << ourAppStartMessage << _myOutputFilename << endl; cout << "Timestamp: " << getCurrentTimeString() << endl; cout << "---------" << endl; // remove all but latest archives if (_myRemoveOldArchiveFlag) { removeoldArchives(); } } }
void Screen::notificate(std::string message, bool sendMail) { boost::mutex::scoped_lock lockClass(m_screenMutex); LOG_INFO2("NOTIFICATION: " << message); if(sendMail) { system(boost::str( boost::format(ConfigManager::instance()->getString(ConfigManager::NOTIFICATION_COMMAND)) % ConfigManager::instance()->getString(ConfigManager::NOTIFICATION_SUBJECT) % message ).c_str()); } m_notifications.push_front(boost::str(boost::format("%1% %2%") % getCurrentTimeString() % message)); while(m_notifications.size() > 6) { m_notifications.pop_back(); } queueClear(); }
void MMSSwitcherThread::threadMain() { if (this->mode == 0) { unsigned int cnt = 0; while (1) { /* lock me */ this->lock.lock(); if (cnt % 10 == 0) { /* check and update date & time */ if ((date_s)||(date_p)||(time_s)||(time_p)) { string datestr, timestr; getCurrentTimeString(NULL, &datestr, ×tr); if (datestr != this->curr_date) { this->curr_date = datestr; if (date_s) date_s->setText(this->curr_date); if (date_p) date_p->setText(this->curr_date); } if (timestr.substr(0, 5) != this->curr_time) { this->curr_time = timestr.substr(0, 5); if (time_s) time_s->setText(this->curr_time); if (time_p) time_p->setText(this->curr_time); } } } if (this->plugin_invoked) { if (cnt - this->plugin_invoked >= 3) { /* if (this->sw->curr_previewWin < 0) this->sw->waitForPreview->show();*/ this->plugin_invoked = 0; } else if (this->preview_shown) this->plugin_invoked = 0; } if (this->my_spt) if (!this->my_spt->isRunning()) { /* if the last invoked show preview thread is not running anymore, check of waitForPreview */ /* if (!this->sw->waitForPreview->willHide()) if (this->sw->waitForPreview->isShown()) { // the wait for preview window is not removed by the plugin thread // therefore i have to display nopreview window this->sw->noPreview->show(); }*/ this->my_spt = NULL; } if (this->invoke_plugin >= 0) { /* start the showPreviewThread only if it does not running */ map<int, plugin_data_t *>::iterator i = this->sw->plugins.find(this->invoke_plugin); this->invoke_plugin = -1; if (i != this->sw->plugins.end()) { this->my_spt = i->second->switcher->showPreviewThread; this->plugin_invoked = cnt; this->preview_shown = false; if (!this->my_spt->isRunning()) this->my_spt->start(); } } /* unlock me */ this->lock.unlock(); /* sleep a little bit */ while (this->sleepcnt > 0) { this->sleepcnt--; msleep(50); } this->sleepcnt = 10; cnt++; } } else if (this->mode == 1) { /* check if i have to call showpreview */ if (this->sw->osdhandler) this->sw->osdhandler->invokeShowPreview(NULL); else if (this->sw->centralhandler) this->sw->centralhandler->invokeShowPreview(NULL); } }
string getLogFileName(logTypes t, unsigned int latentSpace, unsigned int maxIterations) { /* String to be populated for log file name. */ string logFileName; /* An object to convert latent space integer to string. */ ostringstream strLatentSpace; /* An object to convert maximum iterations integer to string. */ ostringstream strMaxIterations; /* An object to convert current thread ID to string. */ ostringstream strCurrThreadID; /* Append the prefix of file name, which is usually the location of the * dump directory folder. */ logFileName.append(OP_FILENAME_PRE); /* Assign log files distinct initials as per the requested log file type.*/ switch (t) { case LOG_USER_FEATURES: logFileName.append("US_"); break; case LOG_BUSINESS_FEATURES: logFileName.append("VB_"); break; case LOG_TRAINING_DATA: logFileName.append("TR_"); break; case LOG_VALIDATION_DATA: logFileName.append("VL_"); break; case LOG_TEST_DATA: logFileName.append("TE_"); break; case LOG_MEAN_SQUARE_ERROR: logFileName.append("ME_"); break; case LOG_BATCH_RESULTS: logFileName.append("BA_"); break; } /* Append the current time string to file name, this is a very important * step as it gives the unique name every single time this function is * called. */ logFileName.append(getCurrentTimeString()); /* Convert latent space integer to string. */ strLatentSpace << latentSpace; /* Convert maximum iterations integer to string. */ strMaxIterations << maxIterations; /* Convert the current thread ID integer to string. */ strCurrThreadID << omp_get_thread_num(); /* Avoid appending max iteration and feature space strings when log file * name request is for logging batch data. */ if (t != LOG_BATCH_RESULTS) { logFileName.append("_K_"); logFileName.append(strLatentSpace.str()); logFileName.append("_I_"); logFileName.append(strMaxIterations.str()); logFileName.append("_TID_"); logFileName.append(strCurrThreadID.str()); } /* Attach appropriate extension to the file name. */ logFileName.append(OP_FILENAME_EXT); return logFileName; }