POEセッション内でデータの中身が見たいときに、無理やりソースの中でprint STDERR $hogehoge;
とかってやっていたんだけど不格好なのでちゃんと調べてみた。
cpanで検索してみた限りだとPOE::Component::LoggerやPOE::Component::SimpleLog,POE::Component::Log4perlあたりを使うっぽい。
とりあえずマニュアルを見た感じPOE::Component::Loggerが分かりやすかったので、コレを使ってロギングすることにした。以下自己流概要。
use POE qw(Component::Server::TCP Component::Logger Sugar::Args); POE::Component::Logger->spawn( ConfigFile => 'conf/controller_server_log.conf', ); POE::Component::Server::TCP->new( Port => 50000, (略) ); POE::Kernel->run;
conf/controller_server_log.conf
# logs to screen (STDERR) dispatchers = screen [screen] class = Log::Dispatch::Screen min_level = info stderr = 1 format = %d %m %n
あとは使いたい箇所でLogger->log($debug_message);とかってやれば画面にログを掃き出してくれる。
上記の書式設定だと
Wed Oct 10 20:06:00 2007 client conneted -> 192.168.1.8
Wed Oct 10 20:06:00 2007 send_data : island_registration:50000,50001,3000
Wed Oct 10 20:06:00 2007 client disconneted <- 192.168.1.8
みたいな感じで掃き出してくれる。