How tomcat uses defalut Log system to print Custom log

problem description

currently learning tomcat development, encountered some printing log problems, I would like to add their own print in serverlet, output to some custom file (but not out of the scope of tomcat, do not customize filehandler to C disk, d disk and so on), still like relying on tomcat default log system, output to a file in the tomcat/logs/ directory. I"d like to use it with log.properties.

the environmental background of the problems and what methods you have tried

the method of java.utils.Logger used by log, that I added in the code

    private static Logger createLocalLogger()
    {
        Logger localLogger = Logger.getLogger("bmWebServer");
        return localLogger;
    }
    logger.info(logs)

using this method, I output log directly to tomcat/logs/tomcat9-stdout, which is not what I want.

what result do you expect? What is the error message actually seen?

I can more or less understand the configuration in

log.properties, but I want to know how to use the handler, file path and formatter defined in this in my serverlet code? I can actually type my custom log into catalina.out.

but searching the Internet is full of articles about configuration, or the method of replacing log4j, which is not what I want.
there are great gods here, do you know? Do not hesitate to give advice, thank you!

Aug.04,2021

https://blog.csdn.net/ljflemo.
I have solved this problem by reading the official documentation myself.
the Internet is full of documents that use log4j, but few of them use JULI.

I can solve this problem above.


define static variables in the file you want to type

private static final Logger logger = Logger.getLogger(bmWebServer.class);

directly logger.info ()
where you want to print the log. Just set the level to info in your properties file

Menu