1

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

  • *"Can't locate object method "SetFormatter" via package "Wx::LogTextCtrl" at MyFrame1.pm line 41"*: Thanks for the update. What is on line 41 in your `MyFrame1.pm`? Is it this line: `$log->SetFormatter($log_format)` ? – Håkon Hægland Apr 16 '20 at 09:19
  • Yes Hakon. On Line 41 in my MyFrame.pm, I am calling method SetFormatter of Wx::LogTextCtrl to set custom Log formatter. – Sahil.Aggarwal Apr 16 '20 at 10:53
  • I have searched trough [the code](https://metacpan.org/release/Wx/source) but I could find any mention of a method called `SetFormatter()`, so maybe it has not been added to the module yet? You could submit an issue at the [bug tracker](https://rt.cpan.org/Public/Dist/Display.html?Name=Wx) or maybe try add it yourself since [the method seems to already exists](https://docs.wxwidgets.org/3.0/classwx_log.html#a9f316422df6930c549db80a5e4bf36a2) in the C++ library – Håkon Hægland Apr 16 '20 at 13:09

0 Answers0