Here is an updated example

#!/usr/bin/perl -- use strict; use warnings; use Tkx; use Log::Log4perl; Log::Log4perl->easy_init( $Log::Log4perl::INFO ); Main( @ARGV ); exit( 0 ); sub Main { #~ $Tkx::TRACE=64; Tkx::package_require('tile'); Tkx::ttk__setTheme('xpnative');#Tkx::tile__setTheme('xpnative'); my $logger = Log::Log4perl->get_logger; ## jellisii2 my $appender = Log::Log4perl::Appender::String2->new; ## jellisii2 $logger->add_appender($appender); ## jellisii2 my $mw = Tkx::widget->new("."); my $eee = $mw->new_entry( -textvariable => $appender->string_ref, ## jellisii2 ); $eee->g_pack( -fill => "x", -expand => 1 ); my $t = $mw->new_text( -padx => 5, -pady => 5, -background => "white", ); $t->g_pack; $appender->tktext( $t ); ## jellisii2 my $b = $mw->new_ttk__button( -text => 'Hello, world', -command => sub { $logger->info("hi"); ## jellisii2 }, ); $b->g_pack; $b->configure(); $logger->info("it begins"); ## jellisii2 Tkx::MainLoop(); } BEGIN { $INC{'Log/Log4perl/Appender/String2.pm'} = __FILE__; package Log::Log4perl::Appender::String2; use Log::Log4perl::Appender; our @ISA = qw(Log::Log4perl::Appender); sub new { my $proto = shift; my $class = ref $proto || $proto; my %params = @_; my $self = { name => "unknown name", string => "", %params, }; bless $self, $class; } sub log { my ($self, $p, $category, $level, $cache) = @_; my %params = %$p; if( my $status_text = $self->{tktext} ){ # text control has to be enabled to write to it. $status_text->configure(-state => "normal"); ### this ought to be handeled through layout_class / layout_pattern $status_text->insert( "end", join '', scalar(gmtime), ' jellisii2 ', @{$params{message}}, "\n", ); $status_text->see("end"); # Don't want the user editing this... $status_text->configure(-state => "disabled"); eval { $status_text->update(); 1} or eval { Tkx::update(); + }; } $self->{string} .= join '', '(', @{ $params{message} }, ')'; } sub string { # getter/setter my($self, $new) = @_; if(defined $new) { $self->{string} = $new; } return $self->{string}; } sub tktext { # getter/setter my($self, $new) = @_; if(defined $new) { $self->{tktext} = $new; } return $self->{tktext}; } sub string_ref { # getter my($self ) = @_; return \$self->{string}; } 1; }

In reply to Re^3: Log4perl appender to write to scalar? by Anonymous Monk
in thread Log4perl appender to write to scalar? by jellisii2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.