fredo2906 has asked for the wisdom of the Perl Monks concerning the following question:
My code is something like that : # Init my variables my $liveview_max_line; # Load the configuration file load_cfg("myconf.cfg"); # Let's create the logger my $log_conf = q( log4perl.category = ALL,Logfile log4perl.appender.Logfile.filename = sub { return get_log_fn(); } log4perl.appender.Logfile.mode = append log4perl.appender.Logfile = Log::Dispatch::FileRotate log4perl.appender.Logfile.max = sub { return get_max_file( +); } log4perl.appender.Logfile.size = sub { return get_max_file +_size(); } log4perl.appender.Logfile.DatePattern = yyyy-MM-dd log4perl.appender.Logfile.TZ = PST log4perl.appender.Logfile.layout = PatternLayout log4perl.appender.Logfile.layout.ConversionPattern = %m %n ); Log::Log4perl::init( \$log_conf ); my $logger = Log::Log4perl::get_logger(); # Make Menu my $Menu = Win32::GUI::MakeMenu( " &?" => { -name => "Help", -enabled => 1 }, " > &Reload" => { -name => "Reload", -onClick => \ +&gw_OnClick }, ); ... other items added here # Create Textfield for Edit Text $mw->AddTextfield( -name => "Edit", -pos => [0, 0], -size => [100, 100], -multiline => 1, -hscroll => 1, -vscroll => 1, -autohscroll => 1, -autovscroll => 1, -keepselection => 1 , -font => $EditFont, -readonly => 1, ); ... build the gui and show the main window with Win32::GUI::Dialog(); #Functions sub gw_OnClick { load_cfg("myconf.cfg"); log2file(2,"Configuration Reloaded"); 0; } sub log2file { my $lvl=shift; my $msg=shift; my ($epochseconds, $microseconds) = gettimeofday; my ($second, $minute, $hour,$d,$m,$y) = localtime($epochseconds); my $time= sprintf("%02d/%02d/%04d %02d:%02d:%02d.%03.3s", $d,($m+1), + ($y+1900), $hour, $minute, $second, $microseconds); my $txt=""; #Use the log 4 perl module. $txt = $time." - ERROR - ".$msg if ($lvl == 0); $txt = $time." - WARN - ".$msg if ($lvl == 1); $txt = $time." - INFO - ".$msg if ($lvl == 2); $logger->error($txt) if ($lvl == 0); $logger->warn($txt) if ($lvl == 1); $logger->info($txt) if ($lvl == 2); update_text($txt); return 1; } sub update_text { my $txt = shift; print "$liveview_max_line\n"; if (exists $mw->{Edit}){ if ($mw->Edit->GetLineCount() >= $liveview_max_line) { my $NewText = $mw->Edit->Text; $NewText =~ s/.*\n//; $mw->Edit->Text($NewText); $mw->Edit->EmptyUndoBuffer(); $mw->Edit->Modify(0); $mw->Edit->SetFocus(); } } $mw->Edit->Clear() if exists $mw->{Edit}; $mw->Edit->Append("$txt\r\n") if exists $mw->{Edit}; }
|
|---|