typora关闭文件保存后,总是自己产生一个log的文件,看着都烦,以前是不会自己产生的,后来有一次没保存断电后,每次使用都自己产生一个log文件,看着都烦,删除对源文件没有影响,怎么才能让它不再产生?

typora关闭文件保存后,总是自己产生一个log的文件,看着都烦,以前是不会自己产生的,后来有一次没保存断电后,每次使用都自己产生一个log文件,看着都烦,删除对源文件没有影响,怎么才能让它不再产生?

引自免费微信小程序:皆我百晓生
在Typora编辑器中,创建并关闭特定日志文件的一个基本步骤包括以下几个部分:
新建和打开一个新的或现有的log.txt文件:
touch log.txt
If you have a file named log.txt in your current directory, you can open it by navigating to the location of the file using the cd command (e.g., cd /path/to/log.txt) and then typing open followed by the filename:
open log.txt
Alternatively, if you want to create a new file, type:
touch typora.log
设置LogfileHandler类的属性:
class LogFileHandler : public std::basic_filebuf<FILE> {
// Add custom logging functionality here
public:
void log(const std::string& message) override {
boost::system::error_code ec;
write_to_file(message, ec);
if (!ec.empty()) {
printf("Error writing to %s\n", ec.message().c_str());
return;
}
std::cout << message << std::endl;
}
};
Here, we are overriding the log method provided by std::basic_filebuf. The write_to_file function is responsible for writing the message to the log.txt file.
Open the Typora editor:
Once you've set up the LogFileHandler, you can open Typora by either clicking on "File" > "New Document" or pressing Ctrl + N (Ctrl + N for Windows and Linux, Cmd + N for macOS) on your keyboard. Alternatively, you can search for "Typora" in your Applications folder and launch the application from there.
Add Markdown files:
Inside the Typora project, create markdown files for each relevant section you want to include in your log. You'll typically find these files within the respective directories, such as C++/src or C++/tests, which correspond to the source code or test cases.
For example, let's say you have two markdown files called C++/src/README.md and C++/src/testcase.md, both with a common heading "Introduction". To include this log entry into the global log file, modify the following lines in the C++/src/main.cpp file:
// ...
if (fopen(log_file_path.c_str(), "a")) {
FILE *log_file = fopen(log_file_path.c_str(), "w");
if (!log_file) {
perror("Failed to open log file.");
fclose(log_file);
return;
}
fprintf(log_file, "%s\n", "Description of C++ src.\n");
// ...
fclose(log_file);
} else {
printf("Error opening log file.\n");
}
Here, we first open the existing log.txt file using fstream:: fopen, specifying "a" mode for appending content to the file. Then, we use fprintf to write the log message to the log file. We concatenate the description of the C++ src with a newline character to separate the sections.
Save the file:
After writing the log entry, save the file to the log.txt file using fclose.
fclose(log_file);
Close the Typora editor:
Finally, close the Typora editor window by clicking on "File" > "Close All Documents" or pressing Ctrl + X (Ctrl + X for Windows and Linux, Cmd + X for macOS).
Here's a simplified outline of the steps that may not be necessary depending on the specific requirements of your log file structure:
.log.txt file in the same directory as your .md files.log_file_path variable is empty.fprintf function to log the message with any additional information or context needed for troubleshooting or performance monitoring.log.txt file has been successfully created by running the ls command with the --color=always option to view the contents of the file in color:
ls --color=always log.txt
log.txt file doesn't contain any duplicate entries by comparing its contents with the generated log file using the cat command:
cat log.txt
This process will allow you to customize the way LogFileHandler handles different types of logs, including log.txt files generated by Typora. Note that the exact implementation will depend on the structure of your log file, so make sure to adapt the code accordingly.