将日志文件中的新数据追加到另一个文件中。
2015-7-27 6:29:9
收藏:0
阅读:123
评论:2
如何确定新数据是否写入日志文件以及如何提取这些新数据并将它们写入另一个文件?
我的目标是为了调试目的创建一个大的日志文件,因为当前的日志文件如果达到特定大小会删除数据。
我的唯一想法是每隔几分钟创建一个旧日志文件的副本。
点赞
用户3297834
另一个快速且不太正规的方法是执行以下操作:
cp /path/to/small_file.log /other/path/to/big_file.log;
nohup tail -f /path/to/small_file.log >> /other/path/to/big_file.log &
2015-11-30 14:31:10
评论区的留言会收到邮件通知哦~
推荐文章
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?
- addEventListener 返回 nil Lua
- Lua中获取用户配置主目录的跨平台方法
一种快速且简单的方式是在控制台中输入以下行 - 用实际路径和日志文件替换 "path/to/..." 和 "other/path/..." :
* * * * * /path/to/small_file.log >> /other/path/to/big_file.log它不会每次写入都执行IO,但它会每分钟执行一次,这可能足够,也可能不足够满足您的需求。
编辑:试图使用C找到更好的方法,以下是我目前的方法(请阅读帖子中的评论获取更多信息)。
//Include the full pathname and file for LOG_BIG and LOG_SMALL #define LOG_BIG "/var/.../log_example_big.txt" #define LOG_SMALL "/var/.../log_example_small.txt" //FIXME: change LOG_BIG and LOG_SMALL to match the locations of the logfiles #include <time.h> #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <math.h> #include <sys/types.h> time_t last_mod_time(const char *path); int main(int argc, const char * argv[]) { char outstr[200]; time_t t; struct tm *tmp; t = time(NULL); tmp = localtime(&t); // check for local time set failure if (tmp == NULL) { perror("localtime"); return 0; } //if the returned size_t for strftime is 0, we exit if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) { fprintf(stderr, "strftime returned 0"); return 0; } double diff_log_mod_time; // get the difference of last modified time between LOG_BIG and LOG_SMALL diff_log_mod_time = difftime(last_mod_time(LOG_BIG),last_mod_time(LOG_SMALL)); //difference in log modification times should be close to 0 +/- 10 ... I think if(fabs(diff_log_mod_time) > 10.0) { /* to finish the code, we would need to find the difference between the data in LOG_BIG and LOG_SMALL (assuming that LOG_BIG should contain all of LOG_SMALL and then some) */ } exit(EXIT_SUCCESS); } /** * last_mod_time - this function finds the last modification time for a filename specified and returns * it in epoch time (seconds lapsed since 1/1/1970) */ time_t last_mod_time(const char *path) { struct stat statbuf; if (stat(path, &statbuf) == -1) { perror(path); exit(1); } return statbuf.st_mtime; }