Você está na página 1de 3

use XML::Simple;

use Data::Dumper;
use HTTP::Cookies;
use LWP::Debug qw(+);
use FileHandle;
use File::stat;
#use Switch;
use List::Compare;
use Term::ReadKey;
use IO::Handle qw( );
use POSIX qw(:signal_h :errno_h :sys_wait_h);
use Log::Log4perl qw(:easy);
# Logging (mode=write|append)
my $log_conf = q/
#log4perl.category = INFO, Logfile, Screen
log4perl.category = INFO, Logfile
log4perl.appender.Logfile = Log::Log4perl::Appender::File
log4perl.appender.Logfile.filename = test.log
log4perl.appender.Logfile.mode = write
log4perl.appender.Logfile.stderr = 1
log4perl.appender.Logfile.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Logfile.layout.ConversionPattern = %d %p> %m%n
log4perl.appender.Screen
= Log::Log4perl::Appender::Screen
log4perl.appender.Screen.stderr = 1
log4perl.appender.Screen.layout = Log::Log4perl::Layout::PatternLayout
log4perl.appender.Screen.layout.ConversionPattern = %d %p> %m%n
log4perl.logger.main = INFO
#log4perl.logger.Hob.Inventory = INFO
#log4perl.logger.Hob.GetWishlist = INFO
#log4perl.logger.Hob.Harvester = INFO
#log4perl.logger.Hob.Harvester.Anna = INFO
#log4perl.logger.Hob.Harvester.Petra = DEBUG
#log4perl.logger.Hob.Harvester.Ludmilla = INFO
/;
# Create Singleton-Object here
Log::Log4perl::init( \$log_conf );
# Logging ready
my $logger = Log::Log4perl::get_logger("main");
#$logger->info("\n\n");
$logger->info("*****************************************************************
**********");
use sigtrap qw{handler sigHandler normal-signals error-signals};
sub sigHandler {
my $sig = shift;
$sig = defined $sig ? $sig : "????";
if ($sig eq "INT")
{
print STDERR "\n\n^C: interrupted by user: starting exit sequence...\n";
print STDERR "Cleaning up... ";
$logger->info("\n\n");
$logger->info("In sigHandler(): ^C: interrupted by user: starting exit seq
uence...");
my $f_diff = main->check_list(1, 1);

}
sleep 1;
print STDERR "done.\n\n";
$logger->info("In sigHandler(): Cleaning up...done.");
}
else
{
print STDERR "\n\nOops, abnormal signal caught: $sig. Program aborted.\n";
$logger->info("\n\n");
$logger->info("In sigHandler(): Oops, abnormal signal caught: $sig. Progra
m aborted");
}
$logger->info("\n\n");
$logger->info("**************************************************************
****************");
$logger->info("****************************** SESSION ENDS **************
****************");
$logger->info("**************************************************************
****************");
exit 0;
}
sub sigHandler1 {
my $sig = shift;
$sig = defined $sig ? $sig : "????";
if ($sig eq "INT")
{
print STDERR "\n\n^C: interrupted by user: starting exit sequence...\n";
print STDERR "Cleaning up... ";
$logger->info("\n\n");
$logger->info("In sigHandler(): ^C: interrupted by user: starting exit seq
uence...");
my $f_diff = main->check_list(1, 1);
}
sleep 1;
print STDERR "done.\n\n";
$logger->info("In sigHandler(): Cleaning up...done.");
}
else
{
print STDERR "\n\nOops, abnormal signal caught: $sig. Program aborted.\n";
$logger->info("\n\n");
$logger->info("In sigHandler(): Oops, abnormal signal caught: $sig. Progra
m aborted");
}
exit 0;
}
sub sigHandler2 {
my $sig = shift;
$sig = defined $sig ? $sig : "????";
if ($sig eq "INT")
{
print STDERR "\n\n^C: interrupted by user: starting exit sequence...\n";
print STDERR "Cleaning up... ";
$logger->info("\n\n");
$logger->info("In sigHandler(): ^C: interrupted by user: starting exit seq

uence...");
}
sleep 1;
print STDERR "done.\n\n";
$logger->info("In sigHandler(): Cleaning up...done.");
}
else
{
print STDERR "\n\nOops, abnormal signal caught: $sig. Program aborted.\n";
$logger->info("\n\n");
$logger->info("In sigHandler(): Oops, abnormal signal caught: $sig. Progra
m aborted");
}
}
sub sigHandler3 {
my $sig = shift;
$sig = defined $sig ? $sig : "????";
if ($sig eq "INT")
{
print STDERR "\n\n^C: interrupted by user: starting exit sequence...\n";
print STDERR "Cleaning up... ";
$logger->info("\n\n");
$logger->info("In sigHandler(): ^C: interrupted by user: starting exit seq
uence...");
my $f_diff = main->check_list(1, 1);
}
sleep 1;
print STDERR "done.\n\n";
$logger->info("In sigHandler(): Cleaning up...done.");
}
else
{
print STDERR "\n\nOops, abnormal signal caught: $sig. Program aborted.\n";
$logger->info("\n\n");
$logger->info("In sigHandler(): Oops, abnormal signal caught: $sig. Progra
m aborted");
}
$logger->info("\n\n");
$logger->info("**************************************************************
****************");
$logger->info("****************************** SESSION ENDS **************
****************");
$logger->info("**************************************************************
****************");
exit 0;
}