-
Call the GetLogger method to create or retrieve a logger
Logger myLogger= Logger.getLogger("log.zhouyong");
-
Suppose you set the log level for the log. Then its child logger will inherit this property as well.
-
There's a little bit of 7 logger levels
- SEVERE
- WARNING
- INFO
- CONFIG
- FINE
- Finer
- FINEST
In the default case. Only the first three levels are recorded. Other levels can also be set. Like what:
logger.setLevel(Level.FINE)
Today, fine and higher-level records can be recorded
Also able to use Level.all to turn all Level.off off all
-
There are several ways to record
logger.warning(message);logger.fine(message);//同一时候还能够用log方法指定级别logger.log(Level.FINE,message);
-
The general use of Config,fine and other records to help diagnose, but for the program ape does not have much meaning debugging information.
-
The default logging will show the include log call class name and method name. However, assuming that the virtual machine is optimized, it may not be able to get accurate information. At this point the Logp method is required to obtain the exact location of the calling class and method, such as the following:
void logp(level l,String className,String methodName,String message)
Here are some other ways to track the running flow
void entering(String className,String methodName)void entering(String className,String methodName,Object param)void entering(String className,String methodName,Object[] params)void exiting(String className,String methodName)void exiting(String className,String methodName,Object result)
Like what:
不知道有什么用。。
-
The most common use of logging is to record unexpected exceptions. There are two ways to use it.
void throwing(String className,String methodName,Throwable t)void log(Level l,String message ,Throwable t)
The typical use is:
if(...){ IOExcption exception = new IOException("..."); logger.throwing("com.my","read",exception); throw exception; //FINER级别}
And also
try{ ...}catch (IOException e){ Logger.getLogger("...").log(Level.WARNING,"Reading image",e);}
11.5.3 Change Log Manager configuration
-
The logger sends the records to the parent processor first, and finally the processor has one ConsoleHandle .
-
For a log record to be logged, it must have a higher logging level than the logger and processor thresholds.
To log the fine level. You must change the default logging level and processor level in the configuration file.
In addition , you can bypass the configuration file and install your own processor.
Console processor
Logger logger=Logger.getLogger("log.zhouyong");logger.setLevel(Level.FINE);logger.setUseParentHandlers(false);Handler handler = new ConsoleHandler();handler.setLevel(Level.FINE);logger.addHandler(handler);logger.log(Level.FINE,"dddd");
By default, the logger sends records to its own processor and parent processor.
The parent processor is the generic default processor, but since we have our own processor, we can turn the parent processor off. Lest the console send two records.
-
To send a log to another location, you need a different processor.
- Filehandler collecting logs from files
- Sockethandler. Send to a specific host and port
-
Filehandler
FileHandler handler = new FileHandler();handler.setLevel(Level.FINE);logger.addHandler(handler);logger.log(Level.FINE,"dddd");
The file is under user. The format is XML. For example, the following:
<?xml version="1.0" encoding="GBK" standalone="no"?
><!DOCTYPE log SYSTEM "logger.dtd"><log><record> <date>2016-03-15T23:40:17</date> <millis>1458056417956</millis> <sequence>0</sequence> <logger>log.zhouyong</logger> <level>FINE</level> <class>log</class> <method>main</method> <thread>1</thread> <message>dddd</message></record></log>
- There are a lot of other complicated ways to deal with the requirements that you want.
11.5.6 Filter