作業部屋の使い方を試しています。
(empty log message)
| @@ -0,0 +1,113 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2014 kgto. | |
| 3 | + * | |
| 4 | + * This library is free software; you can redistribute it and/or | |
| 5 | + * modify it under the terms of the GNU Lesser General Public | |
| 6 | + * License as published by the Free Software Foundation; either | |
| 7 | + * version 2.1 of the License, or (at your option) any later version. | |
| 8 | + * | |
| 9 | + * This library is distributed in the hope that it will be useful, | |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | + * Lesser General Public License for more details. | |
| 13 | + * | |
| 14 | + * You should have received a copy of the GNU Lesser General Public | |
| 15 | + * License along with this library; if not, write to the Free Software | |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 17 | + * MA 02110-1301 USA | |
| 18 | + */ | |
| 19 | +package WebScraping; | |
| 20 | + | |
| 21 | +import javax.swing.text.MutableAttributeSet; | |
| 22 | +import javax.swing.text.html.HTML; | |
| 23 | +import org.junit.AfterClass; | |
| 24 | +import org.junit.BeforeClass; | |
| 25 | +import org.junit.Test; | |
| 26 | +import static org.junit.Assert.*; | |
| 27 | + | |
| 28 | +import org.junit.AfterClass; | |
| 29 | +import org.junit.BeforeClass; | |
| 30 | +import org.junit.Test; | |
| 31 | +import static org.junit.Assert.*; | |
| 32 | + | |
| 33 | +/** | |
| 34 | + * | |
| 35 | + * @author kgto | |
| 36 | + */ | |
| 37 | + | |
| 38 | + | |
| 39 | +public class DebugProcessTest { | |
| 40 | + | |
| 41 | + public DebugProcessTest() { | |
| 42 | + } | |
| 43 | + | |
| 44 | + @BeforeClass | |
| 45 | + public static void setUpClass() { | |
| 46 | + } | |
| 47 | + | |
| 48 | + @AfterClass | |
| 49 | + public static void tearDownClass() { | |
| 50 | + } | |
| 51 | + | |
| 52 | + /** | |
| 53 | + * Test of debuglog_set method, of class DebugProcess. | |
| 54 | + */ | |
| 55 | + @Test | |
| 56 | + public void testDebuglog_set() { | |
| 57 | + System.out.println("debuglog_set"); | |
| 58 | + DebugProcess.debuglog_set(); | |
| 59 | + // TODO review the generated test code and remove the default call to fail. | |
| 60 | + fail("The test case is a prototype."); | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * Test of debuglog_unset method, of class DebugProcess. | |
| 65 | + */ | |
| 66 | + @Test | |
| 67 | + public void testDebuglog_unset() { | |
| 68 | + System.out.println("debuglog_unset"); | |
| 69 | + DebugProcess.debuglog_unset(); | |
| 70 | + // TODO review the generated test code and remove the default call to fail. | |
| 71 | + fail("The test case is a prototype."); | |
| 72 | + } | |
| 73 | + | |
| 74 | + /** | |
| 75 | + * Test of htmlinfo method, of class DebugProcess. | |
| 76 | + */ | |
| 77 | + @Test | |
| 78 | + public void testHtmlinfo_4args() { | |
| 79 | + System.out.println("htmlinfo"); | |
| 80 | + HTML.Tag tag = null; | |
| 81 | + MutableAttributeSet attr = null; | |
| 82 | + String methodname = ""; | |
| 83 | + int count = 0; | |
| 84 | + DebugProcess.htmlinfo(tag, attr, methodname, count); | |
| 85 | + // TODO review the generated test code and remove the default call to fail. | |
| 86 | + fail("The test case is a prototype."); | |
| 87 | + } | |
| 88 | + | |
| 89 | + /** | |
| 90 | + * Test of htmlinfo method, of class DebugProcess. | |
| 91 | + */ | |
| 92 | + @Test | |
| 93 | + public void testHtmlinfo_String() { | |
| 94 | + System.out.println("htmlinfo"); | |
| 95 | + String str = ""; | |
| 96 | + DebugProcess.htmlinfo(str); | |
| 97 | + // TODO review the generated test code and remove the default call to fail. | |
| 98 | + fail("The test case is a prototype."); | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * Test of htmlinfo method, of class DebugProcess. | |
| 103 | + */ | |
| 104 | + @Test | |
| 105 | + public void testHtmlinfo_charArr() { | |
| 106 | + System.out.println("htmlinfo"); | |
| 107 | + char[] data = null; | |
| 108 | + DebugProcess.htmlinfo(data); | |
| 109 | + // TODO review the generated test code and remove the default call to fail. | |
| 110 | + fail("The test case is a prototype."); | |
| 111 | + } | |
| 112 | + | |
| 113 | +} |
| @@ -0,0 +1,66 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2014 kgto. | |
| 3 | + * | |
| 4 | + * This library is free software; you can redistribute it and/or | |
| 5 | + * modify it under the terms of the GNU Lesser General Public | |
| 6 | + * License as published by the Free Software Foundation; either | |
| 7 | + * version 2.1 of the License, or (at your option) any later version. | |
| 8 | + * | |
| 9 | + * This library is distributed in the hope that it will be useful, | |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | + * Lesser General Public License for more details. | |
| 13 | + * | |
| 14 | + * You should have received a copy of the GNU Lesser General Public | |
| 15 | + * License along with this library; if not, write to the Free Software | |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 17 | + * MA 02110-1301 USA | |
| 18 | + */ | |
| 19 | +package WebScraping; | |
| 20 | + | |
| 21 | +import java.util.logging.LogRecord; | |
| 22 | +import org.junit.AfterClass; | |
| 23 | +import org.junit.BeforeClass; | |
| 24 | +import org.junit.Test; | |
| 25 | +import static org.junit.Assert.*; | |
| 26 | + | |
| 27 | +import org.junit.AfterClass; | |
| 28 | +import org.junit.BeforeClass; | |
| 29 | +import org.junit.Test; | |
| 30 | +import static org.junit.Assert.*; | |
| 31 | + | |
| 32 | +/** | |
| 33 | + * | |
| 34 | + * @author kgto | |
| 35 | + */ | |
| 36 | + | |
| 37 | + | |
| 38 | +public class HtmlFormatterTest { | |
| 39 | + | |
| 40 | + public HtmlFormatterTest() { | |
| 41 | + } | |
| 42 | + | |
| 43 | + @BeforeClass | |
| 44 | + public static void setUpClass() { | |
| 45 | + } | |
| 46 | + | |
| 47 | + @AfterClass | |
| 48 | + public static void tearDownClass() { | |
| 49 | + } | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * Test of format method, of class HtmlFormatter. | |
| 53 | + */ | |
| 54 | + @Test | |
| 55 | + public void testFormat() { | |
| 56 | + System.out.println("format"); | |
| 57 | + LogRecord aRecord = null; | |
| 58 | + HtmlFormatter instance = new HtmlFormatter(); | |
| 59 | + String expResult = ""; | |
| 60 | + String result = instance.format(aRecord); | |
| 61 | + assertEquals(expResult, result); | |
| 62 | + // TODO review the generated test code and remove the default call to fail. | |
| 63 | + fail("The test case is a prototype."); | |
| 64 | + } | |
| 65 | + | |
| 66 | +} |
| @@ -0,0 +1,47 @@ | ||
| 1 | + | |
| 2 | +package WebScraping; | |
| 3 | + | |
| 4 | +import static WebScraping.DebugProcess.logger; | |
| 5 | +import java.util.logging.Formatter; | |
| 6 | +import java.util.logging.Handler; | |
| 7 | +import java.util.logging.Logger; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * | |
| 11 | + * @author kgto | |
| 12 | + */ | |
| 13 | + | |
| 14 | + | |
| 15 | +public class DebugProcessT01 { | |
| 16 | + | |
| 17 | + public static void main(String[] args) { | |
| 18 | + | |
| 19 | + DebugProcessT01 test = new DebugProcessT01(); | |
| 20 | + test.testdebuglog_set(); | |
| 21 | + | |
| 22 | + System.out.println("LoggerName : " + logger.getName()); | |
| 23 | + System.out.println("LoggerLevel : " + logger.getLevel()); | |
| 24 | + | |
| 25 | + Handler[] handlers = logger.getHandlers(); | |
| 26 | + for(int i = 0 ; i < handlers.length ; i++) { | |
| 27 | + System.out.println(handlers[i] + "'s Level: " + handlers[i].getLevel()); | |
| 28 | + | |
| 29 | + Formatter formatter = handlers[i].getFormatter(); | |
| 30 | + System.out.println("\tFormatter: " + formatter.toString()); | |
| 31 | + } | |
| 32 | + | |
| 33 | + test.testhtmlinfo(); | |
| 34 | + } | |
| 35 | + | |
| 36 | + public DebugProcessT01() { | |
| 37 | + } | |
| 38 | + | |
| 39 | + void testdebuglog_set() { | |
| 40 | + DebugProcess.debuglog_set(); | |
| 41 | + } | |
| 42 | + | |
| 43 | + void testhtmlinfo() { | |
| 44 | + DebugProcess.htmlinfo("testhtmlinfo"); | |
| 45 | + } | |
| 46 | + | |
| 47 | +} |
| @@ -87,18 +87,7 @@ | ||
| 87 | 87 | handleStartattrdata.add(tag, attr); |
| 88 | 88 | |
| 89 | 89 | //--- DEBUG OUT ---- start --- |
| 90 | - if(DEBUG) { | |
| 91 | - StringBuffer strBuf = new StringBuffer(); | |
| 92 | - // tag情報 | |
| 93 | - strBuf.append(count).append(" : F : ").append(tag.toString()); | |
| 94 | - // 属性情報 | |
| 95 | - for(int i = 0; i < handleStartattrdata.size; i++) { | |
| 96 | - strBuf.append(" [").append(handleStartattrdata.getattrname(i)).append("] ") | |
| 97 | - .append(handleStartattrdata.getattrvalue(i)); | |
| 98 | - } | |
| 99 | - // 表示 | |
| 100 | - System.out.println(strBuf); | |
| 101 | - } | |
| 90 | + DebugProcess.htmlinfo(tag, attr, "handleStartTag", count); | |
| 102 | 91 | //--- DEBUG OUT ---- end --- |
| 103 | 92 | |
| 104 | 93 | if(bufCount == 0) { |
| @@ -126,23 +115,7 @@ | ||
| 126 | 115 | } |
| 127 | 116 | |
| 128 | 117 | //--- DEBUG OUT ---- start --- |
| 129 | - if(DEBUG) { | |
| 130 | - if(tag.equals(bufTag) && count <= bufCount) { | |
| 131 | - for(int i = 0; i < attrdata.size; i++) { | |
| 132 | - StringBuffer strBuf = new StringBuffer(); | |
| 133 | - strBuf.append(" Tag-attr : "); | |
| 134 | - strBuf.append(attrdata.gettag(i)).append(" [ "); | |
| 135 | - strBuf.append(attrdata.getcount(i)).append(" ] "); | |
| 136 | - strBuf.append(attrdata.getattrname(i)).append(" = "); | |
| 137 | - strBuf.append(attrdata.getattrvalue(i)); | |
| 138 | - System.out.println(strBuf); | |
| 139 | - } | |
| 140 | - } | |
| 141 | - StringBuffer strBuf = new StringBuffer(); | |
| 142 | - // tag情報 | |
| 143 | - strBuf.append(count).append(" : E : ").append(tag.toString()); | |
| 144 | - System.out.println(strBuf); | |
| 145 | - } | |
| 118 | + DebugProcess.htmlinfo(tag, null, "handleEndTag", count); | |
| 146 | 119 | //--- DEBUG OUT ---- end --- |
| 147 | 120 | |
| 148 | 121 | if(tag.equals(bufTag) && count <= bufCount) { |
| @@ -163,10 +136,7 @@ | ||
| 163 | 136 | @Override |
| 164 | 137 | public void handleText(char[] data, int pos){ |
| 165 | 138 | //--- DEBUG OUT ---- start --- |
| 166 | - if(DEBUG) { | |
| 167 | - String dat = new String(data); | |
| 168 | - System.out.println(dat); | |
| 169 | - } | |
| 139 | + DebugProcess.htmlinfo(data, "handleText"); | |
| 170 | 140 | //--- DEBUG OUT ---- end --- |
| 171 | 141 | String splitchar = "\t"; |
| 172 | 142 |
| @@ -196,19 +166,7 @@ | ||
| 196 | 166 | } |
| 197 | 167 | |
| 198 | 168 | //--- DEBUG OUT ---- start --- |
| 199 | - if(DEBUG) { | |
| 200 | - AttributeData simpleattrdata = new AttributeData(); | |
| 201 | - simpleattrdata.add(tag, attr); | |
| 202 | - StringBuffer strBuf = new StringBuffer(); | |
| 203 | - // tag情報 | |
| 204 | - strBuf.append("x : S : ").append(tag.toString()); | |
| 205 | - // 属性情報 | |
| 206 | - for(int i = 0; i < simpleattrdata.size; i++) { | |
| 207 | - strBuf.append(" [").append(simpleattrdata.getattrname(i)).append("] ").append(simpleattrdata.getcount(i)) | |
| 208 | - .append(" = ").append(simpleattrdata.getattrvalue(i)); | |
| 209 | - } | |
| 210 | - System.out.println(strBuf); | |
| 211 | - } | |
| 169 | + DebugProcess.htmlinfo(tag, attr, "handleSimpleTag", 0); | |
| 212 | 170 | //--- DEBUG OUT ---- end --- |
| 213 | 171 | } |
| 214 | 172 |
| @@ -39,7 +39,6 @@ | ||
| 39 | 39 | |
| 40 | 40 | URL url; |
| 41 | 41 | String pageData; |
| 42 | - | |
| 43 | 42 | ArrayList sData; |
| 44 | 43 | |
| 45 | 44 | // 作業ワーク |
| @@ -47,10 +46,6 @@ | ||
| 47 | 46 | String htmlid; |
| 48 | 47 | String htmlclass; |
| 49 | 48 | |
| 50 | - public HtmlParser() { | |
| 51 | - url = null; | |
| 52 | - } | |
| 53 | - | |
| 54 | 49 | public HtmlParser(URL UrlAdress) { |
| 55 | 50 | this.url = UrlAdress; |
| 56 | 51 | getpageData(); |
| @@ -66,6 +61,10 @@ | ||
| 66 | 61 | } |
| 67 | 62 | } |
| 68 | 63 | |
| 64 | + public HtmlParser() { | |
| 65 | + url = null; | |
| 66 | + } | |
| 67 | + | |
| 69 | 68 | public void seturl(URL UrlAdress) { |
| 70 | 69 | this.url = UrlAdress; |
| 71 | 70 | getpageData(); |
| @@ -130,7 +129,7 @@ | ||
| 130 | 129 | * @param skey HTMLタグ/ID/CLASSが格納された検索キー |
| 131 | 130 | * @return boolean HTMLタグ/ID/CLASS値が一致する時、true |
| 132 | 131 | */ |
| 133 | - public boolean isHtmlkeyEq(SearchData skey) { | |
| 132 | + boolean isHtmlkeyEq(SearchData skey) { | |
| 134 | 133 | |
| 135 | 134 | String stag = skey.getHtmltag(); |
| 136 | 135 | String sid = skey.getHtmlid(); |
| @@ -180,7 +179,7 @@ | ||
| 180 | 179 | * @param regexp |
| 181 | 180 | * @return |
| 182 | 181 | */ |
| 183 | - public String RegularExpression(String strdata, String regexp) { | |
| 182 | + String RegularExpression(String strdata, String regexp) { | |
| 184 | 183 | String expdata = null; |
| 185 | 184 | |
| 186 | 185 | //regexpのチェック |
| @@ -228,7 +227,10 @@ | ||
| 228 | 227 | * HTMLパーサ. |
| 229 | 228 | * @param skey |
| 230 | 229 | */ |
| 231 | - public void serchpageData(SearchData skey){ | |
| 230 | + private void serchpageData(SearchData skey) { | |
| 231 | + | |
| 232 | + DebugProcess.debuglog_set(); | |
| 233 | + | |
| 232 | 234 | Reader reader; |
| 233 | 235 | try { |
| 234 | 236 | reader = new BufferedReader(new StringReader(pageData)); |
| @@ -243,5 +245,4 @@ | ||
| 243 | 245 | System.err.println(e); |
| 244 | 246 | } |
| 245 | 247 | } |
| 246 | - | |
| 247 | 248 | } |
| @@ -0,0 +1,193 @@ | ||
| 1 | +/* | |
| 2 | + * Copyright (C) 2014 kgto. | |
| 3 | + * | |
| 4 | + * This library is free software; you can redistribute it and/or | |
| 5 | + * modify it under the terms of the GNU Lesser General Public | |
| 6 | + * License as published by the Free Software Foundation; either | |
| 7 | + * version 2.1 of the License, or (at your option) any later version. | |
| 8 | + * | |
| 9 | + * This library is distributed in the hope that it will be useful, | |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 12 | + * Lesser General Public License for more details. | |
| 13 | + * | |
| 14 | + * You should have received a copy of the GNU Lesser General Public | |
| 15 | + * License along with this library; if not, write to the Free Software | |
| 16 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 17 | + * MA 02110-1301 USA | |
| 18 | + */ | |
| 19 | + | |
| 20 | +package WebScraping; | |
| 21 | + | |
| 22 | +import java.io.File; | |
| 23 | +import java.io.FileInputStream; | |
| 24 | +import java.io.FileNotFoundException; | |
| 25 | +import java.io.IOException; | |
| 26 | +import java.util.logging.FileHandler; | |
| 27 | +import java.util.logging.Formatter; | |
| 28 | +import java.util.logging.Handler; | |
| 29 | +import java.util.logging.Level; | |
| 30 | +import java.util.logging.LogManager; | |
| 31 | +import java.util.logging.LogRecord; | |
| 32 | +import java.util.logging.Logger; | |
| 33 | +import javax.swing.text.MutableAttributeSet; | |
| 34 | +import javax.swing.text.html.HTML; | |
| 35 | + | |
| 36 | +/** | |
| 37 | + * | |
| 38 | + * @author kgto | |
| 39 | + */ | |
| 40 | +public class DebugProcess { | |
| 41 | + | |
| 42 | + protected static final String configurationFilename = "Debug.prop"; | |
| 43 | + protected static final Logger logger = Logger.getLogger("WebScraping"); | |
| 44 | + | |
| 45 | + | |
| 46 | + public static void debuglog_set() { | |
| 47 | + try { | |
| 48 | + initLogConfiguration(); | |
| 49 | + | |
| 50 | + if(Level.ALL.equals(logger.getLevel())) { | |
| 51 | + logger.addHandler(new FileHandler("WebScraping%g.log", 100000, 2)); | |
| 52 | + } | |
| 53 | + setFomatter(); | |
| 54 | + | |
| 55 | + } catch (IOException ex) { | |
| 56 | + Logger.getLogger(DebugProcess.class.getName()).log(Level.SEVERE, null, ex); | |
| 57 | + } catch (SecurityException ex) { | |
| 58 | + Logger.getLogger(DebugProcess.class.getName()).log(Level.SEVERE, null, ex); | |
| 59 | + } | |
| 60 | + | |
| 61 | + } | |
| 62 | + | |
| 63 | + public static void debuglog_unset() { | |
| 64 | + | |
| 65 | + } | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + public static void htmlinfo(HTML.Tag tag, MutableAttributeSet attr, | |
| 70 | + String methodname, int count) { | |
| 71 | + | |
| 72 | + if(!Level.ALL.equals(logger.getLevel())) { | |
| 73 | + return; | |
| 74 | + } | |
| 75 | + | |
| 76 | + | |
| 77 | + char kbn = ' '; | |
| 78 | + if("handleStartTag".equals(methodname)) { | |
| 79 | + kbn = 'F'; | |
| 80 | + } | |
| 81 | + if("handleEndTag".equals(methodname)) { | |
| 82 | + kbn = 'E'; | |
| 83 | + } | |
| 84 | + if("handleSimpleTag".equals(methodname)) { | |
| 85 | + kbn = 'S'; | |
| 86 | + } | |
| 87 | + | |
| 88 | + StringBuilder strBuf = new StringBuilder(80); | |
| 89 | + strBuf.append(count).append(" : "); | |
| 90 | + strBuf.append(kbn).append(" : "); | |
| 91 | + strBuf.append(tag.toString()); | |
| 92 | + // 属性情報 | |
| 93 | + if(attr != null) { | |
| 94 | + if(attr.getAttributeCount() != 0) { | |
| 95 | + AttributeData handleAttrData = new AttributeData(); | |
| 96 | + handleAttrData.add(tag, attr); | |
| 97 | + for(int i = 0; i < handleAttrData.size; i++) { | |
| 98 | + strBuf.append(" ["); | |
| 99 | + strBuf.append(handleAttrData.getattrname(i)); | |
| 100 | + strBuf.append("]"); | |
| 101 | + strBuf.append(handleAttrData.getcount(i)); | |
| 102 | + strBuf.append(" = "); | |
| 103 | + strBuf.append(handleAttrData.getattrvalue(i)); | |
| 104 | + } | |
| 105 | + } | |
| 106 | + } | |
| 107 | + | |
| 108 | + logger.finest(strBuf.toString()); | |
| 109 | + } | |
| 110 | + | |
| 111 | + public static void htmlinfo(String str, String methodname) { | |
| 112 | + logger.finest(str); | |
| 113 | + } | |
| 114 | + | |
| 115 | + public static void htmlinfo(String str) { | |
| 116 | + logger.finest(str); | |
| 117 | + } | |
| 118 | + | |
| 119 | + public static void htmlinfo(char[] data, String methodname) { | |
| 120 | + String dat = new String(data); | |
| 121 | + logger.finest(dat); | |
| 122 | + } | |
| 123 | + | |
| 124 | + public static void htmlinfo(char[] data) { | |
| 125 | + String dat = new String(data); | |
| 126 | + logger.finest(dat); | |
| 127 | + } | |
| 128 | + | |
| 129 | + private static void initLogConfiguration() { | |
| 130 | + | |
| 131 | + File file = new File(configurationFilename); | |
| 132 | + try { | |
| 133 | + if(file.exists()) { | |
| 134 | + FileInputStream inputStream = new FileInputStream(file); | |
| 135 | + // 設定ファイルの読み込み | |
| 136 | + LogManager.getLogManager().readConfiguration(inputStream); | |
| 137 | + } | |
| 138 | + | |
| 139 | + } catch (FileNotFoundException ex) { | |
| 140 | + Logger.getLogger(DebugProcess.class.getName()).log(Level.SEVERE, null, ex); | |
| 141 | + } catch (IOException ex) { | |
| 142 | + Logger.getLogger(DebugProcess.class.getName()).log(Level.SEVERE, null, ex); | |
| 143 | + } | |
| 144 | + } | |
| 145 | + | |
| 146 | + private static void setFomatter() { | |
| 147 | + Handler[] handlers = logger.getHandlers(); | |
| 148 | + for(int i = 0 ; i < handlers.length ; i++) { | |
| 149 | + if(handlers[i] instanceof java.util.logging.FileHandler) { | |
| 150 | + handlers[i].setFormatter(new HtmlFormatter()); | |
| 151 | + } | |
| 152 | + } | |
| 153 | + } | |
| 154 | + | |
| 155 | +} | |
| 156 | + | |
| 157 | +class HtmlFormatter extends Formatter { | |
| 158 | + | |
| 159 | + @Override | |
| 160 | + public synchronized String format(final LogRecord aRecord) { | |
| 161 | + | |
| 162 | + final StringBuffer message = new StringBuffer(131); | |
| 163 | + | |
| 164 | + long millis = aRecord.getMillis(); | |
| 165 | + String time = String.format("%tF %<tT", millis); | |
| 166 | + | |
| 167 | + message.append(time); | |
| 168 | + message.append(' '); | |
| 169 | + | |
| 170 | + message.append(aRecord.getLevel()); | |
| 171 | + message.append('<'); | |
| 172 | + String methodName = aRecord.getSourceMethodName(); | |
| 173 | + message.append(methodName != null ? methodName : "N/A"); | |
| 174 | + message.append('>'); | |
| 175 | + | |
| 176 | + message.append(formatMessage(aRecord)); | |
| 177 | + message.append('\n'); | |
| 178 | + | |
| 179 | + Throwable throwable = aRecord.getThrown(); | |
| 180 | + if (throwable != null) { | |
| 181 | + message.append(throwable.toString()); | |
| 182 | + message.append('\n'); | |
| 183 | + for (StackTraceElement trace : throwable.getStackTrace()) { | |
| 184 | + message.append('\t'); | |
| 185 | + message.append(trace.toString()); | |
| 186 | + message.append('\n'); | |
| 187 | + } | |
| 188 | + } | |
| 189 | + return message.toString(); | |
| 190 | + | |
| 191 | + } | |
| 192 | + | |
| 193 | +} |