We can make some changes to the object returned at runtime.

It is possible to make some changes to the object at runtime.

My problem is that I have one class that returns me a registrar instance. and this class contains only one public method that the registrar returns. lower class ..

public class LoggerManager {

    public Logger getLogger(String FQCN) {
        Logger logger = Logger.getLogger(FQCN);
            logger.setLevel(Level.INFO);
            return logger;
    }
}

now, if I want to change the returned object at runtime,

which means that the log object that is set to the INFO level, I want to change it to DEBUG .. during program execution only when this code is called at a specific time ... without changing the code anywhere .. some thing like this ...

logger.setLevel(Level.DEBUG);

can i achieve this, by any means?

.. 1000 , .... ...

+3
4

, , getLogger(String) . : ", ".

, :

  • .

  • BCEL -, - .

, .

, - LogManager, . , .

, , setLevel .

+2

, Objects, .

, . , vm, Logger FQCN.

+1

. Somme.

I can't be specific here because your didn't say exactly what your Logger class is (Log4j ?).

, , . , - ( Tomcat, , ), ( , ).


. , , :

  • ,
  • ( ).
0

It is possible to do this with AOP, but it rather compiles. AOP allows you to handle pre and post method calls.

I'm not sure why you should get more than 1000 places in your one project. Do you have more than 1000 classes? Usually you only need to call it once for each class. I would also modify the code and reverse engineer overcalling for this method.

0
source

Source: https://habr.com/ru/post/1779714/


All Articles