/** * All logging goes to the file. Stops syslog logging. * * @param logFilePath [in] - The path of the file to log to. * * @return bool - false if failed to open file. */ bool Logger::LogToFile(const char *logFilePath) { FILE *newFile; LogAutoLock lock(&m_settingsLock, LogAutoLock::Write); if (!logFilePath || !logFilePath[0]) { closeLogFile(); m_logFile = NULL; return true; } if (0 == m_logFilePath.compare(logFilePath)) return true; newFile = ::fopen(logFilePath, "a"); if (!newFile) { char buf[1024]; compat_strerror_r(errno, buf, sizeof(buf)); fprintf(stderr, "Failed to open logfile %s: %s\n", logFilePath, buf); return false; } closeLogFile(); m_logFile = newFile; m_logFilePath = logFilePath; return true; }
DWORD WINAPI workerThread(LPVOID lpParam) { int result = prepare(lpCmdLine); if (result == ERROR_ALREADY_EXISTS) { //HWND handle = getInstanceWindow(); //ShowWindow(handle, SW_SHOW); //SetForegroundWindow(handle); closeLogFile(); return 2; } if (result != TRUE) { signalError(); return 1; } DWORD exitCode = 0; if (!execute(FALSE, &exitCode)) { signalError(); return 1; } if(!stayAlive){ PostThreadMessage(mainThreadId, WM_QUIT, 0, 0); } return exitCode; }
void signalError() { DWORD err = GetLastError(); if (err) { LPVOID lpMsgBuf; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language (LPTSTR) &lpMsgBuf, 0, NULL); debug("Error:\t\t%s\n", (LPCTSTR) lpMsgBuf); strcat(errMsg, "\n\n"); strcat(errMsg, (LPCTSTR) lpMsgBuf); msgBox(errMsg); LocalFree(lpMsgBuf); } else { msgBox(errMsg); } if (*errUrl) { debug("Open URL:\t%s\n", errUrl); ShellExecute(NULL, "open", errUrl, NULL, NULL, SW_SHOWNORMAL); } closeLogFile(); }
// CmpErrLog::CmpErrLog() constructs a CmpErrLog object and // contains all of the calls that are necessary for logging // information about the current state of the compiler. CmpErrLog::CmpErrLog(const char *failureTxt, CollHeap *failedHeap, size_t size) : fp(0) { // If memory is allocated, then free it to give some extra memory // for logging. if (memPtr != NULL) { free(memPtr); memPtr = NULL; } // Create and lock the log file. openLogFile(); // If the log file was opened successfully, then write the // information to the log file. if (fp != NULL) { writeHeader(failureTxt, failedHeap, size); writeMemoryStats(); writeAllHeapInfo(failedHeap); writeCQDInfo(); writeQueryInfo(); writeStackTrace(); closeLogFile(); } }
void allowLog(const char* message) { if( openLogFile() ) { closeLogFile(); } }
void writeLog(const char *s, int length) { int forceBuffering = (dobuffering++ % 60) != 0; int restLength = commonInfo->maxLogBufferLength - commonInfo->logBufferLength; if (restLength < 512) forceBuffering = 0; if (commonInfo->inWriteLog || forceBuffering) { appendToLogBuffer(s, length); return; } commonInfo->inWriteLog++; if (!commonInfo->logKeepOpen) { openLogFile(); } flushLogBuffer(); if (sceIoWrite(commonInfo->logFd, s, length) < 0) { // Can't write to the log file right now, probably because the interrupts are disabled. // Save the log string for later output. appendToLogBuffer(s, length); } else { flushLogBuffer(); } if (!commonInfo->logKeepOpen) { closeLogFile(); } commonInfo->inWriteLog--; }
void writeLog(const char *s, int length) { if (commonInfo->inWriteLog) { appendToLogBuffer(s, length); return; } commonInfo->inWriteLog++; if (!commonInfo->logKeepOpen) { openLogFile(); } flushLogBuffer(); if (ioWrite(commonInfo->logFd, s, length) < 0) { // Can't write to the log file right now, probably because the interrupts are disabled. // Save the log string for later output. appendToLogBuffer(s, length); } else { flushLogBuffer(); } if (!commonInfo->logKeepOpen) { closeLogFile(); } commonInfo->inWriteLog--; }
/** * Helper method performing shutdown. */ void shutdown() { // stop main loop and all dependent components if (s_mainLoop != NULL) { delete s_mainLoop; s_mainLoop = NULL; } if (s_messageMap!=NULL) { delete s_messageMap; s_messageMap = NULL; } // free templates for (map<string, DataFieldTemplates*>::iterator it = templatesByPath.begin(); it != templatesByPath.end(); it++) { delete it->second; } templatesByPath.clear(); // reset all signal handlers to default signal(SIGHUP, SIG_DFL); signal(SIGINT, SIG_DFL); signal(SIGTERM, SIG_DFL); // delete daemon pid file if necessary closePidFile(); logNotice(lf_main, "ebusd stopped"); closeLogFile(); exit(EXIT_SUCCESS); }
void InstallScreen::cancelInstallation() { qDebug() << "cancelling installation"; closeLogFile(); m_ociHelper->killBackend(); // quit OCIHelper qApp->quit(); // quit OCI }
MainWindow::~MainWindow() { delete ui; closeLogFile(); //--usuń pliki tymczasowe }
void denyLog(const char* message) { if( openLogFile() ) { // writeEncDecLog(LOG_INFO, false, message); closeLogFile(); } }
void DevSW_SetLogEnable (int logEnableFlag) { if (logEnableFlag && !angelDebugLogFile) openLogFile (); else if (!logEnableFlag && angelDebugLogFile) closeLogFile (); angelDebugLogEnable = logEnableFlag; }
void errorLog(const char* message) { if( openLogFile() ) { char logBuf[256] = {'\0', }; sprintf(logBuf, "SYSLOG: %s", message); syslog(LOG_ERR, logBuf); closeLogFile(); } }
void destroyConfig(){ trace_safe("Function DestroyConfig"); lpfnLPSETUPDIOPENDEVREGKEY =0; lpfnSETUPDIGETCLASSDEVS =0; lpfnSETUPDIDESTROYDEVICEINFOLIST =0; lpfnSETUPDIENUMDEVICEINFO =0; FreeLibrary(libApiDLL); trace_safe("Closing Log and configfiles"); closeConfigFileSafe(); closeLogFile(); //WSACleanup(); }
BOOL MemHeapTerm(VOID) { if ( hp ) { return !(_uclose(hp) || _udestroy(hp, _FORCE) || DosSubUnsetMem(pbasemem) || DosFreeMem(pbasemem)); } /* endif */ closeLogFile(); return FALSE; }
// Final steps to run on haret shutdown. void shutdownHaret() { Output("Shutting down"); memPhysReset(); if(DeinitKMDriver()){ Output("Unloading kernel mode driver succeeded"); }else{ Output(C_ERROR "Unloading kernel mode driver FAILED"); } closeLogFile(); }
Logger::~Logger() { closeLogFile(); closeSyslog(); for (size_t i = 0; i < m_levelCount; ++i) delete[] m_levelsMap[i].types; delete[] m_levelsMap; delete[] m_types; if (pthread_rwlock_destroy(&m_settingsLock)) fprintf(stderr, "pthread_rwlock_destroy failed\n"); }
void reOpenFiles(){ DWORD l_pos;//first we check if HANDLE is valid DWORD l_err; l_pos = SetFilePointer(logFileHandle,0,0,FILE_CURRENT); if (l_pos ==INVALID_SET_FILE_POINTER) { //--attempt reopen faileL closeLogFile(); logFileHandle = CreateFile( logFile/*lpFileName*/, FILE_APPEND_DATA/*dwDesiredAccess*/, FILE_SHARE_READ/*dwShareMode*/, NULL /*lpSecurityAttributes*/, OPEN_ALWAYS/*dwCreationDisposition*/, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_SEQUENTIAL_SCAN/*dwFlagsAndAttributes*/, NULL/*hTemplateFile*/); if (logFileHandle == INVALID_HANDLE_VALUE){ printErrorMsg(_T("Could not open or create logfile, reason"),GetLastError(),0,1); destroyConfig(); exit(1); } } //we have a valid handle here for logfile trace(""); trace("Logfile opened"); l_pos = SetFilePointer(configFileHandle,0,0,FILE_CURRENT); if (l_pos ==INVALID_SET_FILE_POINTER) { //--attempt reopen faileL closeConfigFile();//do this anyway configFileHandle = CreateFile( configFile/*lpFileName*/, GENERIC_WRITE|GENERIC_READ/*dwDesiredAccess*/, FILE_SHARE_READ/*dwShareMode*/, NULL /*lpSecurityAttributes*/, OPEN_ALWAYS/*dwCreationDisposition*/, FILE_ATTRIBUTE_NORMAL/*dwFlagsAndAttributes*/, NULL/*hTemplateFile*/); if (configFileHandle == INVALID_HANDLE_VALUE){ trace("ERR:creating or opening the configuration file refused"); traceErrorMsg(configFile,_tcslen(configFile)*sizeof(TCHAR)); trace("ERR:...Check disk space or directory/file permissions"); printErrorMsg(_T("Could not open or create configfile, system error"),GetLastError(),1,1); destroyConfig(); exit(1); } } trace("Configuration file opened."); traceErrorMsg(configFile,_tcslen(configFile)*sizeof(TCHAR)); }
/* Function: mdlTerminate ================================================= * Abstract: * In this function, you should perform any actions that are necessary * at the termination of a simulation. */ static void mdlTerminate(SimStruct *S) { /* * Get access to Parameter/Input/Output/DWork/size information */ void *work1 = ssGetPWorkValue(S, 0); /* * Call the legacy code function */ closeLogFile( &work1); /* Update the PWorks */ ssSetPWorkValue(S, 0, work1); }
int main() { int k = 1; int *pointer = NULL; if( !initLog(INFO, "log_file.txt") ) { printf("Error with init log file\n"); return 0; } LOG(INFO, "This is log file"); LOG(INFO, "%s%d", "Value of var k is equal to ", k); if(!pointer) { LOG(ERROR, "Error: address of the pointer %p, its value is %p", &pointer, pointer); } closeLogFile(); return 0; }
void Logger::LogToSyslog(const char *ident, bool teeLogToStderr) { LogAutoLock lock(&m_settingsLock, LogAutoLock::Write); int opt = LOG_NDELAY; if (teeLogToStderr) opt |= LOG_PERROR; closeLogFile(); closeSyslog(); openlog(ident, opt, LOG_DAEMON); m_useSyslog = true; m_ident = ident; }
void closeSystemLog (void) { #if defined(HAVE_SYSLOG_H) if (syslogOpened) { closelog(); syslogOpened = 0; } #elif defined(WINDOWS) if (windowsEventLog != INVALID_HANDLE_VALUE) { DeregisterEventSource(windowsEventLog); windowsEventLog = INVALID_HANDLE_VALUE; } #elif defined(__MSDOS__) closeLogFile(); #endif /* close system log */ }
void DevSW_SetLogfile (const char *filename) { closeLogFile (); if (angelDebugFilename) { free (angelDebugFilename); angelDebugFilename = NULL; } if (filename && *filename) { angelDebugFilename = strdup (filename); if (angelDebugLogEnable) openLogFile (); } }
void safe_exit(int retVal) { if(restore) { if(tcsetattr(serialportFd, TCSANOW, &old) < 0) { perror("Couldn't restore term attributes"); exit(-1); } } printf("exiting...\n"); registerEvent("exit", ""); closeLogFile(); deleteTempFile(); lockfile_remove(); exit(retVal); }
void FileLogger::changePath(const QString &newPath) { QString tmpPath = Utils::Fs::fromNativePath(newPath); QDir dir(tmpPath); dir.mkpath(tmpPath); tmpPath = dir.absoluteFilePath("qbittorrent.log"); if (tmpPath != m_path) { m_path = tmpPath; if (m_logFile) { closeLogFile(); delete m_logFile; } m_logFile = new QFile(m_path); openLogFile(); } }
bool DebugManager::openLogFile(const UString &file) { closeLogFile(); _logFileStartLine = true; // Create the directories in the path, if necessary UString path = FilePath::canonicalize(file); try { FilePath::createDirectories(FilePath::getDirectory(path)); } catch (...) { return false; } if (!_logFile.open(path)) return false; logString(Version::getProjectNameVersionFull()); logString("\n"); return true; }
void FileLogger::addLogMessage(const Log::Msg &msg) { if (!m_logFile) return; QTextStream str(m_logFile); switch (msg.type) { case Log::INFO: str << "(I) "; break; case Log::WARNING: str << "(W) "; break; case Log::CRITICAL: str << "(C) "; break; default: str << "(N) "; } str << QDateTime::fromMSecsSinceEpoch(msg.timestamp).toString(Qt::ISODate) << " - " << msg.message << endl; if (m_backup && (m_logFile->size() >= m_maxSize)) { closeLogFile(); int counter = 0; QString backupLogFilename = m_path + ".bak"; while (QFile::exists(backupLogFilename)) { ++counter; backupLogFilename = m_path + ".bak" + QString::number(counter); } QFile::rename(m_path, backupLogFilename); openLogFile(); } else { m_flusher.start(); } }
void testSolver(void) { Coor c; int numMoves, numGroupsLeft, totalMoves; clock_t begin, end; openLogFile(); for (int searchDepth = 1; searchDepth <= 2; searchDepth++) { for (int strategy = 0; strategy < FINDMOVE_NUM_STRATEGIES; strategy++) { setStrategy(strategy); for (int i = 0; i < 30; i++) { begin = clock(); totalMoves = 0; Grid grid(20,10,5); while (!grid.isFinished()) { numMoves = grid.findPossibleMoves().size(); if (numMoves < 10) c = findBestMoveWithSearchDepth(grid, searchDepth); else c = findBestMoveWithSearchDepth(grid, 1); grid.makeMove(c); totalMoves++; grid.calculateGroups(); } numGroupsLeft = grid.getNumGroups(); end = clock(); writeOutput(strategy, searchDepth, numGroupsLeft, totalMoves, (double)(end-begin)/CLOCKS_PER_SEC); } } } closeLogFile(); }
void Output(const char *format, ...) { // Check for error indicator (eg, format starting with "<0>") int code = 7; if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { code = format[1] - '0'; format += 3; } // Format output string. char rawbuf[MAXOUTBUF]; va_list args; va_start(args, format); int rawlen = vsnprintf(rawbuf, sizeof(rawbuf) - PADOUTBUF, format, args); va_end(args); // Convert newline characters char buf[MAXOUTBUF]; int len = convertNL(buf, sizeof(buf), rawbuf, rawlen); openLogFile("\\kmode_dll.txt"); writeLog(buf, len); closeLogFile(); }
void ComponentCodeGen::runCodeGen(const std::string &logFile) { boost::filesystem::current_path(_directory); boost::filesystem::create_directory(_slname); printLog("create folder: "+_slname); std::string curr_workDir = _directory + "\\"+ _slname; boost::filesystem::current_path(curr_workDir); try { // Handle exceptions from filesystem::remove //remove existing files if( boost::filesystem::exists( curr_workDir ) ) { boost::filesystem::directory_iterator end; for(boost::filesystem::directory_iterator iter(curr_workDir) ; iter != end ; ++iter ) { if ( !boost::filesystem::is_directory( *iter ) ) { boost::filesystem::path fpath = iter->path(); boost::filesystem::remove(fpath); } } } } catch ( boost::filesystem::filesystem_error & e ) { string errmsg = "\nThe file system reported an error. Please check to see whether\nfiles in "; errmsg += "the generated code directory are open in other programs\nsuch as Visual Studio.\n\n"; errmsg += string(e.what() ); throw std::exception( errmsg.c_str() ); } // for(auto it=sfmodels.begin();it!=sfmodels.end();it++) { //CyPhyML::SignalFlowModel sfmodel = *it; //std::string sfname = sfmodel.name(); //printLog("******Start model transformation(SF_CodeGen) for SignalFlow model: "+sfname+"******"); closeLogFile(); runCyberSF_CodeGen_dllimported(_slmodel, "", CyberComposition::meta, logFile, curr_workDir); openLogFile(logFile, true); if(!runCyberSL_CodeGen(_slmodel,"", _slmodel.__impl()->__getdn(), curr_workDir)) setError(); logGeneratedFiles(curr_workDir); try { if( boost::filesystem::exists( curr_workDir ) ) { boost::filesystem::directory_iterator end; for(boost::filesystem::directory_iterator iter(curr_workDir) ; iter != end ; ++iter ) { if ( !boost::filesystem::is_directory( *iter ) ) { boost::filesystem::path fpath = iter->path(); boost::filesystem::path fpath_ext = fpath.extension(); std::string filepath_str = fpath_ext.string(); if(filepath_str == ".h") _hfiles.insert(fpath.string()); else if(filepath_str == ".c") { std::string fname = fpath.filename().string(); size_t slpos = fname.find("_fmu.c"); if(slpos==std::string::npos) _cfiles.insert(fpath.string()); } } } } } catch ( boost::filesystem::filesystem_error & e ) { string errmsg = "\nThe file system reported an error. Please check to see whether\nfiles in "; errmsg += "the generated code directory are open in other programs\nsuch as Visual Studio.\n\n"; errmsg += string(e.what() ); throw std::exception( errmsg.c_str() ); } } }