I am using wxperl(version .9932) for GUI interface in my console Application. I want to use a custom log formatter, and for this derived a class from 'Wx::PlLogFormatter' and override format subroutine in the derived class. this perl package Wx::PlLogFormatter is defined in log.xs file with new and destroy Xsubs.
MODULE=Wx PACKAGE=Wx::PlLogFormatter
wxPlLogFormatter*
wxPlLogFormatter::new()
CODE:
RETVAL = new wxPlLogFormatter( CLASS );
OUTPUT: RETVAL
void
wxPlLogFormatter::Destroy()
CODE:
delete THIS;
According to wxwidget manual page, we can set the custom log formatter using Setformatter method of WxLog class.
https://docs.wxwidgets.org/3.0/classwx_log.html https://docs.wxwidgets.org/3.0/classwx_log_formatter.html
But when I use SetFormatter method with an object of Wx::LogTextCtrl, it is giving me below error
Can't locate object method "SetFormatter" via package "Wx::LogTextCtrl" at MyFrame1.pm line 41.
This is I am using in my my Frame class to create a Log target object Wx::LogTextCtrl
$self->{txtctrl} = Wx::TextCtrl->new($panel,-1,'',[-1,-1],[400,300],wxTE_RICH | wxTE_MULTILINE);
Wx::Log::EnableLogging(1);
my $log =Wx::LogTextCtrl->new( $self->{txtctrl} );
Wx::Log::SetActiveTarget($log);
my $log_format = customLogFormat->new();
$log->SetFormatter($log_format);
my $string = 'frame has been created';
Wx::LogMessage("%s",$string);
and below is my custom Log formatter class
package customLogFormat;
no strict;
use warnings;
use Wx qw(:everything);
use base 'Wx::PlLogFormatter';
sub new {
my $class = shift;
my $self = $class->SUPER::new();
print "$self";
return $self;
}
sub Format {
my ($self,$level,$msg, $log_record)= @_;
my $string = "$level" . "$msg";
return $string;
}
1;
According to Wxwidget manual, derive a class from WxLogFormatter class and override its format method to create a custom Log formatter and use Wx::Log::SetFormatter() method with WxLog target object.
Do we have any method to use custom log formatter in wxperl ?
thanks