App::Rolling - 標準入力を世代管理されたファイルに書き出す

bayashi
2011-12-03

前置き


bayashi   App::Rolling 





何をするモジュール?


App::Rolling TCPApp::Rolling  roll 使


 
$ /usr/sbin/tcpdump | tee > /tmp/dump.log

roll `dump.log.1230` `dump.log.1231` `dump.log.1232` `dump.log.1233` `dump.log.1234` (5)
 
$ /usr/sbin/tcpdump | roll -t /tmp/dump.log



オプション



 
-f --file        書き出すファイルを指定します *必須*
-a --age         ローテートする世代数 [デフォルト:5]
-i --interval    1世代に書き出す時間(秒) [デフォルト:60]
-t --through     ファイルに書き出しつつ、標準出力にもアウトプットします
-nr --no-rotate  ローテートしません
-h --help        ヘルプを表示します
-v --version     バージョンを表示します

101180`-t`  dump STDIN 
 
$ /usr/sbin/tcpdump | roll -f /tmp/dump -a 10 -i 180 -t

 -f 

設定




 `~/.rolling/config` $ENV{'ROLLING_DIR'}  config 

config 
file: /tmp/roll.log
age: 3
interval: 180
through: 1

既知のバグ

書いてはみたものの、以下のようなバグがあります 、、orz

  • STDINにインターバルを超えて入力がない場合に、ローテートがうまくいかない
  • ファイル存在チェックのせいでパフォーマンスが悪い

TODO

今後、実装予定の機能。

  • インターバルで `-i 3m` (現状の書き方だと -i 180)とか書きたい
  • ファイルサイズでローテーション
  • 出力するファイルの先頭にタイムスタンプ
  • grep オプション

他にもこんなの欲しい!というのがあったら教えてください!

コマンドラインツールの書き方


 Module::Starter Getopt::Long  Pod::Usage 使

App::Cmd App::Cmd::Tester 使App::Rolling 



まとめ

App::Rolling というモジュールを紹介しました。関心を持っていただければ幸いです。