DBI :: ProxyServer:编写日志文件时出现问题

时间:2011-03-07 12:43:06

标签: perl logging proxy dbi

使用

启动代理服务器(DBI::ProxyServer)
dbiproxy --logfile C:\WINDOWS\temp\dbiproxy.log --debug 1 --localport 2000

dbiproxy --configfile dbiproxy.config

除了写日志文件外,一切正常 我的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 个答案:

答案 0 :(得分:1)

如何放

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

进入你的dbiproxy配置文件?我没有办法测试它,但根据Net::Daemon::Log文档,它应该有效。