Java Logger(javaÈÕÖ¾)
Ŀ¼
1. ¼ò½é
2. °²×°
3. log4j»ù±¾¸ÅÄî
3.1. Logger
3.2. Appender
3.2.1. ʹÓÃConsoleAppender
3.2.2. ʹÓÃFileAppender
3.2.3. ʹÓÃWriterAppender
3.3. Layout
3.4. »ù±¾Ê¾Àý
3.4.1. SimpleLayoutºÍFileAppender
3.4.2. HTMLLayoutºÍWriterAppender
3.4.3. PatternLayoutºÍConsoleAppender
4. ʹÓÃÍⲿÅäÖÃÎļþ
5. ²Î¿¼×ÊÁÏ (ÒÔ¼°Ò»Ð©Óвο¼¼ÛÖµµÄÁ´½Ó)
1.¼ò½é
³ÌÐò¿ª·¢»·¾³ÖеÄÈÕÖ¾¼Ç¼ÊÇÓÉǶÈëÔÚ³ÌÐòÖÐÒÔÊä³öһЩ¶Ô¿ª·¢ÈËÔ±ÓÐÓÃÐÅÏ¢µÄÓï¾äËù×é³É¡£ÀýÈ磬¸ú×ÙÓï¾ä£¨trace£©£¬½á¹¹×ª´¢ºÍ³£¼ûµÄSystem.out.println»òprintfµ÷ÊÔÓï¾ä¡£log4jÌṩ·Ö¼¶·½·¨ÔÚ³ÌÐòÖÐǶÈëÈÕÖ¾¼Ç¼Óï¾ä¡£ÈÕÖ¾ÐÅÏ¢¾ßÓжàÖÖÊä³ö¸ñʽºÍ¶à¸öÊä³ö¼¶±ð¡£
ʹÓÃÒ»¸öרÃŵÄÈÕÖ¾¼Ç¼°ü£¬¿ÉÒÔ¼õÇá¶Ô³ÉǧÉÏÍòµÄSystem.out.printlnÓï¾äµÄά»¤³É±¾£¬ÒòΪÈÕÖ¾¼Ç¼¿ÉÒÔͨ¹ýÅäÖýű¾ÔÚÔËÐÐʱµÃÒÔ¿ØÖÆ¡£log4jά»¤Ç¶ÈëÔÚ³ÌÐò´úÂëÖеÄÈÕÖ¾¼Ç¼Óï¾ä¡£Í¨¹ý¹æ·¶ÈÕÖ¾¼Ç¼µÄ´¦Àí¹ý³Ì£¬Ò»Ð©ÈËÈÏΪӦ¸Ã¹ÄÀø¸ü¶àµÄʹÓÃÈÕÖ¾¼Ç¼²¢ÇÒ»ñµÃ¸ü¸ß³Ì¶ÈµÄЧÂÊ¡£
2.°²×°
ΪÁËʹÓÃÎÒÃǼ´½«Òª°²×°µÄÈÕÖ¾¼Ç¼¹¤¾ß£¬»¹±ØÐëÒªÉèÖòÙ×÷»·¾³£¬Ö»ÓÐÕâÑù£¬¹¤¾ß²ÅÄÜÖªµÀ´ÓÄÄÀïÕÒµ½ËüËùÐèÒªµÄÐÅÏ¢£¬²¢ÇÒ²Ù×÷ϵͳ֪µÀ´ÓÄÄÀïÕÒµ½Õâ¸ö¹¤¾ß¡£ÄÇô£¬ÔõÑù×öÄØ£¿Êµ¼ÊÉÏ£¬ËüÒªÇó¸ü¸Ä²Ù×÷»·¾³¡£ÎÒÓÐһЩÕâ·½ÃæµÄ×ʸñÎĵµ¡£ Configuring A Windows Working Environment ºÍ Configuring A Unix Working Environment.
´Ó http://jakarta.apache.org/log4j/docs/download.htmlÏÂÔØlog4j·¢Ðа档
½âѹ´æµµÎļþµ½ºÏÊʵÄĿ¼ÖС£
Ìí¼ÓÎļþ dist/lib/log4j-1.2.6.jar µ½ CLASSPATH »·¾³±äÁ¿ÖС£
3.log4jµÄ»ù±¾¸ÅÄî
ʹÓÃlog4j´ó¸ÅÉæ¼°3¸öÖ÷Òª¸ÅÄî:
¹«¹²Àà Logger
Logger ¸ºÔð´¦ÀíÈÕÖ¾¼Ç¼µÄ´ó²¿·Ö²Ù×÷¡£
¹«¹²½Ó¿Ú Appender
Appender ¸ºÔð¿ØÖÆÈÕÖ¾¼Ç¼²Ù×÷µÄÊä³ö¡£
¹«¹²³éÏóÀàLayout
Layout ¸ºÔð¸ñʽ»¯AppenderµÄÊä³ö¡£
3.1.Logger
ÈÕÖ¾¼Ç¼Æ÷(Logger)ÊÇÈÕÖ¾´¦ÀíµÄºËÐÄ×é¼þ¡£log4j¾ßÓÐ5ÖÖÕý³£¼¶±ð(Level)¡£ÈÕÖ¾¼Ç¼Æ÷(Logger)µÄ¿ÉÓü¶±ðLevel (²»°üÀ¨×Ô¶¨Ò弶±ð Level)£¬ ÒÔÏÂÄÚÈݾÍÊÇÕª×Ôlog4j API (http://jakarta.apache.org/log4j/docs/api/index.html):
static Level DEBUG
DEBUG LevelÖ¸³öϸÁ£¶ÈÐÅϢʼþ¶Ôµ÷ÊÔÓ¦ÓóÌÐòÊǷdz£ÓаïÖúµÄ¡£
static Level INFO
INFO level±íÃ÷ ÏûÏ¢ÔÚ´ÖÁ£¶È¼¶±ðÉÏÍ»³öÇ¿µ÷Ó¦ÓóÌÐòµÄÔËÐйý³Ì¡£
static Level WARN
WARN level±íÃ÷»á³öÏÖDZÔÚ´íÎóµÄÇéÐΡ£
static Lev
Ïà¹ØÎĵµ£º
̸̸»Øµ÷°É£¬ÒÔǰѧjavaµÄʱºò¾ÓȻû½Ó´¥µ½Õâ¸ö´Ê»ã£¬º¹£¬×î½üÑо¿hibernateºÍspring½áºÏʱ£¬·¢ÏÖspringʵÏÖhibernateʱӦÓÃÁ˻ص÷»úÖÆ£¬ÓÚÊÇgoogleÁ˺ܶà´Î£¬ÖÕÓÚÓÐËùÌå»áÁË£¬ÏÖÔÚ×öÏÂССµÄ×ܽᣬÒÔ±ã¼ÓÉîÓ¡Ïó£¡
java»Øµ÷»úÖÆ£º
Èí¼þÄ£¿éÖ®¼ä×ÜÊÇ´æÔÚ×ÅÒ»¶¨µÄ½Ó¿Ú£¬´Óµ÷Ó÷½Ê½ÉÏ£¬¿ÉÒÔ°ÑËûÃÇ·ÖΪÈý ......
µÚ8Õ ¶àÏß³Ì
(Ò»)¿Î³ÌÄÚÈÝ
8.1Ï̵߳Ļù±¾¸ÅÄî
8.1.1Ï̵߳ÄÉúÃüÖÜÆÚ
8.1.2Ï̵߳÷¶ÈÓëÓÅÏȼ¶
8.2 ThreadÀàºÍRunnable½Ó13
8.2.1 ThreadÀà
8.2.2 Runnable½Ó¿Ú
8.3Ï̻߳¥³âºÍͬ²½
8.3.1Ï̻߳¥³â
8.3.2Ïß³Ìͬ²½
(¶þ)ѧϰĿµÄÓëÒªÇó
±¾Õ½éÉܶàÏ̵߳ĸÅÄîºÍ±àд¶àÏ̳߳ÌÐòµÄ·½·¨£¬ÊµÏÖÏß³ÌÖ®¼äÏ໥ͨÐźÍͬ²½µÄ¼¼ ......
µÚ10Õ ÍøÂçÓëÊý¾Ý¿â±à³Ì»ù´¡
(Ò»)¿Î³ÌÄÚÈÝ
10.1 JavaÍøÂç±à³Ì»ù´¡
10.1.1 IPµØÖ·ºÍInetAddressÀà
10.1.2ͳһ×ÊÔ´¶¨Î»·ûURL
10.1.3¿Í»§»ú/·þÎñÆ÷ģʽ
l0.2 JavaÊý¾Ý¿â±à³Ì»ù´¡
10.2.1 Java³ÌÐòÓëÊý¾Ý¿âÁ¬½Ó
10.2.2¼¸¸öÖØÒªµÄÀàºÍ½Ó¿Ú
10.2.3Êý¾Ý¿â²éѯ
10.2.4Êý¾Ý¿â¸üÐÂ
(¶þ)ѧϰĿµÄÓëÒªÇó
±¾Õ½éÉÜJavaÍøÂç± ......
//´òÓ¡³ömess±íµÄÁÐÊýÊǶàÉÙ
public static void main(String[] args){
String sql="select count(*) from mess";
ResultSet set=null;
try {
Object paramValues[] = new Object[0];
set = DBUtil.preExec ......