DBI::ProxyServer: Problem with writing a log-file

三世轮回 提交于 2019-12-11 16:54:28

问题


When starting the proxyserver (DBI::ProxyServer) with

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

or with

dbiproxy --configfile dbiproxy.config

everything works, except the writing of a logfile.
My dbiproxy config file:

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

I pass a filename, but the Net::Daemon::Log needs a filehandle.
Is the code not OK or have I missed something?

# 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:


What about putting

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

into your dbiproxy config file? I don't have a way how to test it, but according to Net::Daemon::Log docs it should work.



来源:https://stackoverflow.com/questions/5219859/dbiproxyserver-problem-with-writing-a-log-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!