Hi,

This was bad news indeed, because I don't really like the idea of redefining (parts of) Log::Log4perl (or Log::Log4perl::Tiny, as per clueless newbie's suggestion). But your reply made me take a closer look at the information available to cspec callbacks, and I was able to snatch good news from the jaws of the bad news: although the callbacks don't get %info, they do get $caller_level, using which I can get at filename and line number on my own (duplicating Log::Log4perl's work a bit). After some experimenting, I came up with a complete solution.

In log4perl.conf, I say:

log4perl.PatternLayout.cspec.S = sub { ' ' x level_for_l4p(); } log4perl.PatternLayout.cspec.A = sub { msgpfx_for_l4p( @_ ); } log4perl.appender.std.layout.ConversionPattern = %-32A%S%m%n

And in the main program:

my $zerolevel = 8; sub level_for_l4p { my $level = 0; 1 while caller( $level++ ); return $level - $zerolevel; } sub msgpfx_for_l4p { my ( $l, $m, $c, $p, $caller_level ) = @_; my ( $unused, $filename, $line, @unused ) = caller( $caller_level + 1 ); return "$filename:$line:"; } Log::Log4perl::init('log4perl.conf');

This setup produces the exact output I wished for and described near the end of my initial message, making me happy again.

Thanks and regards,
T.


In reply to Re^2: Log::Log4perl::Layout::PatternLayout: setting combined length for two fields? by toomas
in thread Log::Log4perl::Layout::PatternLayout: setting combined length for two fields? by toomas

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.