How to use Java Loggingapi

Source: Internet
Author: User

Because you don't want to import log4j jars, the project is just testing something, so choosing the logging that comes with the JDK is a good choice for small projects or testing something for yourself.

In log4j, the output of the log is controlled by log4j.properties this configuration file, and the Java logging is done with similar functionality through logging.properties files.

The Logging.properties file is located in the jre/lib/directory of the JDK installation path, directly on the configuration file:

handlers= java.util.logging.ConsoleHandler.level ==%h/java%= 50000= 1  = == Java.util.logging.SimpleFormatter

You want to enter both the console and the revenue in the file, as set below.

handlers= Java.util.logging.FileHandler, Java.util.logging.ConsoleHandler

The format requirements for the log file are set to the following line:

Java.util.logging.FileHandler.pattern =%h/java%u.log

Specify how to define, and you can view the Java Logging Format API to set it up.

The above settings allow you to enter the log into the specified file requirements. But sometimes just want some kind of file output to make, so debugging more clear, in order to achieve the requirements of a few more settings.

Com.jason.logger.LoggerDemo.level == Java.util.logging.FileHandler

"Com.spt.logger.LoggerDemo" is the name of "Logger", which matches the logger specified in the code.

C program in use, the code is as follows:

Private Static Logger log = Logger.getlogger (Loggerdemo.  Class. GetName ());

By the way, I also forgot the logging several levels to do the introduction:

SEVERE (highest level) WARNING INFO CONFIG FINE finer FINEST (lowest level)

Simple use of these is enough, and then the use of complex, personal feeling will be on the log4j.

How to use Java loggingapi

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.