Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Perl DBI::ProxyServer:写入日志文件时出现问题_Perl_Logging_Proxy_Dbi - Fatal编程技术网

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

Perl DBI::ProxyServer:写入日志文件时出现问题,perl,logging,proxy,dbi,Perl,Logging,Proxy,Dbi,使用启动proxyserver时 或与 dbiproxy --configfile dbiproxy.config 除了写日志文件,一切都正常。 我的dbiproxy配置文件: { 'logfile' => 'C:\WINDOWS\temp\dbiproxy.log', 'localport' => '2000', 'debug' => 1, } 我传递了一个文件名,但需要一个文件句柄。 代码不正确还是我遗漏了什么 # Net/Daemo

使用启动proxyserver时

或与

dbiproxy --configfile dbiproxy.config
除了写日志文件,一切都正常。
我的dbiproxy配置文件:

{ 'logfile'     => 'C:\WINDOWS\temp\dbiproxy.log',
  'localport'   => '2000',
  'debug'       => 1,   }
我传递了一个文件名,但需要一个文件句柄。
代码不正确还是我遗漏了什么

# 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'}) {
    # ...
    # ...
}
#Net/Daemon.pm
子ReadConfigFile{
我的($self、$file、$options、$args)=@;
# ...   
my$copts=do$file;
# ...
#使用配置文件选项覆盖当前配置。
而(我的($var,$val)=每个%$copts){
$self->{$var}=$val;
}
}
子新建($$;$){
我的($class,$attr,$args)=@;
my($self)=$attr?\%$attr:{};
祝福($self,(ref($class)| |$class));
我的$options=($self->{'options'}我的$options={});
# ...
# ...
my$file=$options->{'configfile'}| |$self->{'configfile'};
如果($file){
$self->ReadConfigFile($file,$options,$args);
}
而(我的($var,$val)=每个%$选项){
$self->{$var}=$val;
}
# ...
# ...
$self;
}
#Net/Daemon/Log.pm
子OpenLog($){
我的$self=shift;
返回1,除非参考($self);
如果定义了$self->{'logfile'},则返回$self->{'logfile'};
# ...
# ...
}
子日志($$;@){
我的($self,$level,$format,@args)=@;
我的$logfile=!ref($self)|$self->OpenLog();
# ...
# ...
如果($logfile){
my$logtime=$self->logtime();
#把球投进去怎么样

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

进入你的dbiproxy配置文件?我没有办法测试它,但根据文档,它应该能工作。

当我用配置文件启动代理服务器时,它能工作。这能工作吗,因为来自Net::Daemon的IO::file和IO::Socket继承自IO::Handle?@sid_com-内核中包括
IO::Handle
IO::file
名为
IO
的包。它们是perl I/O子系统的对象接口。如果在任何脚本中使用IO::Handle/IO::File,
open
也将返回此类的对象。
'logfile' => IO::File->new('C:\WINDOWS\temp\dbiproxy.log', 'a'),