From: Stephen L Johnson Date: Tue, 14 Mar 2000 22:51:40 +0000 (+0000) Subject: coverted debug() and error() to using Spong::Log modules routines X-Git-Tag: spong-2_7-alpha5~33 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec057608299539e25a92675233ea74827b26e8a8;p=spong.git coverted debug() and error() to using Spong::Log modules routines --- diff --git a/src/spong-network.pl b/src/spong-network.pl index ad46e81..3cd967f 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -30,6 +30,7 @@ use Getopt::Long; use Spong::Daemon; use Spong::Status qw(status); +use Spong::Log; srand( time() ^ ($$ + ($$ << 15 )) ); @@ -42,13 +43,8 @@ if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart, exit 1; } -$debug = $debuglevel; - -#if( $ARGV[0] eq "--debug" ) { $debug = 1; shift; } -#if( $ARGV[0] eq "--restart" ) { $restart = 1; shift; } -#if( $ARGV[0] eq "--kill" ) { $kill = 1; shift; } -#if( $ARGV[0] eq "--nosleep" ) { $nosleep = 1; shift; } -#if( $ARGV[0] eq "--refresh" ) { $nosleep = 1; shift; } +# Initial debugging for preconfiguration debugging +Spong::Log::set_debug_context( 'debuglevel' => $debuglevel ); $me = "@@BINDIR@@/spong-network"; $conf_file = $ARGV[0] || "@@ETCDIR@@/spong.conf"; @@ -57,6 +53,7 @@ $hosts_file = "@@ETCDIR@@/spong.hosts"; $HOST =~ tr/A-Z/a-z/; &load_config_files(); # Loads the user specified configuration information +&init_logging(); # Initialize logging contexts Spong::Daemon::Daemonize() # Daemonize if not signalling or a one-shot unless ($nosleep || $restart || $kill || $debug ); &handle_signals(); # Set up handlers, and signal the current server if asked @@ -252,6 +249,27 @@ sub usage { } +# This function initializes the debug and error logging contexts in the +# Log module. + +sub init_logging { + if (defined $debuglevel) { + $debug = ($debuglevel == 0) ? 1 : $debuglevel + } + + Spong::Log::set_debug_context( 'debuglevel' => $debug ); + + my $filename = ($SPONG_LOG_FILE) ? "$SPONGTMP/spong-network.log" : ""; + my $syslog = ($SPONG_LOG_SYSLOG) ? 1 : 0; + + Spong::Log::set_error_context( syslog => $syslog, + ident => 'spong-network', + logopt => 'pid,cons', + priority => 'ERR', + filename => $filename, + ); +} + # Load our configuration variables, including anything specific to the host # that we are running on. @@ -333,8 +351,8 @@ sub handle_signals { # Output functions, one for debugging information, the other for errors. -sub debug { print scalar localtime, " ", $_[0], "\n" if $main::debug; } -sub error { warn scalar localtime(), " Error: ", $_[0], "\n"; } +sub debug { Spong::Log::debug($_[0],$_[1]); } +sub error { Spong::Log::error($_[0]); } # Handle some signals...