Making self-logging modules with Log::Log4perl

后端 未结 2 1129
小鲜肉
小鲜肉 2020-12-28 11:35

Is there a way to use Log::Log4perl to make a smart self-logging module that logs its operations to a file even in the absence of the calling script not initializing Log4per

2条回答
  •  渐次进展
    2020-12-28 11:52

    The short answer is to call Log::Log4perl::initialized(); at some point and if it is false, set up some default logging.

    The tricky part is "some point."

    You can't do it in BEGIN {}, because then the main script's will stomp your initialisation even though you created unnessary files. You don't want to do it before each call to get_logger() because that is wasteful. So you should do it during the module's initialisation, say sub new or sub init.

提交回复
热议问题