newlisp按行处理日志文件
来源:互联网 发布:算法导论视频 编辑:程序博客网 时间:2024/05/27 10:43
newlisp提供了很多的文件处理函数,由于网络等原因。传递失败的消息可以暂时缓存在本地,为较少原程序的负担,可以利用newlisp脚本做容错处理,将这些失败的消息再次传递到接收端。
日志文件格式是一条消息一行。
newlisp代码如下:
#!/usr/bin/newlisp(set 'rest-url "http://localhost/collect")(set 'dir "/home/file/log_file/")(set 'cmd (string "ls " dir))(println "cmd: " cmd)(set 'file (exec cmd))(define (post-msg msg) (set 'res (post-url rest-url msg "application/x-www-form-urlencoded" 100000)) (println "res: " res ) (unless (find "ERR: HTTP document empty" res) ;;write a new file when error occur (append-file (string file-path ".bk") (append msg "\n")) ) )(define (parse-file file-name) (set 'file-path (string dir file-name)) (println file-path) (set 'f (open file-path "read")) (while (read-line f) (set 'msg (current-line)) (println "msg: " msg) (post-msg msg) ))(dolist (file-name file) (parse-file file-name) ;;delete file after all lines processed (delete-file file-path))(exit)程序主要用到的文件函数包括read-line和current-line。从dolist开始,其中file是遍历文件目录下得到的所有消息文件,parse-file函数是对其中一个消息文件逐行读取,并通过post-msg函数传递给接收端的api. post-msg中的unless表名如果没有传递成功,会把失败的消息再次写到一个新的文件,等到下此运行脚本会再次传递。
0 0
- newlisp按行处理日志文件
- newLISP文件合并
- newLISP处理mysql escape character
- newlisp文件作为脚本运行
- newlisp读取文件性能测试
- Go1.9按行读取日志文件并处理
- 用newLisp开发网站五 日志
- -------日志文件的处理---------
- 日志文件的处理
- 数据库日志文件处理办法
- SQLServer 日志文件处理办法
- 用脚本处理日志文件
- 日志文件过大 处理方法
- oracle10g日志文件丢失处理!
- apache 日志文件 处理方法
- 数据库日志文件超出处理
- 异常处理&创建日志文件
- 关于SQL2008日志文件处理
- Swift字典
- Qt样式表参考(三)
- css 图片文字居中对齐方案
- HTML5本地存储之Database Storage篇
- 打开log日志
- newlisp按行处理日志文件
- 初识gennerator-bee
- 小强的HTML5移动开发之路(18)——HTML5地理定位
- iOS相册实现与AssetsLibrary框架使用
- 【Wordpress】以修改文章页面single.php下的评论栏说明一些Wordpress的函数与页面
- Core Animation系列之CADisplayLink
- spark读取hdfs数据本地性异常
- iOS开发之NSString
- Android Studio.Duplicate files copied in APK META-INF/notice.txt