Java.util.logging.Logger wrote to the file.

Source: Internet
Author: User

First define and initialize it:

Logger Logger = Logger.getlogger ("log");

If you want to enter the logger information into the specified file, you will write a filehandler, as follows:

String LogPath = "C:/mylog";//This is the path to the log file you specified

Filehandler Filehandler = new Filehandler (LogPath);

At this point, the log file format is the default XML format, if you want to change it into a general text format, format, as follows:

Filehandler.setformatter (New Fimpleformatter ());//Create a new format class, let it specify

Also, the Logger class uses the default output handler will display all the information you want to the console, and if you don't want it to be displayed to the console, write the following sentence:

Logger.setuseparenthandler (false);//This is the handler that specifies that the parent class is not used,

Then, add Filehandler to the logger:

Logger.addhandler (Fiehandler):

Finally you can use logger to write the information you want, O (∩_∩) o ... Ha ha.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.