首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何通过OutputDebugString登录Log4Perl

如何通过OutputDebugString登录Log4Perl
EN

Stack Overflow用户
提问于 2013-07-23 15:05:03
回答 1查看 178关注 0票数 1

是否可以使用Log4Perl将所有消息/级别直接登录到OutputDebugString (Windows )?

我有一些已经使用log4perl的模块,但是现在我想在一个所有日志消息都是OutputDebugStrings的环境中使用这些模块--在这个环境中,消息用DbgView读取,我想用DbgView读取模块的输出。我不想将Log4Perl日志文件与DbgView输出合并。

我使用以下Perl代码直接从perl编写OutputDebugStrings:

代码语言:javascript
复制
use Win32::API::OutputDebugString qw(OutputDebugString DStr);
OutputDebugString("Foo bar", "baz\n"); # sends  Foo barbaz\n to the debugger

我找到了log4net.Appender.OutputDebugStringAppender --如何在Perl上实现相同的功能?

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-25 12:32:45

====找到了一个====解决方案,多亏了达辛姆,我写了自己的附录。这是来源

使用以下代码-generate一个perl包

代码语言:javascript
复制
package Log4PerlOutputDebugStringAppender;

sub new {
   my($class, %options) = @_;
   my $self = { %options };
   bless $self, $class;
   return $self;
}

sub log {
   my($self, %params) = @_;
   use Win32::API::OutputDebugString qw(OutputDebugString DStr);
   OutputDebugString( "$params{message}" );
}

1;

使用以下内容-generate一个Log4Perl配置文件

代码语言:javascript
复制
log4perl.logger = INFO, OutputDebugString
log4perl.appender.OutputDebugString=Log4PerlOutputDebugStringAppender
log4perl.appender.OutputDebugString.layout=Log::Log4perl::Layout::PatternLayout
log4perl.appender.OutputDebugString.layout.ConversionPattern=[%-5p] %-15.15c{1} (%4L) - %m%n

-initialize脚本中的记录器

代码语言:javascript
复制
use Log::Log4perl qw(:easy);
Log::Log4perl->init("logconf.txt");
INFO("INFO");
WARN("WARN");
FATAL("FATAL");

Età-所有日志记录消息都通过OutputDebugStrings

谢谢达辛姆的帮助。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17813963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档