NDC(3)

🌸 NDC(3) β€” Log::Log4perl::NDC, bestie edition ✨

okay so this page is NDC(3) from the User Contributed Perl Documentation crew. And it's literally about the Nested Diagnostic Context, which is a whole vibe. Let's get into it πŸ’…


✨ NAME ✨

Log::Log4perl::NDC β€” Nested Diagnostic Context πŸŽ€


πŸ¦‹ DESCRIPTION πŸ¦‹

So Log::Log4perl lets loggers keep global thread-specific data around, and that whole thing is called the Nested Diagnostic Context (NDC). Iconic naming, no notes.

Here's the situation: at some point your app might decide to push a piece of data onto the NDC stack, and other parts of the app might wanna reuse it later. Like, imagine you're at the beginning of a web request in a server β€” your app might push the IP address of the client onto the stack so other loggers down the road can just have it without you passing that data from function to function like some kind of clown 🀑. Passing args everywhere? not the move.

And get this β€” the Log::Log4perl::Layout::PatternLayout class even has this handy %x placeholder that gets replaced by the blank-separated list of elements currently chilling on the stack. obsessed 😭✨

So this module keeps a simple stack for you. You can push data onto it, peek at what's on top, pop it off again, or nuke the entire stack. Very main character energy.

Its whole purpose is to give you a thread-specific context that all Log::Log4perl loggers can refer to without your application having to pass context data around between its functions. fr fr, that's the point 🫢

And a little lore drop: since in 5.8.0 perl's threads don't share data only upon request, global data is by definition thread-specific. slay.

  • Log::Log4perl::NDC->push($text); β€” Push an item onto the stack. If the stack grows beyond the defined limit ($Log::Log4perl::NDC::MAX_SIZE), just the topmost element will be replated. (yes that's the exact wording in the docs, don't come for me πŸ’€). This is typically done when a context is entered.
  • Log::Log4perl::NDC->pop(); β€” Discard the upmost element of the stack. This is typically done when a context is left.
  • my $text = Log::Log4perl::NDC->get(); β€” Retrieve the content of the stack as a string of blank-separated values without disrupting the stack structure. Typically done by %x. If the stack is empty, the value "[undef]" is being returned. πŸ’œ
  • Log::Log4perl::NDC->remove(); β€” Reset the stack, remove all items. bye bestie πŸ‘‹
⚠️ real talk: all of the methods above are class methods β€” there's no instances of this class. Don't try to new it, it's not that kind of relationship πŸ™ˆ

πŸ’– LICENSE πŸ’–

Copyright 2002-2013 by Mike Schilli <m@perlmeister.com> and Kevin Goess <cpan@goess.org>.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸŽ€


πŸ‘‘ AUTHOR πŸ‘‘

Please contribute patches to the project on Github:

http://github.com/mschilli/log4perl

Send bug reports or requests for enhancements to the authors via our

MAILING LIST (questions, bug reports, suggestions/patches): log4perl-devel@lists.sourceforge.net

Authors (please contact them via the list above, not directly): Mike Schilli <m@perlmeister.com>, Kevin Goess <cpan@goess.org>

Contributors (in alphabetical order): Ateeq Altaf, Cory Bennett, Jens Berthold, Jeremy Bopp, Hutton Davidson, Chris R. Donnelly, Matisse Enzer, Hugh Esco, Anthony Foiani, James FitzGibbon, Carl Franks, Dennis Gregorovic, Andy Grundman, Paul Harrington, Alexander Hartmaier David Hull, Robert Jacobson, Jason Kohles, Jeff Macdonald, Markus Peter, Brett Rann, Peter Rabbitson, Erik Selberg, Aaron Straup Cope, Lars Thegler, David Viner, Mac Yang. β€” the whole squad, absolute legends 🌈⭐


okay that's the whole page, no cap 🧚 this was perl v5.42.0, dated 2022-10-22, straight from NDC(3). mwah πŸ’‹πŸ“

πŸ“¦ where this page comes from