http://www.perlmonks.org?node_id=923395


in reply to [log4perl] log level vs. threads

Different threads will have separate private copies of the Log::Log4perldata structures, so any changes you make in one thread will not affect another.

I can think of three solutions to your problem.

  1. Make the Log4perl data structure shared between threads. This might not work if Log4perl is not thread safe.
  2. Find a way of signalling between threads via another shared variable, sockets, signals etc, so they all change their log level at once.
  3. Make changes to the log4perl config file, and take advantage of the fact that log4perl can watch for changes and automatically reload the file,

Of the three options, I think the third is probably the most reliable and safest in the long term.

I would also ask why you are changing the log level at runtime?

If it is as a response to an exceptional situation, then it would probably be better to log at a higher level to begin with, and adjust the retention of those detailed log files in response to a problem.

Also it is worth noting that you can have different log4perl configurations for different classes within you perl program, so that would be another way of having more detailed logging for an area that deserves more logging.