Show
Ignore:
Timestamp:
05/20/08 22:13:47 (5 years ago)
Author:
hio
Message:

Log::Channel, 自動でチャンネル別にログを保存できるように.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/tiarra/trunk/module/Log/Channel.pm

    r11365 r12068  
    1717use Multicast; 
    1818 
     19our $DEFAULT_FILENAME_ENCODING = $^O eq 'MSWin32' ? 'sjis' : 'utf8'; 
     20 
    1921sub new { 
    2022    my $class = shift; 
     
    180182            # マッチした。 
    181183            my $fname_format = $this->config->filename || '%Y.%m.%d.txt'; 
    182             my $fpath_format = $ch->[0]."/$fname_format"; 
     184            # あまり好ましくなさそうな文字はあらかじめエスケープ. 
     185            my $chan_filename = $channel; 
     186            $chan_filename =~ s/![0-9A-Z]{5}/!/; 
     187            $chan_filename =~ s{([^-\w@#%!+&.\x80-\xff])}{ 
     188              sprintf('=%02x', unpack("C", $1)); 
     189            }ge; 
     190            my $chan_dir = Auto::AliasDB->shared->replace(undef, $ch->[0], channel => $chan_filename); 
     191            my $fpath_format = "$chan_dir/$fname_format"; 
    183192 
    184193            $this->{matching_cache}->{$channel} = $fpath_format; 
     
    211220        } 
    212221    }; 
     222    my $filename_encoding = $this->config->filename_encoding || $DEFAULT_FILENAME_ENCODING; 
     223    if( $filename_encoding ne 'ascii' ) 
     224    { 
     225      $concrete_fpath = Tiarra::Encoding->new($concrete_fpath)->conv($filename_encoding); 
     226    }else 
     227    { 
     228      $concrete_fpath =~ s/([^ -~])/sprintf('=%02x', unpack("C", $1))/ge; 
     229    } 
    213230    my $header = Tools::DateConvert::replace( 
    214231        $this->config->header || '%H:%M' 
     
    384401# この例では、#IRC談話室@ircnetのログはIRCDanwasitu/%Y.%m.%d.txtに、 
    385402# それ以外(privも含む)のログはothers/%Y.%m.%d.txtに保存される。 
     403# #(channel) はチャンネル名に展開される。 
     404# (古いバージョンだと展開されずにそのままディレクトリ名になってしまいます。) 
    386405channel: priv priv 
    387 channel: others * 
     406channel: #(channel) * 
     407-channel: others * 
     408 
     409# ファイル名のエンコーディング. 
     410# 指定可能な値は, utf8, sjis, euc, jis, ascii. 
     411# ascii は実際には utf8 と同等で8bit部分が全てquoted-printableされる. 
     412# デフォルトはWindowsではsjis, それ以外では utf8. 
     413-filename-encoding: utf8 
     414 
    388415=cut