NullLogLite(3pm)

πŸ“¦
version 0.82 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– NullLogLite(3pm) β€” the page you're reading is NullLogLite, from the User Contributed Perl Documentation besties πŸ’–

okay so. sit down. hydrate. because this module is genuinely one of the most iconic little sleight-of-hand tricks in all of Perl and I need you to be normal about it 🫢


✨ NAME ✨

Log::NullLogLite β€” the class that implements the Null Object pattern for the Log::LogLite class. that's it. that's the whole vibe. πŸ’…


🌸 SYNOPSIS 🌸

use Log::NullLogLite;

# create new Log::NullLogLite object
my $log = new Log::NullLogLite();

...

# we had an error (this entry will not be written to the log
# file because we use Log::NullLogLite object).
$log->write("Could not open the file ".$file_name.": $!", 4);

see how that last one looks like a real, functioning log call? yeah. it does nothing. and that is the entire point ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so here's the tea, bestie β˜•

Log::NullLogLite is derived from the Log::LogLite class, and it implements the Null Object Pattern so we can use Log::LogLite with null Log::LogLite objects. ngl that sentence sounds like a tongue twister but it's lowkey genius.

when would you even want that?? okay so picture this: you've got a Log::LogLite object living in your code, right? but you don't always wanna actually define one β€” like, sometimes you do not want to write to a log file at all. main character code, flexible needs πŸ’β€β™€οΈ

so instead of defining a Log::LogLite object, you create a Log::NullLogLite object instead, and you use that instead. it has all the methods the Log::LogLite object has... but those methods do nothing. πŸ’€

which means:

  • your code keeps running with zero changes πŸŽ€
  • you never have to define a log file path for the Log::LogLite object
  • no log will be created 🌈

it's giving "I'm here, I'm present, I'm doing absolutely nothing, and I'm slaying while doing it." ✨


πŸŽ€ CONSTRUCTOR πŸŽ€

  • new ( FILEPATH [,LEVEL [,DEFAULT_MESSAGE ]] ) β€” the constructor, bestie. the parameters will not have any affect. like, at all. it just returns the new Log::NullLogLite object. 🫢

πŸ’… METHODS πŸ’…

  • write( MESSAGE [, LEVEL ] ) β€” does nothing. the parameters will not have any affect. returns nothing. not even a lil something. nothing. 😌
  • level( [ LEVEL ] ) β€” does nothing. the parameters will not have any affect. returns -1. yes, -1, that's the whole personality. πŸ”₯
  • default_message( [ MESSAGE ] ) β€” does nothing. the parameters will not have any affect. returns empty string (""). the void, but make it a string. 🌸

πŸ‘‘ AUTHOR πŸ‘‘

Rani Pinchuk, rani@cpan.org


Copyright (c) 2001-2002 Ockham Technology N.V. & Rani Pinchuk. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


🌈 SEE ALSO 🌈


ok real talk for one sec β€” this is the null object, so like, none of the parameters do anything and nothing gets written anywhere. if you were expecting output, that's not a bug, that's the whole assignment πŸ’€ don't go filing tickets about the silence. the silence is the feature. 🫢

and that's the page, bestie!! this was perl v5.36.0, dated 2022-12-04, and it's filed under NullLogLite(3pm). obsessed with her honestly. periodt. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from