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

发布于 2024-10-21 04:45:06 字数 2097 浏览 3 评论 0原文

启动代理服务器 (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'}) {
    # ...
    # ...
}

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'}) {
    # ...
    # ...
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

栖迟 2024-10-28 04:45:06

怎么样

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

将其放入 dbiproxy 配置文件 ?我没有办法测试它,但根据 Net: :Daemon::Log 文档它应该可以工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文