in reply to Re: log4perl - accessing logger in subscripts/subroutines?
in thread log4perl - accessing logger in subscripts/subroutines?
Yes, this is what I understand I should be able to do from reading up on log4perl, call get_logger.
I do understand I could pass the log handle to subscripts, modules, subroutines as a few people have suggested, but my impression was that log4perl should be able to work such that I don't have to pass the variable around.
In my subroutine I called get_logger() however when I ran this what I got was a new instance with the root logger being set up which means the log messages do not go to the logfiles created in my main script. I've just tried again by calling get_logger("logfile") in the subroutine exactly as it was called in my main script and it now seems to be doing what I want. I also ran 2 instances of the main script at the same time and got 2 instances of my log files as I want.
Update: I guess the question would be, is there a way to call get_logger in the subroutine such that I don't have to know what logger the main script called get_logger with?
If I have a 2nd script which could be called from the main script or could be called independently then would I do the Log::Log4perl->init_once so it would work under both scenarios? And again I would need to be calling get_logger("logfile") the same way for it to refer to the logger of the main script if being scheduled from the main script?
Is this what you were suggesting and does this approach make sense in terms of how the log4perl module works? I think my lack of object oriented coding skills is making it a bit difficult for me to really get how the logger instance and get_logger is working. I'm trying to fully understand so that I can set up a configuration and approach that will work generically for all our scripts.
Thanks for the help
|
|---|