0

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'}) {
    # ...
    # ...
}
sid_com
  • 24,137
  • 26
  • 96
  • 187

1 Answers1

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.

bvr
  • 9,687
  • 22
  • 28
  • When I start the proxy-server with the config-file it works. Does this work, because IO::File and IO::Socket from Net::Daemon inherit from IO::Handle? – sid_com Mar 07 '11 at 14:15
  • @sid_com - both `IO::Handle` and `IO::File` are included in core package called `IO`. They are object interface for perl I/O subsystem. If you use IO::Handle/IO::File in any script, `open` will also return objects of this class. – bvr Mar 07 '11 at 15:01