My application displays the content of a log file into a TextField using Win32::GUI.
The number of lines displayed is set inside a config file and I want to reload the file when the user click a menu item "Reload Config" and to reset the maximum number of line to display.
For test purpose I disabled all threads and process that are creating a lot of logs and I just printed the value of my variable.
When I close the application I can see the variable value correctly updated. Can somebody give me a hint?
Thanks a lot in advance!
==========================================================
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};
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.