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
Ïà¹ØÎĵµ£º
public class DateTest {
public static void main(String[] args) {
Date date = new Date(); // н¨Ò»¸öÈÕÆÚ
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // ¸ñʽ»¯ÈÕÆÚ
String beforeDate = sdf.format(getDateBefore(date, 10));
System ......
̸̸»Øµ÷°É£¬ÒÔǰѧjavaµÄʱºò¾ÓȻû½Ó´¥µ½Õâ¸ö´Ê»ã£¬º¹£¬×î½üÑо¿hibernateºÍspring½áºÏʱ£¬·¢ÏÖspringʵÏÖhibernateʱӦÓÃÁ˻ص÷»úÖÆ£¬ÓÚÊÇgoogleÁ˺ܶà´Î£¬ÖÕÓÚÓÐËùÌå»áÁË£¬ÏÖÔÚ×öÏÂССµÄ×ܽᣬÒÔ±ã¼ÓÉîÓ¡Ïó£¡
java»Øµ÷»úÖÆ£º
Èí¼þÄ£¿éÖ®¼ä×ÜÊÇ´æÔÚ×ÅÒ»¶¨µÄ½Ó¿Ú£¬´Óµ÷Ó÷½Ê½ÉÏ£¬¿ÉÒÔ°ÑËûÃÇ·ÖΪÈý ......
ÔÚJava AplicationÖÐʵÏֵļòÒײ¥·ÅÆ÷¡£À´Ô´ÓÚºúÇɶàÖ÷±àµÄ¡¶Java³ÌÐòÉè¼Æ°¸Àý½Ì³Ì¡·
ÎÒÊÔÔËÐйýÁË£¬ÆäÖÐµÄ “Ìýº£.wav”,“Ò»¶¨Òª°®Äã.wav”ÒôƵÎļþÒª·ÅÔÚclassËùÔÚµÄÎļþ¼ÐÖУ¬ÇÒÖ»Ö§³Öwav¸ñʽ
Ô´´úÂ룺
import java.applet.Applet;
import java.applet.AudioClip;
import javax.swing.* ......
¡¶javaÓïÑÔ³ÌÐòÉè¼Æ£¨Ò»£©¡·2009Äê×Ôѧ¿¼ÊÔ´ó¸ÙµÚ4ÕÂ
www.wesiedu.com 2009-5-5 ÔÚÏßÄ£Ä⿼³¡
µÚ4Õ Êý×éºÍ×Ö·û´®
(Ò»)¿Î³ÌÄÚÈÝ
4.1 Êý×é
4.1.1 һάÊý×é
4.1.2 ¶àάÊý×é
4.2 ×Ö·û´®
4.2.1 ×Ö·û´®³£Á¿
4.2.2 ×Ö·û´®ÉùÃ÷ºÍ´´½¨
4.2.3 ×Ö·û´®»ù±¾²Ù×÷
4.2.4 StringTokenizerÀà
4.2.5×Ö· ......
//´òÓ¡³ö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 ......