typora关闭文件保存后,总是自己产生一个log的文件,看着都烦,以前是不会自己产生的,后来有一次没保存断电后,每次使用都自己产生一个log文件,看着都烦,删除对源文件没有影响,怎么才能让它不再产生?
3条回答 默认 最新
- 专家-皆知 2024-03-28 16:01关注
引自免费微信小程序:皆我百晓生
在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 thecd
command (e.g.,cd /path/to/log.txt
) and then typingopen
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 bystd::basic_filebuf
. Thewrite_to_file
function is responsible for writing the message to thelog.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
orC++/tests
, which correspond to the source code or test cases. For example, let's say you have two markdown files calledC++/src/README.md
andC++/src/testcase.md
, both with a common heading "Introduction". To include this log entry into the global log file, modify the following lines in theC++/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 usingfstream:: fopen
, specifying "a" mode for appending content to the file. Then, we usefprintf
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 usingfclose
.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:
- Create a new or existing
.log.txt
file in the same directory as your.md
files. - Set up a LogFileHandler object with appropriate properties for your markdown files.
- Open the Typora editor and navigate to the desired file directory.
- Add a markdown file with a header describing the C++ src.
- Modify the main function of your selected source code file or test case to log an error or warning if the
log_file_path
variable is empty. - Use the
fprintf
function to log the message with any additional information or context needed for troubleshooting or performance monitoring. - Save the file and close the editor window.
- Check if the
log.txt
file has been successfully created by running thels
command with the--color=always
option to view the contents of the file in color:ls --color=always log.txt
- Ensure that the existing
log.txt
file doesn't contain any duplicate entries by comparing its contents with the generated log file using thecat
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.解决 无用评论 打赏 举报 编辑记录 -
悬赏问题
- ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
- ¥15 孟德尔随机化怎样画共定位分析图
- ¥18 模拟电路问题解答有偿速度
- ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
- ¥15 误删注册表文件致win10无法开启
- ¥15 请问在阿里云服务器中怎么利用数据库制作网站
- ¥60 ESP32怎么烧录自启动程序
- ¥50 html2canvas超出滚动条不显示
- ¥15 java业务性能问题求解(sql,业务设计相关)
- ¥15 52810 尾椎c三个a 写蓝牙地址