QString readLogFile() { SystemMutexLocker lock(getSessionMutex()); QString content; for (int i = 0; i < logFileCount; ++i) content.prepend( readLogFile(logFileName(i)) ); content.prepend(logFileName() + "\n\n"); return content; }
bool patchBinaryWithQtPathes(const char *fileName, const char *baseQtPath) { bool result = true; static const struct { const char *variable; const char *subDirectory; } variables[] = { {"qt_prfxpath=", ""}, {"qt_docspath=", "/doc"}, {"qt_hdrspath=", "/include"}, {"qt_libspath=", "/lib"}, {"qt_binspath=", "/bin"}, {"qt_plugpath=", "/plugins"}, {"qt_datapath=", ""}, {"qt_trnspath=", "/translations"}, {"qt_xmplpath=", "/examples"}, {"qt_demopath=", "/demos"} }; logFileName(fileName); for (int i = 0; i < (int)(sizeof(variables) / sizeof(variables[0])); i++) { const char * const newStr = allocFileNameCopyAppend( variables[i].variable, baseQtPath, variables[i].subDirectory); BinPatch binFile(fileName); const bool success = binFile.patch(variables[i].variable, newStr); delete[] newStr; if (!success) { result = false; } } return result; }
LogDialog::LogDialog(QWidget *parent) : QDialog(parent) , ui(new Ui::LogDialog) , m_showError(true) , m_showWarning(true) , m_showNote(true) , m_showDebug(true) , m_showTrace(true) { ui->setupUi(this); auto font = ui->textBrowserLog->font(); font.setFamily("Monospace"); ui->textBrowserLog->setFont(font); m_logDecorator = new LogDecorator(font, this); m_stringDecorator = new StringDecorator(this); m_threadNameDecorator = new ThreadNameDecorator(font, this); ui->labelLogFileName->setText(logFileName()); addFilterCheckBox(LogError, &LogDialog::showError); addFilterCheckBox(LogWarning, &LogDialog::showWarning); addFilterCheckBox(LogNote, &LogDialog::showNote); addFilterCheckBox(LogDebug, &LogDialog::showDebug); addFilterCheckBox(LogTrace, &LogDialog::showTrace); ui->layoutFilters->addStretch(1); updateLog(); }
string getLogFileName() { char buff[128]; long ti; struct tm *tm; string logFileName("proxy_"); time(&ti); tm=localtime(&ti); sprintf(buff,"%04d_%02d%02d_%02d%02d", tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday, tm->tm_hour,tm->tm_min); return logFileName+string(buff); }
void patchTextFiles(const char *newInstallBase) { #ifndef Q_OS_WIN const char * const baseQtPath = newInstallBase; const char * const newSourceBase = newInstallBase; const int fileCount = sizeof(textFileFileNames) / sizeof(const char *); for (int i = 0; i < fileCount; i++) { char * const fileName = allocFileNameCopyAppend(baseQtPath, textFileFileNames[i]); logFileName(fileName); logDiff(oldSourceBase, newSourceBase); logDiff(oldInstallBase, newInstallBase); replaceInTextFile(fileName, oldSourceBase, newSourceBase, oldInstallBase, newInstallBase); delete[] fileName; } #endif patchQMakeSpec(newInstallBase); }
void patchQMakeSpec(const char *path) { QString baseQtPath(path); const QString fileName(baseQtPath + "/mkspecs/default/qmake.conf"); QFile f(fileName); logFileName(qPrintable(fileName)); f.open(QIODevice::ReadOnly); QTextStream in(&f); QString all = in.readAll(); f.close(); // Old value is QMAKESPEC_ORIGINAL=C:/somepath/mkspecs/amakespce // New value should be QMAKESPEC_ORIGINAL=baseQtPath/mkspec/amakespec // We don't care to match the line end we simply match to the end of the file QRegExp regExp("(QMAKESPEC_ORIGINAL=).*(/mkspecs/.*)"); all.replace(regExp, "\\1"+baseQtPath+"\\2"); f.open(QIODevice::WriteOnly); QTextStream out(&f); out << all; }
EKF::EKF(const char *configurationFileName, const char *outputPath) : _ekfSteps(0), _strOutputPath(outputPath) { ConfigurationManager &configManager = ConfigurationManager::getInstance(); configManager.loadConfigurationFromFile(configurationFileName); if (!_strOutputPath.empty()) { std::string outputFileName(_strOutputPath + "output.yml"); _outputFileStorage.open(outputFileName, cv::FileStorage::WRITE); std::string logFileName(_strOutputPath + "log.txt"); _logFile.open(logFileName.c_str(), std::ios_base::out); #ifndef ANDROID // Se genera el video en el cual se va a guardar la secuencia de predicciones cv::Size size(configManager.cameraCalibration->pixelsX, configManager.cameraCalibration->pixelsY); _outputVideoWriter.open(_strOutputPath + "videoOutput.mpg", CV_FOURCC('P','I','M','1'), 20, size, true); #endif } }
GLC_TraceLog* GLC_TraceLog::instance(QString baseName) { if (NULL == m_pTraceLog) { if (baseName.isEmpty()) { QString fileName(QApplication::applicationName()); if (fileName.isEmpty()) { baseName= "GLC_lib_TraceLog"; } else { baseName= fileName + "_TraceLog"; } } QString logFileName(QDir::tempPath() + QDir::separator() + baseName); m_pTraceLog= new GLC_TraceLog(logFileName); m_pTraceLog->writeHeader(); } return m_pTraceLog; }
void log(const QString &text, const LogLevel level) { if ( !hasLogLevel(level) ) return; SystemMutexLocker lock(getSessionMutex()); const QByteArray msg = createLogMessage(text, level).toUtf8(); QFile f( logFileName() ); const bool writtenToLogFile = f.open(QIODevice::Append) && f.write(msg); if (writtenToLogFile) f.close(); // Log to file and if needed to stderr. if ( !writtenToLogFile || level <= LogWarning ) { QFile ferr; ferr.open(stderr, QIODevice::WriteOnly); ferr.write(msg); } if ( writtenToLogFile && f.size() > logFileSize ) rotateLogFiles(); }
bool patchDebugLibrariesWithQtPath(const char *baseQtPath) { bool result = true; static const struct { const char *fileName; } libraries[] = { #ifdef Q_OS_WIN { "/bin/Qt3Supportd4.dll" }, { "/bin/QtCored4.dll" }, { "/bin/QtGuid4.dll" }, { "/bin/QtHelpd4.dll" }, { "/bin/QtNetworkd4.dll" }, { "/bin/QtOpenGLd4.dll" }, { "/bin/QtScriptd4.dll" }, { "/bin/QtScriptToolsd4.dll" }, { "/bin/QtSqld4.dll" }, { "/bin/QtSvgd4.dll" }, { "/bin/QtTestd4.dll" }, { "/bin/QtWebKitd4.dll" }, { "/bin/QtXmld4.dll" }, { "/bin/QtXmlPatternsd4.dll" }, { "/lib/Qt3Supportd4.dll" }, { "/lib/QtCored4.dll" }, { "/lib/QtGuid4.dll" }, { "/lib/QtHelpd4.dll" }, { "/lib/QtNetworkd4.dll" }, { "/lib/QtOpenGLd4.dll" }, { "/lib/QtScriptd4.dll" }, { "/lib/QtScriptToolsd4.dll" }, { "/lib/QtSqld4.dll" }, { "/lib/QtSvgd4.dll" }, { "/lib/QtTestd4.dll" }, { "/lib/QtWebKitd4.dll" }, { "/lib/QtXmld4.dll" }, { "/lib/QtXmlPatternsd4.dll" }, { "/plugins/accessible/qtaccessiblecompatwidgetsd4.dll" }, { "/plugins/accessible/qtaccessiblewidgetsd4.dll" }, { "/plugins/codecs/qcncodecsd4.dll" }, { "/plugins/codecs/qjpcodecsd4.dll" }, { "/plugins/codecs/qkrcodecsd4.dll" }, { "/plugins/codecs/qtwcodecsd4.dll" }, { "/plugins/iconengines/qsvgicond4.dll" }, { "/plugins/imageformats/qgifd4.dll" }, { "/plugins/imageformats/qjpegd4.dll" }, { "/plugins/imageformats/qmngd4.dll" }, { "/plugins/imageformats/qsvgd4.dll" }, { "/plugins/imageformats/qtiffd4.dll" }, { "/plugins/sqldrivers/qsqlited4.dll" }, // { "/plugins/sqldrivers/qsqlodbcd4.dll" } #else { "/bin/assistant" }, { "/bin/assistant_adp" }, { "/bin/designer" }, { "/bin/linguist" }, { "/bin/lrelease" }, { "/bin/lupdate" }, { "/bin/moc" }, { "/bin/pixeltool" }, { "/bin/qcollectiongenerator" }, { "/bin/qdbus" }, { "/bin/qdbuscpp2xml" }, { "/bin/qdbuscpp2xml" }, { "/bin/qdbusviewer" }, { "/bin/qdbusxml2cpp" }, { "/bin/qhelpconverter" }, { "/bin/qhelpgenerator" }, { "/bin/qmake" }, { "/bin/qt3to4" }, { "/bin/qtconfig" }, { "/bin/qtdemo" }, { "/bin/rcc" }, { "/bin/uic" }, { "/bin/uic3" }, { "/bin/xmlpatterns" }, { "/demos/affine/affine" }, { "/demos/books/books" }, { "/demos/browser/browser" }, { "/demos/chip/chip" }, { "/demos/composition/composition" }, { "/demos/deform/deform" }, { "/demos/embeddeddialogs/embeddeddialogs" }, { "/demos/gradients/gradients" }, { "/demos/interview/interview" }, { "/demos/mainwindow/mainwindow" }, { "/demos/pathstroke/pathstroke" }, { "/demos/shared/libdemo_shared.a" }, { "/demos/spreadsheet/spreadsheet" }, { "/demos/sqlbrowser/sqlbrowser" }, { "/demos/textedit/textedit" }, { "/demos/undo/undo" }, { "/examples/assistant/simpletextviewer/simpletextviewer" }, { "/examples/dbus/chat/dbus-chat" }, { "/examples/dbus/complexpingpong/complexping" }, { "/examples/dbus/complexpingpong/complexpong" }, { "/examples/dbus/listnames/listnames" }, { "/examples/dbus/pingpong/ping" }, { "/examples/dbus/pingpong/pong" }, { "/examples/dbus/remotecontrolledcar/car/car" }, { "/examples/dbus/remotecontrolledcar/controller/controller" }, { "/examples/designer/calculatorbuilder/calculatorbuilder" }, { "/examples/designer/calculatorform/calculatorform" }, { "/examples/designer/worldtimeclockbuilder/worldtimeclockbuilder" }, { "/examples/desktop/screenshot/screenshot" }, { "/examples/desktop/systray/systray" }, { "/examples/dialogs/classwizard/classwizard" }, { "/examples/dialogs/configdialog/configdialog" }, { "/examples/dialogs/extension/extension" }, { "/examples/dialogs/findfiles/findfiles" }, { "/examples/dialogs/licensewizard/licensewizard" }, { "/examples/dialogs/standarddialogs/standarddialogs" }, { "/examples/dialogs/tabdialog/tabdialog" }, { "/examples/dialogs/trivialwizard/trivialwizard" }, { "/examples/draganddrop/draggableicons/draggableicons" }, { "/examples/draganddrop/draggabletext/draggabletext" }, { "/examples/draganddrop/dropsite/dropsite" }, { "/examples/draganddrop/fridgemagnets/fridgemagnets" }, { "/examples/draganddrop/puzzle/puzzle" }, { "/examples/graphicsview/collidingmice/collidingmice" }, { "/examples/graphicsview/diagramscene/diagramscene" }, { "/examples/graphicsview/dragdroprobot/dragdroprobot" }, { "/examples/graphicsview/elasticnodes/elasticnodes" }, { "/examples/graphicsview/padnavigator/padnavigator" }, { "/examples/graphicsview/portedasteroids/portedasteroids" }, { "/examples/graphicsview/portedcanvas/portedcanvas" }, { "/examples/help/contextsensitivehelp/contextsensitivehelp" }, { "/examples/help/remotecontrol/remotecontrol" }, { "/examples/help/simpletextviewer/simpletextviewer" }, { "/examples/ipc/localfortuneclient/localfortuneclient" }, { "/examples/ipc/localfortuneserver/localfortuneserver" }, { "/examples/ipc/sharedmemory/sharedmemory" }, { "/examples/itemviews/addressbook/addressbook" }, { "/examples/itemviews/basicsortfiltermodel/basicsortfiltermodel" }, { "/examples/itemviews/chart/chart" }, { "/examples/itemviews/coloreditorfactory/coloreditorfactory" }, { "/examples/itemviews/customsortfiltermodel/customsortfiltermodel" }, { "/examples/itemviews/dirview/dirview" }, { "/examples/itemviews/editabletreemodel/editabletreemodel" }, { "/examples/itemviews/pixelator/pixelator" }, { "/examples/itemviews/puzzle/puzzle" }, { "/examples/itemviews/simpledommodel/simpledommodel" }, { "/examples/itemviews/simpletreemodel/simpletreemodel" }, { "/examples/itemviews/simplewidgetmapper/simplewidgetmapper" }, { "/examples/itemviews/spinboxdelegate/spinboxdelegate" }, { "/examples/itemviews/stardelegate/stardelegate" }, { "/examples/layouts/basiclayouts/basiclayouts" }, { "/examples/layouts/borderlayout/borderlayout" }, { "/examples/layouts/dynamiclayouts/dynamiclayouts" }, { "/examples/layouts/flowlayout/flowlayout" }, { "/examples/linguist/arrowpad/arrowpad" }, { "/examples/linguist/hellotr/hellotr" }, { "/examples/linguist/trollprint/trollprint" }, { "/examples/mainwindows/application/application" }, { "/examples/mainwindows/dockwidgets/dockwidgets" }, { "/examples/mainwindows/mdi/mdi" }, { "/examples/mainwindows/menus/menus" }, { "/examples/mainwindows/recentfiles/recentfiles" }, { "/examples/mainwindows/sdi/sdi" }, { "/examples/network/blockingfortuneclient/blockingfortuneclient" }, { "/examples/network/broadcastreceiver/broadcastreceiver" }, { "/examples/network/broadcastsender/broadcastsender" }, { "/examples/network/chat/network-chat" }, { "/examples/network/download/download" }, { "/examples/network/downloadmanager/downloadmanager" }, { "/examples/network/fortuneclient/fortuneclient" }, { "/examples/network/fortuneserver/fortuneserver" }, { "/examples/network/ftp/ftp" }, { "/examples/network/http/http" }, { "/examples/network/loopback/loopback" }, { "/examples/network/securesocketclient/securesocketclient" }, { "/examples/network/threadedfortuneserver/threadedfortuneserver" }, { "/examples/network/torrent/torrent" }, { "/examples/opengl/2dpainting/2dpainting" }, { "/examples/opengl/framebufferobject/framebufferobject" }, { "/examples/opengl/framebufferobject2/framebufferobject2" }, { "/examples/opengl/grabber/grabber" }, { "/examples/opengl/hellogl/hellogl" }, { "/examples/opengl/overpainting/overpainting" }, { "/examples/opengl/pbuffers/pbuffers" }, { "/examples/opengl/pbuffers2/pbuffers2" }, { "/examples/opengl/samplebuffers/samplebuffers" }, { "/examples/opengl/textures/textures" }, { "/examples/painting/basicdrawing/basicdrawing" }, { "/examples/painting/concentriccircles/concentriccircles" }, { "/examples/painting/fontsampler/fontsampler" }, { "/examples/painting/imagecomposition/imagecomposition" }, { "/examples/painting/painterpaths/painterpaths" }, { "/examples/painting/svgviewer/svgviewer" }, { "/examples/painting/transformations/transformations" }, { "/examples/qtconcurrent/imagescaling/imagescaling" }, { "/examples/qtconcurrent/map/mapdemo" }, { "/examples/qtconcurrent/progressdialog/progressdialog" }, { "/examples/qtconcurrent/runfunction/runfunction" }, { "/examples/qtconcurrent/wordcount/wordcount" }, { "/examples/qtestlib/tutorial1/tutorial1" }, { "/examples/qtestlib/tutorial2/tutorial2" }, { "/examples/qtestlib/tutorial3/tutorial3" }, { "/examples/qtestlib/tutorial4/tutorial4" }, { "/examples/richtext/calendar/calendar" }, { "/examples/richtext/orderform/orderform" }, { "/examples/richtext/syntaxhighlighter/syntaxhighlighter" }, { "/examples/script/calculator/calculator" }, { "/examples/script/context2d/context2d" }, { "/examples/script/customclass/customclass" }, { "/examples/script/defaultprototypes/defaultprototypes" }, { "/examples/script/helloscript/helloscript" }, { "/examples/script/marshal/marshal" }, { "/examples/script/qscript/qscript" }, { "/examples/script/tetrix/tetrix" }, { "/examples/sql/cachedtable/cachedtable" }, { "/examples/sql/drilldown/drilldown" }, { "/examples/sql/masterdetail/masterdetail" }, { "/examples/sql/querymodel/querymodel" }, { "/examples/sql/relationaltablemodel/relationaltablemodel" }, { "/examples/sql/tablemodel/tablemodel" }, { "/examples/threads/mandelbrot/mandelbrot" }, { "/examples/threads/semaphores/semaphores" }, { "/examples/threads/waitconditions/waitconditions" }, { "/examples/tools/codecs/codecs" }, { "/examples/tools/completer/completer" }, { "/examples/tools/customcompleter/customcompleter" }, { "/examples/tools/echoplugin/echoplugin" }, { "/examples/tools/echoplugin/plugin/libechoplugin.so" }, { "/examples/tools/i18n/i18n" }, { "/examples/tools/plugandpaint/plugandpaint" }, { "/examples/tools/plugandpaint/plugins/libpnp_basictools.a" }, { "/examples/tools/plugandpaint/plugins/libpnp_extrafilters.so" }, { "/examples/tools/regexp/regexp" }, { "/examples/tools/settingseditor/settingseditor" }, { "/examples/tools/styleplugin/styleplugin" }, { "/examples/tools/styleplugin/styles/libsimplestyleplugin.so" }, { "/examples/tools/treemodelcompleter/treemodelcompleter" }, { "/examples/tools/undoframework/undoframework" }, { "/examples/tutorials/addressbook/part1/part1" }, { "/examples/tutorials/addressbook/part2/part2" }, { "/examples/tutorials/addressbook/part3/part3" }, { "/examples/tutorials/addressbook/part4/part4" }, { "/examples/tutorials/addressbook/part5/part5" }, { "/examples/tutorials/addressbook/part6/part6" }, { "/examples/tutorials/addressbook/part7/part7" }, { "/examples/tutorials/tutorial/t1/t1" }, { "/examples/tutorials/tutorial/t10/t10" }, { "/examples/tutorials/tutorial/t11/t11" }, { "/examples/tutorials/tutorial/t12/t12" }, { "/examples/tutorials/tutorial/t13/t13" }, { "/examples/tutorials/tutorial/t14/t14" }, { "/examples/tutorials/tutorial/t2/t2" }, { "/examples/tutorials/tutorial/t3/t3" }, { "/examples/tutorials/tutorial/t4/t4" }, { "/examples/tutorials/tutorial/t5/t5" }, { "/examples/tutorials/tutorial/t6/t6" }, { "/examples/tutorials/tutorial/t7/t7" }, { "/examples/tutorials/tutorial/t8/t8" }, { "/examples/tutorials/tutorial/t9/t9" }, { "/examples/uitools/multipleinheritance/multipleinheritance" }, { "/examples/uitools/textfinder/textfinder" }, { "/examples/webkit/formextractor/formExtractor" }, { "/examples/webkit/previewer/previewer" }, { "/examples/widgets/analogclock/analogclock" }, { "/examples/widgets/calculator/calculator" }, { "/examples/widgets/calendarwidget/calendarwidget" }, { "/examples/widgets/charactermap/charactermap" }, { "/examples/widgets/digitalclock/digitalclock" }, { "/examples/widgets/groupbox/groupbox" }, { "/examples/widgets/icons/icons" }, { "/examples/widgets/imageviewer/imageviewer" }, { "/examples/widgets/lineedits/lineedits" }, { "/examples/widgets/movie/movie" }, { "/examples/widgets/scribble/scribble" }, { "/examples/widgets/shapedclock/shapedclock" }, { "/examples/widgets/sliders/sliders" }, { "/examples/widgets/spinboxes/spinboxes" }, { "/examples/widgets/styles/styles" }, { "/examples/widgets/stylesheet/stylesheet" }, { "/examples/widgets/tablet/tablet" }, { "/examples/widgets/tetrix/tetrix" }, { "/examples/widgets/tooltips/tooltips" }, { "/examples/widgets/validators/validators" }, { "/examples/widgets/wiggly/wiggly" }, { "/examples/widgets/windowflags/windowflags" }, { "/examples/xml/dombookmarks/dombookmarks" }, { "/examples/xml/rsslisting/rsslisting" }, { "/examples/xml/saxbookmarks/saxbookmarks" }, { "/examples/xml/streambookmarks/streambookmarks" }, { "/examples/xml/xmlstreamlint/xmlstreamlint" }, { "/examples/xmlpatterns/filetree/filetree" }, { "/examples/xmlpatterns/qobjectxmlmodel/qobjectxmlmodel" }, { "/examples/xmlpatterns/recipes/recipes" }, { "/lib/libQt3Support.so.4.5.0" }, { "/lib/libQtAssistantClient.so.4.5.0" }, { "/lib/libQtCLucene.so.4.5.0" }, { "/lib/libQtCore.so.4.5.0" }, { "/lib/libQtDBus.so.4.5.0" }, { "/lib/libQtDesigner.so.4.5.0" }, { "/lib/libQtDesignerComponents.so.4.5.0" }, { "/lib/libQtGui.so.4.5.0" }, { "/lib/libQtHelp.so.4.5.0" }, { "/lib/libQtNetwork.so.4.5.0" }, { "/lib/libQtOpenGL.so.4.5.0" }, { "/lib/libQtScript.so.4.5.0" }, { "/lib/libQtScriptTools.so.4.5.0" }, { "/lib/libQtSql.so.4.5.0" }, { "/lib/libQtSvg.so.4.5.0" }, { "/lib/libQtTest.so.4.5.0" }, { "/lib/libQtUiTools.a" }, { "/lib/libQtWebKit.so.4.5.0" }, { "/lib/libQtXml.so.4.5.0" }, { "/lib/libQtXmlPatterns.so.4.5.0" }, { "/plugins/accessible/libqtaccessiblecompatwidgets.so" }, { "/plugins/accessible/libqtaccessiblewidgets.so" }, { "/plugins/codecs/libqcncodecs.so" }, { "/plugins/codecs/libqjpcodecs.so" }, { "/plugins/codecs/libqkrcodecs.so" }, { "/plugins/codecs/libqtwcodecs.so" }, { "/plugins/designer/libarthurplugin.so" }, { "/plugins/designer/libcontainerextension.so" }, { "/plugins/designer/libcustomwidgetplugin.so" }, { "/plugins/designer/libqt3supportwidgets.so" }, { "/plugins/designer/libqwebview.so" }, { "/plugins/designer/libtaskmenuextension.so" }, { "/plugins/designer/libworldtimeclockplugin.so" }, { "/plugins/iconengines/libqsvgicon.so" }, { "/plugins/imageformats/libqgif.so" }, { "/plugins/imageformats/libqico.so" }, { "/plugins/imageformats/libqjpeg.so" }, { "/plugins/imageformats/libqmng.so" }, { "/plugins/imageformats/libqsvg.so" }, { "/plugins/imageformats/libqtiff.so" }, { "/plugins/inputmethods/libqimsw-multi.so" }, { "/plugins/script/libqtscriptdbus.so" }, { "/plugins/sqldrivers/libqsqlite.so" }, { "/plugins/sqldrivers/libqsqlite2.so" }, { "/plugins/sqldrivers/libqsqlmysql.so" }, { "/plugins/sqldrivers/libqsqlpsql.so" } #endif }; for (int i = 0; i < (int)(sizeof(libraries) / sizeof(libraries[0])); i++) { // USAGE NOTE: Don't use FILENAME_MAX as the size of an array in which to store a file name! // [In some cases] you [may not be able to statically] make an array that big! // Use dynamic allocation [..] instead. // From http://www.gnu.org/software/libc/manual/html_mono/libc.html#Limits-for-Files // Make filename char * const fileName = allocFileNameCopyAppend(baseQtPath, libraries[i].fileName); logFileName(fileName); logDiff(oldSourceBase, baseQtPath); // Patch BinPatch binFile(fileName); binFile.enableInsertReplace(true); if (!binFile.patch(oldSourceBase, baseQtPath)) result = false; delete[] fileName; } return result; }
int main (int argc, char** argv) { int returnCode = 0; try { const char* epocRoot = getenv("EPOCROOT"); if(NULL == epocRoot) { throw CException("EPOCROOT environment variable not specified.", ExceptionCodes::EEnvNotSpecified); } std::string epocRootStr(epocRoot); COptions options(argc, argv); std::string logFileName(options.GetLogFileName()); std::auto_ptr<CLogger> logger(new CLogger(logFileName, options.GetLogLevel())); #ifdef __LINUX__ std::string dllPath = "sqlite-3.6.1.so"; #else std::string dllPath = "sqlite3.dll"; #endif std::auto_ptr<CDbLayer> db( new CDbLayer(dllPath, options.GetDbFileName())); std::auto_ptr<CScrXmlParser> xmlParser( new CScrXmlParser()); if(options.IsDbAbsent()) { #ifdef __LINUX__ std::string dbFileName = epocRootStr + "epoc32/tools/create_db.xml"; #else std::string dbFileName = epocRootStr + "epoc32\\tools\\create_db.xml"; #endif std::auto_ptr<SchemaDetails> schema(xmlParser->ParseDbSchema(dbFileName)); db->CreateScrDatabase(*schema); } std::vector<std::string> xmlFileNames = options.GetEnvFileNames(); for(StringIterator xmlIter=xmlFileNames.begin(); xmlIter != xmlFileNames.end(); ++xmlIter) { std::auto_ptr<EnvDetails> envDetails(xmlParser->GetEnvironmentDetails(*xmlIter)); db->PopulateScrDatabase(*envDetails); } if(options.IsPreProvisionInfoAvailable()) { std::string preProvFileName = options.GetPrePovisionFileName(); XmlDetails::TScrPreProvisionDetail preProvisionDetailList = xmlParser->GetPreProvisionDetails(preProvFileName); db->PopulatePreProvisionDetails(preProvisionDetailList); } } catch(CException& aException) { const std::string& exc = aException.GetMessageA(); returnCode = aException.GetCode(); std::cout << "Exception caught::" << exc << std::endl; std::cout << "Error Code::" << returnCode << std::endl; } return returnCode; }
/* * Author: Csaszar, Peter <*****@*****.**> * Copyright (C) 2009-2012 Csaszar, Peter */ #include <sys/time.h> #include <sys/stat.h> #include <unistd.h> #include <errno.h> #include <time.h> #include <string.h> #include <stdio.h> #include <stdlib.h> #include <stdarg.h> #ifdef FCLOG #include <fclog.h> #endif #include "csjp_logger.h" namespace csjp { static void dateStamp(char res[16]) { time_t t = time(NULL); strftime(res, 16, "%Y-%m-%d-%a", localtime(&t)); } static void timeStamp(char res[16]) { char timeStr[16] = {0}; timeval unixTime; gettimeofday(&unixTime, NULL); time_t t = unixTime.tv_sec; int unixMillisecs = unixTime.tv_usec/1000; struct tm _tm; localtime_r(&t, &_tm); strftime(timeStr, sizeof(timeStr), "%H:%M:%S", &_tm); snprintf(res, 16, "%s:%03d", timeStr, unixMillisecs); } static char g_LogDir[256] = {0}; static char g_LogFileName[512] = {0}; static char g_LogFileNameSpecializer[128] = {0}; static char g_BinaryName[128] = "unknown"; bool verboseMode = false; bool haveLogDir = true; void resetLogFileName() { g_LogFileName[0] = 0; } void setLogDir(const char * dir) { if(dir) strncpy(g_LogDir, dir, sizeof(g_LogDir)); else strncpy(g_LogDir, "./", sizeof(g_LogDir)); haveLogDir = true; resetLogFileName(); } void setBinaryName(const char * name) { if(!name) return; const char *baseName = strrchr(name, '/'); baseName = baseName ? baseName + 1 : name; strncpy(g_BinaryName, baseName, sizeof(g_BinaryName)); resetLogFileName(); } const char * getBinaryName() { return g_BinaryName; } const char * logFileName() { #ifdef FCLOG return FCLOG_FILE; #else if(g_LogFileName[0] == 0 && haveLogDir){ struct stat fileStat; if(0 <= stat(g_LogDir, &fileStat)) if(S_ISDIR(fileStat.st_mode)){ snprintf(g_LogFileName, sizeof(g_LogFileName), "%s/%s%s.log", g_LogDir, g_BinaryName, g_LogFileNameSpecializer); return g_LogFileName; } haveLogDir = false; } return g_LogFileName; #endif } void setLogFileNameSpecializer(const char * str) { if(str != NULL){ g_LogFileNameSpecializer[0] = '.'; strncpy(g_LogFileNameSpecializer + 1, str, sizeof(g_LogFileNameSpecializer) - 1); } else g_LogFileNameSpecializer[0] = 0; resetLogFileName(); } static unsigned loggerMutex = 0; /* Initialized before main() */ void msgLogger(FILE * stdfile, const char * string, size_t length) { if(!length) length = strlen(string); char header[64]; { char time_stamp[16]; timeStamp(time_stamp); char date_stamp[16]; dateStamp(date_stamp); double c = (double)(clock())/(double)(CLOCKS_PER_SEC); snprintf(header, sizeof(header), "%14s %12s %7.3f %5d", date_stamp, time_stamp, c, getpid()); } const char * fmt = "%s %s "; #if ! _ISOC99_SOURCE #error We need to use C99 for calculating printed number of characters with vsnprintf(). #endif /* Now lets calculate the amount of memory needed by the full log message. */ int size = 0; size += strlen(fmt); size += sizeof(header); size += length; /* Allocate memory */ char * msg = (char*)malloc(size); if(!msg){ if(stderr) fprintf(stderr, VT_RED VT_TA_BOLD "ERROR" VT_NORMAL "No enoguh memory for log message!"); return; } /* Compose the log message */ int len = snprintf(msg, size, fmt, header, string); if(len < 0){ if(stderr) fprintf(stderr, VT_RED VT_TA_BOLD "ERROR" VT_NORMAL "Failed to snprintf the log message and its header!\n"); free(msg); return; } msg[len++] = '\n'; msg[len] = 0; /* We need to have logging thread safe. * We should not use posix mutex since that might fail, and * on posix failure we should report the issue, thus call * this logger. This would be a circular dependency and a * possible place to have infinite recursion. * * So we are going to use gcc special low level atomic operations. * http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html#Atomic-Builtins * type __sync_fetch_and_add (type *ptr, type value, ...) * type __sync_fetch_and_sub (type *ptr, type value, ...) */ #if not __GNUC__ >= 4 #error "We need gcc 4 or later for __sync_fetch_and_add() and __sync_fetch_and_sub()" #endif unsigned loggerMutexLast = 1; while(loggerMutexLast){ loggerMutexLast = __sync_fetch_and_add(&loggerMutex, 1); if(loggerMutexLast){ __sync_fetch_and_sub(&loggerMutex, 1); usleep(100); } } if(haveLogDir && logFileName()[0]){ FILE *log = fopen(logFileName(), "a"); if(log){ fputs(msg, log); fflush(log); TEMP_FAILURE_RETRY( fclose(log) ); } else if(stderr) { fprintf(stderr, VT_RED VT_TA_BOLD "ERROR" VT_NORMAL " Could not open logfile: %s\n", logFileName()); haveLogDir = false; } } basicLogger(msg, stdfile, g_BinaryName); __sync_fetch_and_sub(&loggerMutex, 1); free(msg); }
/////////////////////////////////////////////////////////////////////////////// // Note: this method should get speeded up (see Gnats PR 846). MyString MultiLogFiles::loadLogFileNameFromSubFile(const MyString &strSubFilename, const MyString &directory, bool &isXml, bool usingDefaultNode) { dprintf( D_FULLDEBUG, "MultiLogFiles::loadLogFileNameFromSubFile(%s, %s)\n", strSubFilename.Value(), directory.Value() ); TmpDir td; if ( directory != "" ) { MyString errMsg; if ( !td.Cd2TmpDir(directory.Value(), errMsg) ) { dprintf(D_ALWAYS, "Error from Cd2TmpDir: %s\n", errMsg.Value()); return ""; } } StringList logicalLines; if ( fileNameToLogicalLines( strSubFilename, logicalLines ) != "" ) { return ""; } MyString logFileName(""); MyString initialDir(""); MyString isXmlLogStr(""); // Now look through the submit file logical lines to find the // log file and initial directory (if specified) and combine // them into a path to the log file that's either absolute or // relative to the DAG submit directory. Also look for log_xml. const char *logicalLine; while( (logicalLine = logicalLines.next()) != NULL ) { MyString submitLine(logicalLine); MyString tmpLogName = getParamFromSubmitLine(submitLine, "log"); if ( tmpLogName != "" ) { logFileName = tmpLogName; } // If we are using the default node log, we don't care // about these if( !usingDefaultNode ) { MyString tmpInitialDir = getParamFromSubmitLine(submitLine, "initialdir"); if ( tmpInitialDir != "" ) { initialDir = tmpInitialDir; } MyString tmpLogXml = getParamFromSubmitLine(submitLine, "log_xml"); if ( tmpLogXml != "" ) { isXmlLogStr = tmpLogXml; } } } if ( !usingDefaultNode ) { // // Check for macros in the log file name -- we currently don't // handle those. // // If we are using the default node, we don't need to check this if ( logFileName != "" ) { if ( strstr(logFileName.Value(), "$(") ) { dprintf(D_ALWAYS, "MultiLogFiles: macros ('$(...') not allowed " "in log file name (%s) in DAG node submit files\n", logFileName.Value()); logFileName = ""; } } // Do not need to prepend initialdir if we are using the // default node log if ( logFileName != "" ) { // Prepend initialdir to log file name if log file name is not // an absolute path. if ( initialDir != "" && !fullpath(logFileName.Value()) ) { logFileName = initialDir + DIR_DELIM_STRING + logFileName; } // We do this in case the same log file is specified with a // relative and an absolute path. // Note: we now do further checking that doesn't rely on // comparing paths to the log files. wenger 2004-05-27. CondorError errstack; if ( !makePathAbsolute( logFileName, errstack ) ) { dprintf(D_ALWAYS, "%s\n", errstack.getFullText().c_str()); return ""; } } isXmlLogStr.lower_case(); isXml = (isXmlLogStr == "true"); if ( directory != "" ) { MyString errMsg; if ( !td.Cd2MainDir(errMsg) ) { dprintf(D_ALWAYS, "Error from Cd2MainDir: %s\n", errMsg.Value()); return ""; } } } return logFileName; }
bool XmlReport::createInformationLog( const QString& dir, const ER_EXCEPTIONRECORD& exceptionRecord, const ER_ADDITIONALINFO& info, const ER_PROCESSOR& processor, const ER_OPERATINGSYSTEM& os, const ER_MEMORY& memory, const MODULE_LIST& modules) { // // 生成 XML 文件的名字。 // QString logFileName("InforLog.xml"); QString filePath = dir + "\\" + logFileName; QFile logFile(filePath); bool opened = logFile.open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text); if (!opened) { return false; } // 写 XML 文件的头。 QTextStream xmlStream(&logFile); xmlStream << "<Exception>"; // // 生成 ExceptionRecord 节点。 // QString xRecord = QString( "<ExceptionRecord ModuleName=\"%1\" " "ExceptionCode=\"%2\" " "ExceptionDescription=\"%3\" " "ExceptionAddress=\"%4\" " "ExceptionModuleName=\"%5\" " "/>").arg(exceptionRecord.ModuleName) .arg(exceptionRecord.ExceptionCode) .arg(exceptionRecord.ExceptionDescription) .arg(exceptionRecord.ExceptionAddress) .arg(exceptionRecord.ExceptionModuleName); xmlStream << xRecord; QString xInfo = QString( "<AdditionalInfomation Guid=\"%1\" DistSrc=\"%2\"/>").arg(info.Guid).arg(info.DistSrc); xmlStream << xInfo; // // 生成 Processor 节点。 // QString xProcessor = QString( "<Processor Architecture=\"%1\" Level=\"%2\" NumberOfProcessors=\"%3\"/>") .arg(processor.Architecture).arg(processor.Level) .arg(processor.NumberOfProcessors); xmlStream << xProcessor; // // 生成 OperatingSystem 节点。 // QString xOS = QString( "<OperatingSystem MajorVersion=\"%1\" " "MinorVersion=\"%2\" " "BuildNumber=\"%3\" " "CSDVersion=\"%4\" " "OSLanguage=\"%5\" " "/>").arg(os.MajorVersion).arg(os.MinorVersion).arg(os.BuildNumber).arg(os.CSDVersion) .arg(os.OSLanguage); xmlStream << xOS; // // 生成 Memory 节点。 // QString xMemory = QString( "<Memory MemoryLoad=\"%1%\" " "TotalPhys=\"%2 MB\" " "AvailPhys=\"%3 MB\" " "TotalPageFile=\"%4 MB\" " "AvailPageFile=\"%5 MB\" " "TotalVirtual=\"%6 MB\" " "AvailVirtual=\"%7 MB\" " "/>").arg(memory.MemoryLoad).arg(memory.TotalPhys).arg(memory.AvailPhys) .arg(memory.TotalPageFile).arg(memory.AvailPageFile).arg(memory.TotalVirtual) .arg(memory.AvailVirtual); xmlStream << xMemory; // // 生成 Modules 和 Module 节点。 // xmlStream << "<Modules>"; int count = modules.size(); for (int i = 0; i < count; ++i) { QString xModule = QString( "<Module FullPath=\"%1\" " "BaseAddress=\"%2\" " "Size=\"%3\" " "TimeStamp=\"%4\" " "FileVersion=\"%5\" " "ProductVersion=\"%6\" " "/>").arg(modules[i].FullPath).arg(modules[i].BaseAddress) .arg(modules[i].Size).arg(modules[i].TimeStamp).arg(modules[i].FileVersion) .arg(modules[i].ProductVersion); xmlStream << xModule; } xmlStream << "</Modules></Exception>"; return true; }
int main(int argc, char* argv[]) { po::options_description desc("Usage"); desc.add_options() ("execute", new ArgTypeString(std::string("<directory>")), "Backtest the configuration file in <directory>. Various files are output to the same location. The configuration file must be named config.xml or _config.xml.") ("genetic-algo", new ArgTypeString(std::string("<config template>")), "Run a genetic algo using the supplied file as the template. Requires an HTCondor cluster.") // ("tcp-port", new ArgTypeInt(std::string("<Port Number>")), // "Used with --genetic-algo. Specifies the TCP port node comminicate with the GA server on.") // ("test-send", "Send a test message to another DeepThought instance via ZeroMQ to test comms.") // ("test-receive", "Test receiving messages via ZeroMQ to test comms.") ("version", "Print version info.") ; po::variables_map variablesMap; try { namespace po_style = boost::program_options::command_line_style; po::store(po::command_line_parser(argc, argv).options(desc).style(po_style::unix_style|po_style::case_insensitive).run(), variablesMap); } catch (std::exception &e) { std::cout << "Error parsing command line : " << e.what() << "\n\n" << desc << "\n"; return 1; } po::notify(variablesMap); if (variablesMap.count("version")) { std::cout << "GridGA Version :\t\t" << DEEPTHOUGHT_VERSION << std::endl << "Build type :\t\t\t" << BUILD_TYPE << std::endl << "Build host :\t\t\t" << COMPILE_HOST << std::endl << "Compiler : \t\t\t" << COMPILER_ID << " " << COMPILER_VERSION << std::endl << "Boost version : \t\t" << BOOST_COMPILE_VERSION << std::endl << "Home directory : \t\t" << DeepThoughtLib::FileUtils::GetHomeDir() << std::endl << "Binary install directory : \t" << DeepThoughtLib::FileUtils::GetExePath() << std::endl; return 1; } std::string logFileName("ga.log"); if (variablesMap.count("execute")) { std::string filesLocation(variablesMap["execute"].as<std::string>()); logFileName = filesLocation + "/ga_execute.log"; } if (variablesMap.count("genetic-algo")) { std::string filesLocation(variablesMap["genetic-algo"].as<std::string>()); logFileName = filesLocation + "/genetic-algo.log"; } Logger::Initialise(logFileName); if (variablesMap.count("help")) { std::cout << desc << std::endl; return 0; } if (variablesMap.count("genetic-algo")) { zmq::context_t zmqContext(1); GridGALib::GeneticAlgo geneticAlgo(variablesMap["genetic-algo"].as<std::string>(), zmqContext); if (!geneticAlgo.ReadConfig()) { return 1; } geneticAlgo.Evolve(); return 0; } //if (variablesMap.count("test-send")) //{ // DeepThoughtLib::AppContext appContext; // appContext.TransmitTestData(); // std::cerr << "finished" << std::endl; // return 0; //} //if (variablesMap.count("test-receive")) //{ // zmq::context_t zmqContext(1); // DeepThoughtLib::GeneticAlgo geneticAlgo(false, "", zmqContext); // std::deque<DeepThoughtLib::GenomePtr> genomesToTest; // geneticAlgo.WaitForResults(genomesToTest); // return 0; //} if (variablesMap.count("execute")) { std::string filesLocation = variablesMap["execute"].as<std::string>(); if (!boost::filesystem::exists(filesLocation)) { std::cerr << "Cannot find location \"" << filesLocation << "\"" << std::endl; return -1; } //DeepThoughtLib::AppContext appContext; //appContext.Backtest(filesLocation); return 0; } std::cout << desc << std::endl; return 0; }