java.util.logging


1. logging.properties
   A-- Default :
         My logging.properties file is at C:\Program Files\Java\jdk1.6.0_23\jre\lib.

   B-- To read config from a file by using code.

InputStream lp = new BufferedInputStream(new FileInputStream("./config/log.properties"));
LogManager.getLogManager().readConfiguration(lp);
lp.close();

   C-- To get config from a property.

String propString = "myClass.level=FINE";
byte[] propBytes = propString.getBytes();
LogManager.getLogManager().readConfiguration(new ByteArrayInputStream(propBytes));


1.1 Example:
 code:  //
 this._log.log(Level.SEVERE, "getConnection:"+DBurl+":"+user, e);
Out:
SEVERE: getConnection:jdbc:oracle:thin:@127.0.0.1:1521/pdborcl:miis
java.sql.SQLRecoverableException: ORA-01033: ORACLE initialization or shutdown in progress

... ... 
Reason:
That is the connection to go Oracle12c1.  The DB pdborcl is not open;
Solution:  
SQL> alter pluggable database pdborcl open;

2. java.util.logging.FileHandler is for to save a log file.


  FileHandler fileHandler =new FileHandler("%h/myLogger%g.log.log");

  logger.addHandler(fileHandler);

  • "/" the local pathname separator
  • "%t" the system temporary directory
  • "%h" the value of the "user.home" system property
  • "%g" the generation number to distinguish rotated logs
  • "%u" a unique number to resolve conflicts
  • "%%" translates to a single percent sign "%" 

Ref: h t t p : / / d ocs .oracle.com/javase/7/docs/api/java/util/logging/FileHandler.html

评论

此博客中的热门博文

XML, XSL, HTML

Input in element.eleme.io

Data URI是由RFC 2397 ACE