package log; # $Id: log.pm,v 1.16 2002/01/29 22:38:31 gc Exp $



use c;





my $logOpen = 0;
my $logDebugMessages = 0;





sub F() { *LOG }

sub l {
    $logOpen or openLog();
    if ($::isStandalone) {
	c::syslog(c::LOG_WARNING(), join("", @_));
    } elsif ($::isInstall) {
	print LOG "* ", @_, "\n";
	print LOG2 "* ", @_, "\n";
    } else {
	print STDERR @_, "\n";
    }
}
sub ld { $logDebugMessages and &l }
sub w { &l }

sub openLog(;$) {
    if ($::isInstall) {
	if ($_[0]) { 
	    open LOG, "> $_[0]";# or die "no log possible :(";
	} else {
	    open LOG, "> /dev/tty3";# or die "no log possible :(";
	}
	open LOG2, ">> /tmp/ddebug.log";# or die "no log possible :(";
	select((select(LOG),  $| = 1)[0]);
	select((select(LOG2), $| = 1)[0]);
    }
    exists $ENV{DEBUG} and $logDebugMessages = 1;
    $logOpen = 1;
}

sub closeLog() { 
    if ($::isStandalone) {
	c::closelog();
    } else { close LOG; close LOG2; }
}




1;
