我在控制台应用程序中使用 wxperl(版本 .9932)作为 GUI 界面。我想使用自定义日志格式化程序,为此从“Wx::PlLogFormatter”派生一个类并覆盖派生类中的格式子例程。这个 perl 包 Wx::PlLogFormatter 在 log.xs 文件中定义,带有 new 和 destroy Xsubs。
MODULE=Wx PACKAGE=Wx::PlLogFormatter
wxPlLogFormatter*
wxPlLogFormatter::new()
CODE:
RETVAL = new wxPlLogFormatter( CLASS );
OUTPUT: RETVAL
void
wxPlLogFormatter::Destroy()
CODE:
delete THIS;
根据 wxwidget 手册页,我们可以使用 WxLog 类的 Setformatter 方法设置自定义日志格式化程序。
https://docs.wxwidgets.org/3.0/classwx_log.html https://docs.wxwidgets.org/3.0/classwx_log_formatter.html
但是当我将 SetFormatter 方法与 Wx::LogTextCtrl 的对象一起使用时,它给了我以下错误
无法通过 MyFrame1.pm 第 41 行的包“Wx::LogTextCtrl”找到对象方法“SetFormatter”。
这是我在我的 Frame 类中用来创建 Log 目标对象 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);
下面是我的自定义日志格式化程序类
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;
根据 Wxwidget 手册,从 WxLogFormatter 类派生一个类并覆盖其格式方法以创建自定义 Log 格式化程序,并将 Wx::Log::SetFormatter() 方法与 WxLog 目标对象一起使用。
我们有什么方法可以在 wxperl 中使用自定义日志格式化程序吗?
谢谢