2011-03-07 34 views
0

DBI ::訪問代理服務器:問題寫一個日誌文件

dbiproxy --logfile C:\WINDOWS\temp\dbiproxy.log --debug 1 --localport 2000 

dbiproxy --configfile dbiproxy.config 

一切正常,除了一個日誌文件的寫入開始的訪問代理服務器(DBI::ProxyServer)
我dbiproxy配置文件:

{ 'logfile'  => 'C:\WINDOWS\temp\dbiproxy.log', 
    'localport' => '2000', 
    'debug'  => 1, } 

我傳一個文件名,但Net::Daemon::Log需要一個文件句柄。
代碼不正確或我錯過了什麼?

# Net/Daemon.pm 
sub ReadConfigFile { 
    my($self, $file, $options, $args) = @_; 
    # ... 
    my $copts = do $file; 
    # ... 
    # Override current configuration with config file options. 
    while (my($var, $val) = each %$copts) { 
    $self->{$var} = $val; 
    } 
} 
sub new ($$;$) { 
    my($class, $attr, $args) = @_; 
    my($self) = $attr ? \%$attr : {}; 
    bless($self, (ref($class) || $class)); 
    my $options = ($self->{'options'} ||= {}); 
    # ... 
    # ... 
    my $file = $options->{'configfile'} || $self->{'configfile'}; 
    if ($file) { 
    $self->ReadConfigFile($file, $options, $args); 
    } 
    while (my($var, $val) = each %$options) { 
    $self->{$var} = $val; 
    } 
    # ... 
    # ... 
    $self; 
} 

# Net/Daemon/Log.pm 
sub OpenLog($) { 
    my $self = shift; 
    return 1 unless ref($self); 
    return $self->{'logfile'} if defined($self->{'logfile'}); 
    # ... 
    # ... 
} 
sub Log ($$$;@) { 
    my($self, $level, $format, @args) = @_; 
    my $logfile = !ref($self) || $self->OpenLog(); 
    # ... 
    # ... 
    if ($logfile) { 
    my $logtime = $self->LogTime(); 
    # <- get this far, but don't pass the "ref($logfile)" 
    if (ref($logfile)) { 
     $logfile->print(sprintf("$logtime $level, $tid$format\n", @args)); 
    } else { 
     printf STDERR ("$logtime $level, $tid$format\n", @args); 
    } 
    } elsif (my $eventLog = $self->{'eventLog'}) { 
    # ... 
    # ... 
} 

回答

1

關於把

'logfile' => IO::File->new('C:\WINDOWS\temp\dbiproxy.log', 'a'), 

到您dbiproxy配置文件是什麼?我沒有辦法如何測試它,但根據Net::Daemon::Log文檔它應該工作。

+0

當我啓動代理服務器與配置文件它的作品。這是否工作,因爲Net :: Daemon中的IO :: File和IO :: Socket從IO :: Handle繼承? – 2011-03-07 14:15:54

+0

@sid_com - 'IO :: Handle'和'IO :: File'都包含在名爲'IO'的核心軟件包中。它們是perl I/O子系統的對象接口。如果在任何腳本中使用IO :: Handle/IO :: File,則open也會返回該類的對象。 – bvr 2011-03-07 15:01:57