MCPcopy Create free account
hub / github.com/PlatformLab/NanoLog / setLogFile_internal

Method setLogFile_internal

runtime/RuntimeLogger.cc:624–666  ·  view source on GitHub ↗

Documentation in NanoLog.h

Source from the content-addressed store, hash-verified

622
623// Documentation in NanoLog.h
624void
625RuntimeLogger::setLogFile_internal(const char *filename) {
626 // Check if it exists and is readable/writeable
627 if (access(filename, F_OK) == 0 && access(filename, R_OK | W_OK) != 0) {
628 std::string err = "Unable to read/write from new log file: ";
629 err.append(filename);
630 throw std::ios_base::failure(err);
631 }
632
633 // Try to open the file
634 int newFd = open(filename, NanoLogConfig::FILE_PARAMS, 0666);
635 if (newFd < 0) {
636 std::string err = "Unable to open file new log file: '";
637 err.append(filename);
638 err.append("': ");
639 err.append(strerror(errno));
640 throw std::ios_base::failure(err);
641 }
642
643 // Everything seems okay, stop the background thread and change files
644 sync();
645
646 // Stop the compression thread completely
647 {
648 std::lock_guard<std::mutex> lock(nanoLogSingleton.condMutex);
649 compressionThreadShouldExit = true;
650 workAdded.notify_all();
651 }
652
653 if (compressionThread.joinable())
654 compressionThread.join();
655
656 if (outputFd > 0)
657 close(outputFd);
658 outputFd = newFd;
659
660 // Relaunch thread
661 nextInvocationIndexToBePersisted = 0; // Reset the dictionary
662 compressionThreadShouldExit = false;
663#ifndef BENCHMARK_DISCARD_ENTRIES_AT_STAGINGBUFFER
664 compressionThread = std::thread(&RuntimeLogger::compressionThreadMain, this);
665#endif
666}
667
668/**
669* Set where the NanoLog should output its compressed log. If a previous

Callers 1

setLogFileMethod · 0.80

Calls 1

syncFunction · 0.85

Tested by

no test coverage detected