| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| |
| --> |
| <!-- Generated by Apache Maven Doxia at Oct 14, 2013 --> |
| <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| <head> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| <title>CPD Results</title> |
| <style type="text/css" media="all"> |
| @import url("./css/maven-base.css"); |
| @import url("./css/maven-theme.css"); |
| @import url("./css/site.css"); |
| </style> |
| <link rel="stylesheet" href="./css/print.css" type="text/css" media="print" /> |
| <meta name="Date-Revision-yyyymmdd" content="20131014" /> |
| <meta http-equiv="Content-Language" content="en" /> |
| </head> |
| <body class="composite"> |
| <div id="banner"> |
| <a href="../../" id="bannerLeft"> |
| <img src="images/ls-logo.jpg" alt="Apache Logging Services" /> |
| </a> |
| <a href=".." id="bannerRight"> |
| <img src="images/logo.jpg" alt="Apache log4j" /> |
| </a> |
| <div class="clear"> |
| <hr/> |
| </div> |
| </div> |
| <div id="breadcrumbs"> |
| |
| |
| <div class="xleft"> |
| <span id="publishDate">Last Published: 2013-10-14</span> |
| | <span id="projectVersion">Version: 1.2.17</span> |
| | <a href="http://www.apache.org/" class="externalLink" title="Apache">Apache</a> |
| > |
| <a href="../../" title="Logging Services">Logging Services</a> |
| > |
| <a href="../" title="log4j">log4j</a> |
| > |
| <a href="./" title="Extras">Extras</a> |
| </div> |
| <div class="xright"> |
| |
| </div> |
| <div class="clear"> |
| <hr/> |
| </div> |
| </div> |
| <div id="leftColumn"> |
| <div id="navcolumn"> |
| |
| |
| <h5>Get it</h5> |
| <ul> |
| <li class="none"> |
| <a href="download.html" title="Download">Download</a> |
| </li> |
| <li class="none"> |
| <a href="changes-report.html" title="Changes">Changes</a> |
| </li> |
| <li class="none"> |
| <a href="http://www.apache.org/licenses/" class="externalLink" title="License">License</a> |
| </li> |
| </ul> |
| <h5>About</h5> |
| <ul> |
| <li class="none"> |
| <a href="index.html" title="What is it?">What is it?</a> |
| </li> |
| <li class="none"> |
| <a href="roadmap.html" title="Roadmap">Roadmap</a> |
| </li> |
| <li class="none"> |
| <a href="apidocs/index.html" title="JavaDoc">JavaDoc</a> |
| </li> |
| </ul> |
| <h5>More</h5> |
| <ul> |
| <li class="none"> |
| <a href="../1.2/" title="Apache log4j 1.x">Apache log4j 1.x</a> |
| </li> |
| <li class="none"> |
| <a href="../2.x/" title="Apache log4j 2.x">Apache log4j 2.x</a> |
| </li> |
| </ul> |
| <h5>Community</h5> |
| <ul> |
| <li class="none"> |
| <a href="mail-lists.html" title="Mailing Lists">Mailing Lists</a> |
| </li> |
| <li class="none"> |
| <a href="issue-tracking.html" title="Issue Tracking">Issue Tracking</a> |
| </li> |
| </ul> |
| <h5>Project Documentation</h5> |
| <ul> |
| <li class="collapsed"> |
| <a href="project-info.html" title="Project Information">Project Information</a> |
| </li> |
| <li class="expanded"> |
| <a href="project-reports.html" title="Project Reports">Project Reports</a> |
| <ul> |
| <li class="none"> |
| <a href="changes-report.html" title="Changes Report">Changes Report</a> |
| </li> |
| <li class="none"> |
| <a href="pmd.html" title="PMD Report">PMD Report</a> |
| </li> |
| <li class="none"> |
| <strong>CPD Report</strong> |
| </li> |
| <li class="none"> |
| <a href="apidocs/index.html" title="JavaDocs">JavaDocs</a> |
| </li> |
| <li class="none"> |
| <a href="testapidocs/index.html" title="Test JavaDocs">Test JavaDocs</a> |
| </li> |
| <li class="none"> |
| <a href="rat-report.html" title="RAT Report">RAT Report</a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| <h5>Development</h5> |
| <ul> |
| <li class="none"> |
| <a href="source-repository.html" title="Repository">Repository</a> |
| </li> |
| <li class="none"> |
| <a href="dependencies.html" title="Dependencies">Dependencies</a> |
| </li> |
| <li class="none"> |
| <a href="integration.html" title="Continuous Integration">Continuous Integration</a> |
| </li> |
| </ul> |
| <h5>Apache</h5> |
| <ul> |
| <li class="none"> |
| <a href="http://www.apache.org" class="externalLink" title="Home">Home</a> |
| </li> |
| <li class="none"> |
| <a href="http://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship">Sponsorship</a> |
| </li> |
| <li class="none"> |
| <a href="http://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks">Thanks</a> |
| </li> |
| <li class="none"> |
| <a href="http://www.apache.org/security/" class="externalLink" title="Security">Security</a> |
| </li> |
| <li class="none"> |
| <a href="http://www.apachecon.com" class="externalLink" title="Conferences">Conferences</a> |
| </li> |
| </ul> |
| <a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"> |
| <img class="poweredBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /> |
| </a> |
| |
| |
| </div> |
| </div> |
| <div id="bodyColumn"> |
| <div id="contentBox"> |
| <div class="section"><h2>CPD Results<a name="CPD_Results"></a></h2><p>The following document contains the results of PMD's <a class="externalLink" href="http://pmd.sourceforge.net/cpd.html">CPD</a> 4.3.</p></div><div class="section"><h2>Duplications<a name="Duplications"></a></h2><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/extras/XSLTLayout.java</td><td>100</td></tr><tr class="a"><td>org/apache/log4j/xml/XSLTLayout.java</td><td>96</td></tr><tr class="b"><td colspan='2'><div><pre> implements org.apache.log4j.xml.UnrecognizedElementHandler { |
| /** |
| * Namespace for XSLT. |
| */ |
| private static final String XSLT_NS = "http://www.w3.org/1999/XSL/Transform"; |
| /** |
| * Namespace for log4j events. |
| */ |
| private static final String LOG4J_NS = "http://jakarta.apache.org/log4j/"; |
| /** |
| * Whether location information should be written. |
| */ |
| private boolean locationInfo = false; |
| /** |
| * media-type (mime type) extracted from XSLT transform. |
| */ |
| private String mediaType = "text/plain"; |
| /** |
| * Encoding extracted from XSLT transform. |
| */ |
| private Charset encoding; |
| /** |
| * Transformer factory. |
| */ |
| private SAXTransformerFactory transformerFactory; |
| /** |
| * XSLT templates. |
| */ |
| private Templates templates; |
| /** |
| * Output stream. |
| */ |
| private final ByteArrayOutputStream outputStream; |
| /** |
| * Whether throwable information should be ignored. |
| */ |
| private boolean ignoresThrowable = false; |
| /** |
| * Whether properties should be extracted. |
| */ |
| private boolean properties = true; |
| /** |
| * Whether activateOptions has been called. |
| */ |
| private boolean activated = false; |
| |
| /** |
| * DateFormat for UTC time. |
| */ |
| private final CachedDateFormat utcDateFormat; |
| |
| /** |
| * Default constructor. |
| * |
| */ |
| public XSLTLayout() { |
| outputStream = new ByteArrayOutputStream(); |
| transformerFactory = (SAXTransformerFactory) |
| TransformerFactory.newInstance(); |
| |
| SimpleDateFormat zdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); |
| zdf.setTimeZone(TimeZone.getTimeZone("UTC")); |
| utcDateFormat = new CachedDateFormat(zdf, 1000); |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public synchronized String getContentType() { |
| return mediaType; |
| } |
| |
| /** |
| * The <b>LocationInfo </b> option takes a boolean value. By default, it is |
| * set to false which means there will be no location information output by |
| * this layout. If the the option is set to true, then the file name and line |
| * number of the statement at the origin of the log statement will be output. |
| * |
| * <p> |
| * If you are embedding this layout within an {@link |
| * org.apache.log4j.net.SMTPAppender} then make sure to set the |
| * <b>LocationInfo </b> option of that appender as well. |
| * |
| * @param flag new value. |
| */ |
| public synchronized void setLocationInfo(final boolean flag) { |
| locationInfo = flag; |
| } |
| |
| /** |
| * Gets whether location info should be output. |
| * @return if location is output. |
| */ |
| public synchronized boolean getLocationInfo() { |
| return locationInfo; |
| } |
| |
| /** |
| * Sets whether MDC key-value pairs should be output, default false. |
| * @param flag new value. |
| */ |
| public synchronized void setProperties(final boolean flag) { |
| properties = flag; |
| } |
| |
| /** |
| * Gets whether MDC key-value pairs should be output. |
| * @return true if MDC key-value pairs are output. |
| */ |
| public synchronized boolean getProperties() { |
| return properties; |
| } |
| |
| |
| /** {@inheritDoc} */ |
| public synchronized void activateOptions() { |
| if (templates == null) { |
| try { |
| InputStream is = XSLTLayout.class.getResourceAsStream("default.xslt"); |
| StreamSource ss = new StreamSource(is); |
| templates = transformerFactory.newTemplates(ss); |
| encoding = Charset.forName("US-ASCII"); |
| mediaType = "text/plain"; |
| } catch (Exception ex) { |
| LogLog.error("Error loading default.xslt", ex); |
| } |
| } |
| activated = true; |
| } |
| |
| /** |
| * Gets whether throwables should not be output. |
| * @return true if throwables should not be output. |
| */ |
| public synchronized boolean ignoresThrowable() { |
| return ignoresThrowable; |
| } |
| |
| /** |
| * Sets whether throwables should not be output. |
| * @param ignoresThrowable if true, throwables should not be output. |
| */ |
| public synchronized void setIgnoresThrowable(boolean ignoresThrowable) { |
| this.ignoresThrowable = ignoresThrowable; |
| } |
| |
| |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public synchronized String format(final LoggingEvent event) { |
| if (!activated) { |
| activateOptions(); |
| } |
| if (templates != null && encoding != null) { |
| outputStream.reset(); |
| |
| try { |
| TransformerHandler transformer = |
| transformerFactory.newTransformerHandler(templates); |
| |
| transformer.setResult(new StreamResult(outputStream)); |
| transformer.startDocument(); |
| |
| // |
| // event element |
| // |
| AttributesImpl attrs = new AttributesImpl(); |
| attrs.addAttribute(null, "logger", "logger", |
| "CDATA", event.getLoggerName()); |
| attrs.addAttribute(null, "timestamp", "timestamp", |
| "CDATA", Long.toString(event.timeStamp)); |
| attrs.addAttribute(null, "level", "level", |
| "CDATA", event.getLevel().toString()); |
| attrs.addAttribute(null, "thread", "thread", |
| "CDATA", event.getThreadName()); |
| StringBuffer buf = new StringBuffer(); |
| utcDateFormat.format(event.timeStamp, buf); |
| attrs.addAttribute(null, "time", "time", "CDATA", buf.toString()); |
| |
| |
| transformer.startElement(LOG4J_NS, "event", "event", attrs); |
| attrs.clear(); |
| |
| // |
| // message element |
| // |
| transformer.startElement(LOG4J_NS, "message", "message", attrs); |
| String msg = event.getRenderedMessage(); |
| if (msg != null && msg.length() > 0) { |
| transformer.characters(msg.toCharArray(), 0, msg.length()); |
| } |
| transformer.endElement(LOG4J_NS, "message", "message"); |
| |
| // |
| // NDC element |
| // |
| String ndc = event.getNDC(); |
| if (ndc != null) { |
| transformer.startElement(LOG4J_NS, "NDC", "NDC", attrs); |
| char[] ndcChars = ndc.toCharArray(); |
| transformer.characters(ndcChars, 0, ndcChars.length); |
| transformer.endElement(LOG4J_NS, "NDC", "NDC"); |
| } |
| |
| // |
| // throwable element unless suppressed |
| // |
| if (!ignoresThrowable) { |
| String[] s = event.getThrowableStrRep(); |
| if (s != null) { |
| transformer.startElement(LOG4J_NS, "throwable", |
| "throwable", attrs); |
| char[] nl = new char[] { '\n' }; |
| for (int i = 0; i < s.length; i++) { |
| char[] line = s[i].toCharArray(); |
| transformer.characters(line, 0, line.length); |
| transformer.characters(nl, 0, nl.length); |
| } |
| transformer.endElement(LOG4J_NS, "throwable", "throwable"); |
| } |
| } |
| |
| // |
| // location info unless suppressed |
| // |
| // |
| if (locationInfo) { |
| LocationInfo locationInfo = event.getLocationInformation(); |
| attrs.addAttribute(null, "class", "class", "CDATA", |
| locationInfo.getClassName()); |
| attrs.addAttribute(null, "method", "method", "CDATA", |
| locationInfo.getMethodName()); |
| attrs.addAttribute(null, "file", "file", "CDATA", |
| locationInfo.getFileName()); |
| attrs.addAttribute(null, "line", "line", "CDATA", |
| locationInfo.getLineNumber()); |
| transformer.startElement(LOG4J_NS, "locationInfo", |
| "locationInfo", attrs); |
| transformer.endElement(LOG4J_NS, "locationInfo", |
| "locationInfo"); |
| } |
| |
| if (properties) { |
| // |
| // write MDC contents out as properties element |
| // |
| Set mdcKeySet = MDCKeySetExtractor.INSTANCE.getPropertyKeySet(event); |
| |
| if ((mdcKeySet != null) && (mdcKeySet.size() > 0)) { |
| attrs.clear(); |
| transformer.startElement(LOG4J_NS, |
| "properties", "properties", attrs); |
| Object[] keys = mdcKeySet.toArray(); |
| Arrays.sort(keys); |
| for (int i = 0; i < keys.length; i++) { |
| String key = keys[i].toString(); |
| Object val = event.getMDC(key); |
| attrs.clear(); |
| attrs.addAttribute(null, "name", "name", "CDATA", key); |
| attrs.addAttribute(null, "value", "value", |
| "CDATA", val.toString()); |
| transformer.startElement(LOG4J_NS, |
| "data", "data", attrs); |
| transformer.endElement(LOG4J_NS, "data", "data"); |
| } |
| } |
| } |
| |
| |
| transformer.endElement(LOG4J_NS, "event", "event"); |
| transformer.endDocument(); |
| |
| String body = encoding.decode( |
| ByteBuffer.wrap(outputStream.toByteArray())).toString(); |
| outputStream.reset(); |
| // |
| // must remove XML declaration since it may |
| // result in erroneous encoding info |
| // if written by FileAppender in a different encoding |
| if (body.startsWith("<?xml ")) { |
| int endDecl = body.indexOf("?>"); |
| if (endDecl != -1) { |
| for(endDecl += 2; |
| endDecl < body.length() && |
| (body.charAt(endDecl) == '\n' || body.charAt(endDecl) == '\r'); |
| endDecl++); |
| return body.substring(endDecl); |
| } |
| } |
| return body; |
| } catch (Exception ex) { |
| LogLog.error("Error during transformation", ex); |
| return ex.toString(); |
| } |
| } |
| return "No valid transform or encoding specified."; |
| } |
| |
| /** |
| * Sets XSLT transform. |
| * @param xsltdoc DOM document containing XSLT transform source, |
| * may be modified. |
| * @throws TransformerConfigurationException if transformer can not be |
| * created. |
| */ |
| public void setTransform(final Document xsltdoc) |
| throws TransformerConfigurationException { |
| // |
| // scan transform source for xsl:output elements |
| // and extract encoding, media (mime) type and output method |
| // |
| String encodingName = null; |
| mediaType = null; |
| String method = null; |
| NodeList nodes = xsltdoc.getElementsByTagNameNS( |
| XSLT_NS, |
| "output"); |
| for(int i = 0; i < nodes.getLength(); i++) { |
| Element outputElement = (Element) nodes.item(i); |
| if (method == null || method.length() == 0) { |
| method = outputElement.getAttributeNS(null, "method"); |
| } |
| if (encodingName == null || encodingName.length() == 0) { |
| encodingName = outputElement.getAttributeNS(null, "encoding"); |
| } |
| if (mediaType == null || mediaType.length() == 0) { |
| mediaType = outputElement.getAttributeNS(null, "media-type"); |
| } |
| } |
| |
| if (mediaType == null || mediaType.length() == 0) { |
| if ("html".equals(method)) { |
| mediaType = "text/html"; |
| } else if ("xml".equals(method)) { |
| mediaType = "text/xml"; |
| } else { |
| mediaType = "text/plain"; |
| } |
| } |
| |
| // |
| // if encoding was not specified, |
| // add xsl:output encoding=US-ASCII to XSLT source |
| // |
| if (encodingName == null || encodingName.length() == 0) { |
| Element transformElement = xsltdoc.getDocumentElement(); |
| Element outputElement = xsltdoc. |
| createElementNS(XSLT_NS, "output"); |
| outputElement.setAttributeNS(null, "encoding", "US-ASCII"); |
| transformElement.insertBefore(outputElement, transformElement.getFirstChild()); |
| encoding = Charset.forName("US-ASCII"); |
| } else { |
| encoding = Charset.forName(encodingName); |
| } |
| |
| DOMSource transformSource = new DOMSource(xsltdoc); |
| |
| templates = transformerFactory.newTemplates(transformSource); |
| |
| } |
| |
| /** |
| * {@inheritDoc} |
| */ |
| public boolean parseUnrecognizedElement(final Element element, |
| final Properties props) |
| throws Exception { |
| if (XSLT_NS.equals(element.getNamespaceURI()) || |
| element.getNodeName().indexOf("transform") != -1 || |
| element.getNodeName().indexOf("stylesheet") != -1) { |
| // |
| // DOMConfigurator typically not namespace aware |
| // serialize tree and reparse. |
| ByteArrayOutputStream os = new ByteArrayOutputStream(); |
| DOMSource source = new DOMSource(element); |
| TransformerFactory transformerFactory = TransformerFactory.newInstance(); |
| Transformer transformer = transformerFactory.newTransformer(); |
| transformer.transform(source, new StreamResult(os)); |
| |
| ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); |
| DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); |
| domFactory.setNamespaceAware(true); |
| Document xsltdoc = domFactory.newDocumentBuilder().parse(is); |
| setTransform(xsltdoc); |
| return true; |
| } |
| return false; |
| } |
| |
| |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/extras/UtilLoggingLevel.java</td><td>57</td></tr><tr class="a"><td>org/apache/log4j/receivers/helpers/UtilLoggingLevel.java</td><td>54</td></tr><tr class="b"><td colspan='2'><div><pre> public static final int CONFIG_INT = 14000; |
| /** |
| * Numerical value for FINE. |
| */ |
| public static final int FINE_INT = 13000; |
| /** |
| * Numerical value for FINER. |
| */ |
| public static final int FINER_INT = 12000; |
| /** |
| * Numerical value for FINEST. |
| */ |
| public static final int FINEST_INT = 11000; |
| /** |
| * Numerical value for UNKNOWN. |
| */ |
| public static final int UNKNOWN_INT = 10000; |
| |
| /** |
| * SEVERE. |
| */ |
| public static final UtilLoggingLevel SEVERE = |
| new UtilLoggingLevel(SEVERE_INT, "SEVERE", 0); |
| /** |
| * WARNING. |
| */ |
| public static final UtilLoggingLevel WARNING = |
| new UtilLoggingLevel(WARNING_INT, "WARNING", 4); |
| /** |
| * INFO. |
| */ |
| public static final UtilLoggingLevel INFO = |
| new UtilLoggingLevel(INFO_INT, "INFO", 5); |
| /** |
| * CONFIG. |
| */ |
| public static final UtilLoggingLevel CONFIG = |
| new UtilLoggingLevel(CONFIG_INT, "CONFIG", 6); |
| /** |
| * FINE. |
| */ |
| public static final UtilLoggingLevel FINE = |
| new UtilLoggingLevel(FINE_INT, "FINE", 7); |
| /** |
| * FINER. |
| */ |
| public static final UtilLoggingLevel FINER = |
| new UtilLoggingLevel(FINER_INT, "FINER", 8); |
| /** |
| * FINEST. |
| */ |
| public static final UtilLoggingLevel FINEST = |
| new UtilLoggingLevel(FINEST_INT, "FINEST", 9); |
| |
| /** |
| * Create new instance. |
| * @param level numeric value for level. |
| * @param levelStr symbolic name for level. |
| * @param syslogEquivalent Equivalent syslog severity. |
| */ |
| protected UtilLoggingLevel(final int level, |
| final String levelStr, |
| final int syslogEquivalent) { |
| super(level, levelStr, syslogEquivalent); |
| } |
| |
| /** |
| * Convert an integer passed as argument to a level. If the |
| * conversion fails, then this method returns the specified default. |
| * @param val numeric value. |
| * @param defaultLevel level to be returned if no level matches |
| * numeric value. |
| * @return matching level or default level. |
| */ |
| public static UtilLoggingLevel toLevel(final int val, |
| final UtilLoggingLevel defaultLevel) { |
| switch (val) { |
| case SEVERE_INT: |
| return SEVERE; |
| |
| case WARNING_INT: |
| return WARNING; |
| |
| case INFO_INT: |
| return INFO; |
| |
| case CONFIG_INT: |
| return CONFIG; |
| |
| case FINE_INT: |
| return FINE; |
| |
| case FINER_INT: |
| return FINER; |
| |
| case FINEST_INT: |
| return FINEST; |
| |
| default: |
| return defaultLevel; |
| } |
| } |
| |
| /** |
| * Gets level matching numeric value. |
| * @param val numeric value. |
| * @return matching level or UtilLoggerLevel.FINEST if no match. |
| */ |
| public static Level toLevel(final int val) { |
| return toLevel(val, FINEST); |
| } |
| |
| /** |
| * Gets list of supported levels. |
| * @return list of supported levels. |
| */ |
| public static List getAllPossibleLevels() { |
| ArrayList list = new ArrayList(); |
| list.add(FINE); |
| list.add(FINER); |
| list.add(FINEST); |
| list.add(INFO); |
| list.add(CONFIG); |
| list.add(WARNING); |
| list.add(SEVERE); |
| return list; |
| } |
| |
| /** |
| * Get level with specified symbolic name. |
| * @param s symbolic name. |
| * @return matching level or Level.DEBUG if no match. |
| */ |
| public static Level toLevel(final String s) { |
| return toLevel(s, Level.DEBUG); |
| } |
| |
| |
| /** |
| * Get level with specified symbolic name. |
| * @param sArg symbolic name. |
| * @param defaultLevel level to return if no match. |
| * @return matching level or defaultLevel if no match. |
| */ |
| public static Level toLevel(final String sArg, |
| final Level defaultLevel) { |
| if (sArg == null) { |
| return defaultLevel; |
| } |
| |
| String s = sArg.toUpperCase(); |
| |
| if (s.equals("SEVERE")) { |
| return SEVERE; |
| } |
| |
| //if(s.equals("FINE")) return Level.FINE; |
| if (s.equals("WARNING")) { |
| return WARNING; |
| } |
| |
| if (s.equals("INFO")) { |
| return INFO; |
| } |
| |
| if (s.equals("CONFI")) { |
| return CONFIG; |
| } |
| |
| if (s.equals("FINE")) { |
| return FINE; |
| } |
| |
| if (s.equals("FINER")) { |
| return FINER; |
| } |
| |
| if (s.equals("FINEST")) { |
| return FINEST; |
| } |
| return defaultLevel; |
| } |
| |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/receivers/xml/UtilLoggingXMLDecoder.java</td><td>159</td></tr><tr class="a"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>164</td></tr><tr class="b"><td colspan='2'><div><pre> InputSource inputSource = |
| new InputSource(new StringReader(buf.toString())); |
| document = docBuilder.parse(inputSource); |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| |
| return document; |
| } |
| |
| /** |
| * Decodes a File into a Vector of LoggingEvents. |
| * @param url the url of a file containing events to decode |
| * @return Vector of LoggingEvents |
| * @throws IOException if IO error during processing. |
| */ |
| public Vector decode(final URL url) throws IOException { |
| LineNumberReader reader; |
| boolean isZipFile = url.getPath().toLowerCase().endsWith(".zip"); |
| InputStream inputStream; |
| if (isZipFile) { |
| inputStream = new ZipInputStream(url.openStream()); |
| //move stream to next entry so we can read it |
| ((ZipInputStream)inputStream).getNextEntry(); |
| } else { |
| inputStream = url.openStream(); |
| } |
| if (owner != null) { |
| reader = new LineNumberReader( |
| new InputStreamReader( |
| new ProgressMonitorInputStream(owner, |
| "Loading " + url , inputStream), ENCODING)); |
| } else { |
| reader = new LineNumberReader(new InputStreamReader(inputStream, ENCODING)); |
| } |
| Vector v = new Vector(); |
| |
| String line; |
| Vector events; |
| try { |
| while ((line = reader.readLine()) != null) { |
| StringBuffer buffer = new StringBuffer(line); |
| for (int i = 0; i < 1000; i++) { |
| buffer.append(reader.readLine()).append("\n"); |
| } |
| events = decodeEvents(buffer.toString()); |
| if (events != null) { |
| v.addAll(events); |
| } |
| } |
| } finally { |
| partialEvent = null; |
| try { |
| if (reader != null) { |
| reader.close(); |
| } |
| } catch (Exception e) { |
| e.printStackTrace(); |
| } |
| } |
| return v; |
| } |
| |
| /** |
| * Decodes a String representing a number of events into a |
| * Vector of LoggingEvents. |
| * @param document to decode events from |
| * @return Vector of LoggingEvents |
| */ |
| public Vector decodeEvents(final String document) { |
| |
| if (document != null) { |
| |
| if (document.trim().equals("")) { |
| return null; |
| } |
| |
| String newDoc;</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/receivers/xml/UtilLoggingXMLDecoder.java</td><td>237</td></tr><tr class="a"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>240</td></tr><tr class="b"><td colspan='2'><div><pre> String newPartialEvent = null; |
| //separate the string into the last portion ending with </record> |
| // (which will be processed) and the partial event which |
| // will be combined and processed in the next section |
| |
| //if the document does not contain a record end, |
| // append it to the partial event string |
| if (document.lastIndexOf(RECORD_END) == -1) { |
| partialEvent = partialEvent + document; |
| return null; |
| } |
| |
| if (document.lastIndexOf(RECORD_END) + RECORD_END.length() |
| < document.length()) { |
| newDoc = document.substring(0, |
| document.lastIndexOf(RECORD_END) + RECORD_END.length()); |
| newPartialEvent = document.substring( |
| document.lastIndexOf(RECORD_END) + RECORD_END.length()); |
| } else { |
| newDoc = document; |
| } |
| if (partialEvent != null) { |
| newDoc = partialEvent + newDoc; |
| } |
| partialEvent = newPartialEvent; |
| |
| Document doc = parse(newDoc); |
| if (doc == null) { |
| return null; |
| } |
| return decodeEvents(doc); |
| } |
| return null; |
| } |
| |
| /** |
| * Converts the string data into an XML Document, and then soaks out the |
| * relevant bits to form a new LoggingEvent instance which can be used |
| * by any Log4j element locally. |
| * @param data XML fragment |
| * @return a single LoggingEvent or null |
| */ |
| public LoggingEvent decode(final String data) { |
| Document document = parse(data); |
| |
| if (document == null) { |
| return null; |
| } |
| |
| Vector events = decodeEvents(document); |
| |
| if (events.size() > 0) { |
| return (LoggingEvent) events.firstElement(); |
| } |
| |
| return null; |
| } |
| |
| /** |
| * Given a Document, converts the XML into a Vector of LoggingEvents. |
| * @param document XML document |
| * @return Vector of LoggingEvents |
| */ |
| private Vector decodeEvents(final Document document) { |
| Vector events = new Vector();</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rule/AndRule.java</td><td>101</td></tr><tr class="a"><td>org/apache/log4j/rule/OrRule.java</td><td>101</td></tr><tr class="b"><td colspan='2'><div><pre> if (result) { |
| for (Iterator iter = tempMatches1.entrySet().iterator();iter.hasNext();) { |
| Map.Entry entry = (Map.Entry)iter.next(); |
| Object key = entry.getKey(); |
| Set value = (Set)entry.getValue(); |
| Set mainSet = (Set) matches.get(key); |
| if (mainSet == null) { |
| mainSet = new HashSet(); |
| matches.put(key, mainSet); |
| } |
| mainSet.addAll(value); |
| } |
| for (Iterator iter = tempMatches2.entrySet().iterator();iter.hasNext();) { |
| Map.Entry entry = (Map.Entry)iter.next(); |
| Object key = entry.getKey(); |
| Set value = (Set)entry.getValue(); |
| Set mainSet = (Set) matches.get(key); |
| if (mainSet == null) { |
| mainSet = new HashSet(); |
| matches.put(key, mainSet); |
| } |
| mainSet.addAll(value); |
| } |
| } |
| return result; |
| } |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rule/LevelEqualsRule.java</td><td>61</td></tr><tr class="a"><td>org/apache/log4j/rule/NotLevelEqualsRule.java</td><td>61</td></tr><tr class="b"><td colspan='2'><div><pre> private LevelEqualsRule(final Level level) { |
| super(); |
| this.level = level; |
| } |
| |
| /** |
| * Populate list of levels. |
| */ |
| private static void populateLevels() { |
| levelList = new LinkedList(); |
| |
| levelList.add(Level.FATAL.toString()); |
| levelList.add(Level.ERROR.toString()); |
| levelList.add(Level.WARN.toString()); |
| levelList.add(Level.INFO.toString()); |
| levelList.add(Level.DEBUG.toString()); |
| Level trace = Level.toLevel(5000, null); |
| if (trace != null) { |
| levelList.add(trace.toString()); |
| } |
| } |
| |
| /** |
| * Create new rule. |
| * @param value name of level. |
| * @return instance of LevelEqualsRule. |
| */ |
| public static Rule getRule(final String value) { |
| Level thisLevel; |
| if (levelList.contains(value.toUpperCase())) { |
| thisLevel = Level.toLevel(value.toUpperCase()); |
| } else { |
| thisLevel = UtilLoggingLevel.toLevel(value.toUpperCase()); |
| } |
| |
| return new LevelEqualsRule(thisLevel);</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rule/LevelEqualsRule.java</td><td>106</td></tr><tr class="a"><td>org/apache/log4j/rule/NotLevelEqualsRule.java</td><td>106</td></tr><tr class="b"><td colspan='2'><div><pre> boolean result = (level.toInt() == eventLevel.toInt()); |
| if (result && matches != null) { |
| Set entries = (Set) matches.get(LoggingEventFieldResolver.LEVEL_FIELD); |
| if (entries == null) { |
| entries = new HashSet(); |
| matches.put(LoggingEventFieldResolver.LEVEL_FIELD, entries); |
| } |
| entries.add(eventLevel); |
| } |
| return result; |
| } |
| |
| /** |
| * Deserialize the state of the object. |
| * |
| * @param in object input stream. |
| * |
| * @throws IOException if error in reading stream for deserialization. |
| */ |
| private void readObject(final java.io.ObjectInputStream in) |
| throws IOException { |
| populateLevels(); |
| boolean isUtilLogging = in.readBoolean(); |
| int levelInt = in.readInt(); |
| if (isUtilLogging) { |
| level = UtilLoggingLevel.toLevel(levelInt); |
| } else { |
| level = Level.toLevel(levelInt); |
| } |
| } |
| |
| /** |
| * Serialize the state of the object. |
| * |
| * @param out object output stream. |
| * |
| * @throws IOException if error in writing stream during serialization. |
| */ |
| private void writeObject(final java.io.ObjectOutputStream out) |
| throws IOException { |
| out.writeBoolean(level instanceof UtilLoggingLevel); |
| out.writeInt(level.toInt()); |
| } |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/extras/SoundAppender.java</td><td>47</td></tr><tr class="a"><td>org/apache/log4j/varia/SoundAppender.java</td><td>44</td></tr><tr class="b"><td colspan='2'><div><pre>public final class SoundAppender extends AppenderSkeleton { |
| |
| private AudioClip clip; |
| private String audioURL; |
| |
| public SoundAppender() { |
| } |
| |
| /** |
| * Attempt to initialize the appender by creating a reference to an AudioClip. |
| * |
| * Will log a message if format is not supported, file not found, etc. |
| * |
| */ |
| public void activateOptions() { |
| /* |
| * AudioSystem.getAudioInputStream requires jdk 1.3, |
| * so we use applet.newaudioclip instead |
| * |
| */ |
| try { |
| clip = Applet.newAudioClip(new URL(audioURL)); |
| } catch (MalformedURLException mue) { |
| LogLog.error("unable to initialize SoundAppender", mue);} |
| if (clip == null) { |
| LogLog.error("Unable to initialize SoundAppender"); |
| } |
| } |
| |
| /** |
| * Accessor |
| * |
| * @return audio file |
| */ |
| public String getAudioURL() { |
| return audioURL; |
| } |
| |
| /** |
| * Mutator - common format for a file-based url: |
| * file:///c:/path/someaudioclip.wav |
| * |
| * @param audioURL |
| */ |
| public void setAudioURL(String audioURL) { |
| this.audioURL = audioURL; |
| } |
| |
| /** |
| * Play the sound if an event is being processed |
| */ |
| protected void append(LoggingEvent event) { |
| if (clip != null) { |
| clip.play(); |
| } |
| } |
| |
| public void close() { |
| //nothing to do |
| } |
| |
| /** |
| * Gets whether appender requires a layout. |
| * @return false |
| */ |
| public boolean requiresLayout() { |
| return false; |
| } |
| |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rolling/helper/GZCompressAction.java</td><td>60</td></tr><tr class="a"><td>org/apache/log4j/rolling/helper/ZipCompressAction.java</td><td>61</td></tr><tr class="b"><td colspan='2'><div><pre> public GZCompressAction( |
| final File source, final File destination, final boolean deleteSource) { |
| if (source == null) { |
| throw new NullPointerException("source"); |
| } |
| |
| if (destination == null) { |
| throw new NullPointerException("destination"); |
| } |
| |
| this.source = source; |
| this.destination = destination; |
| this.deleteSource = deleteSource; |
| } |
| |
| /** |
| * Compress. |
| * @return true if successfully compressed. |
| * @throws IOException on IO exception. |
| */ |
| public boolean execute() throws IOException { |
| return execute(source, destination, deleteSource); |
| } |
| |
| /** |
| * Compress a file. |
| * |
| * @param source file to compress, may not be null. |
| * @param destination compressed file, may not be null. |
| * @param deleteSource if true, attempt to delete file on completion. Failure to delete |
| * does not cause an exception to be thrown or affect return value. |
| * @return true if source file compressed. |
| * @throws IOException on IO exception. |
| */ |
| public static boolean execute( |
| final File source, final File destination, final boolean deleteSource) |
| throws IOException { |
| if (source.exists()) { |
| FileInputStream fis = new FileInputStream(source); |
| FileOutputStream fos = new FileOutputStream(destination);</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/receivers/net/MulticastAppender.java</td><td>87</td></tr><tr class="a"><td>org/apache/log4j/receivers/net/UDPAppender.java</td><td>107</td></tr><tr class="b"><td colspan='2'><div><pre> super(false); |
| } |
| |
| /** |
| Open the multicast sender for the <b>RemoteHost</b> and <b>Port</b>. |
| */ |
| public void activateOptions() { |
| try { |
| hostname = InetAddress.getLocalHost().getHostName(); |
| } catch (UnknownHostException uhe) { |
| try { |
| hostname = InetAddress.getLocalHost().getHostAddress(); |
| } catch (UnknownHostException uhe2) { |
| hostname = "unknown"; |
| } |
| } |
| |
| //allow system property of application to be primary |
| if (application == null) { |
| application = System.getProperty(Constants.APPLICATION_KEY); |
| } else { |
| if (System.getProperty(Constants.APPLICATION_KEY) != null) { |
| application = application + "-" + System.getProperty(Constants.APPLICATION_KEY); |
| } |
| } |
| |
| if(remoteHost != null) { |
| address = getAddressByName(remoteHost);</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>356</td></tr><tr class="a"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>396</td></tr><tr class="b"><td colspan='2'><div><pre> NodeList propertyList = list.item(y).getChildNodes(); |
| int propertyLength = propertyList.getLength(); |
| |
| for (int i = 0; i < propertyLength; i++) { |
| String propertyTag = propertyList.item(i).getNodeName(); |
| |
| if (propertyTag.equalsIgnoreCase("log4j:data")) { |
| Node property = propertyList.item(i); |
| String name = |
| property.getAttributes().getNamedItem("name").getNodeValue(); |
| String value = |
| property.getAttributes().getNamedItem("value").getNodeValue(); |
| properties.put(name, value); |
| } |
| } |
| } |
| |
| if (tagName.equalsIgnoreCase("log4j:throwable")) {</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rolling/RollingFileAppender.java</td><td>246</td></tr><tr class="a"><td>org/apache/log4j/rolling/RollingFileAppender.java</td><td>294</td></tr><tr class="b"><td colspan='2'><div><pre> closeWriter(); |
| |
| boolean success = true; |
| |
| if (rollover.getSynchronous() != null) { |
| success = false; |
| |
| try { |
| success = rollover.getSynchronous().execute(); |
| } catch (Exception ex) { |
| exception = ex; |
| } |
| } |
| |
| if (success) { |
| if (rollover.getAppend()) { |
| fileLength = new File(rollover.getActiveFileName()).length(); |
| } else { |
| fileLength = 0; |
| } |
| |
| if (rollover.getAsynchronous() != null) { |
| lastRolloverAsyncAction = rollover.getAsynchronous(); |
| new Thread(lastRolloverAsyncAction).start(); |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/receivers/xml/UtilLoggingXMLDecoder.java</td><td>407</td></tr><tr class="a"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>426</td></tr><tr class="b"><td colspan='2'><div><pre> } |
| } |
| |
| LocationInfo info; |
| if ((fileName != null) |
| || (className != null) |
| || (methodName != null) |
| || (lineNumber != null)) { |
| info = new LocationInfo(fileName, className, methodName, lineNumber); |
| } else { |
| info = LocationInfo.NA_LOCATION_INFO; |
| } |
| |
| ThrowableInformation throwableInfo = null; |
| if (exception != null) { |
| throwableInfo = new ThrowableInformation(exception); |
| } |
| |
| LoggingEvent loggingEvent = new LoggingEvent(null, |
| logger, timeStamp, level, message, |
| threadName, |
| throwableInfo, |
| ndc, |
| info, |
| properties); |
| |
| events.add(loggingEvent);</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="a"><th>File</th><th>Line</th></tr><tr class="b"><td>org/apache/log4j/rule/LevelEqualsRule.java</td><td>64</td></tr><tr class="a"><td>org/apache/log4j/rule/LevelInequalityRule.java</td><td>57</td></tr><tr class="b"><td>org/apache/log4j/rule/NotLevelEqualsRule.java</td><td>64</td></tr><tr class="a"><td colspan='2'><div><pre> } |
| |
| /** |
| * Populate list of levels. |
| */ |
| private static void populateLevels() { |
| levelList = new LinkedList(); |
| |
| levelList.add(Level.FATAL.toString()); |
| levelList.add(Level.ERROR.toString()); |
| levelList.add(Level.WARN.toString()); |
| levelList.add(Level.INFO.toString()); |
| levelList.add(Level.DEBUG.toString()); |
| Level trace = Level.toLevel(5000, null); |
| if (trace != null) { |
| levelList.add(trace.toString()); |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="b"><th>File</th><th>Line</th></tr><tr class="a"><td>org/apache/log4j/receivers/xml/UtilLoggingXMLDecoder.java</td><td>435</td></tr><tr class="b"><td>org/apache/log4j/receivers/xml/XMLDecoder.java</td><td>462</td></tr><tr class="a"><td colspan='2'><div><pre> } |
| return events; |
| } |
| |
| /** |
| * Get contents of CDATASection. |
| * @param n CDATASection |
| * @return text content of all text or CDATA children of node. |
| */ |
| private String getCData(final Node n) { |
| StringBuffer buf = new StringBuffer(); |
| NodeList nl = n.getChildNodes(); |
| |
| for (int x = 0; x < nl.getLength(); x++) { |
| Node innerNode = nl.item(x); |
| |
| if ( |
| (innerNode.getNodeType() == Node.TEXT_NODE) |
| || (innerNode.getNodeType() == Node.CDATA_SECTION_NODE)) { |
| buf.append(innerNode.getNodeValue()); |
| } |
| } |
| |
| return buf.toString(); |
| } |
| }</pre></div></td></tr></table><table border="0" class="bodyTable"><tr class="b"><th>File</th><th>Line</th></tr><tr class="a"><td>org/apache/log4j/receivers/net/SocketNode13.java</td><td>201</td></tr><tr class="b"><td>org/apache/log4j/receivers/net/XMLSocketNode.java</td><td>175</td></tr><tr class="a"><td colspan='2'><div><pre> } |
| } |
| } catch (java.io.EOFException e) { |
| getLogger().info("Caught java.io.EOFException closing connection."); |
| listenerException = e; |
| } catch (java.net.SocketException e) { |
| getLogger().info("Caught java.net.SocketException closing connection."); |
| listenerException = e; |
| } catch (IOException e) { |
| getLogger().info("Caught java.io.IOException: " + e); |
| getLogger().info("Closing connection."); |
| listenerException = e; |
| } catch (Exception e) { |
| getLogger().error("Unexpected exception. Closing connection.", e); |
| listenerException = e; |
| } |
| } |
| |
| // close the socket |
| try { |
| if (ois != null) {</pre></div></td></tr></table></div> |
| </div> |
| </div> |
| <div class="clear"> |
| <hr/> |
| </div> |
| <div id="footer"> |
| <div class="xleft">Copyright © 2013 |
| <a href="http://www.apache.org/">The Apache Software Foundation</a>. |
| |
| |
| Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache Software License, Version 2.0</a>.</div> |
| <div class="xleft">Apache Extras for Apache log4j, Apache log4j, Apache, the Apache feather logo, |
| the Apache Logging Services project logo, the log4j logo, and the Built by Maven logo are trademarks of The Apache Software Foundation.</div> |
| <div class="clear"> |
| <hr/> |
| </div> |
| </div> |
| </body> |
| </html> |