When I haven't pushed anything to the Log::Log4perl::NDC stack, %x
returns [undef]
. I would like it to return an empty string when the stack is empty.
For example, take this code:
use strict;
use Log::Log4perl qw(:easy);
Log::Log4perl->easy_init({ level => $INFO, layout => "%x %m%n" });
Log::Log4perl->get_logger()->info("first message");
Log::Log4perl::NDC->push("prefix");
Log::Log4perl->get_logger()->info("second message");
This prints:
[undef] first message
prefix second message
But I want it to print:
first message
prefix second message
How can I do this?