Java Code Examples for org.apache.log4j.helpers.Transform#escapeTags()

The following examples show how to use org.apache.log4j.helpers.Transform#escapeTags() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HTMLLayout.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public String format(LoggingEvent event) {

		if (sbuf.capacity() > MAX_CAPACITY) {
			sbuf = new StringBuffer(BUF_SIZE);
		} else {
			sbuf.setLength(0);
		}

		sbuf.append(Layout.LINE_SEP + "<tr>" + Layout.LINE_SEP);

		sbuf.append("<td>");
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		sbuf.append(df.format(new Date()));
		sbuf.append("</td>" + Layout.LINE_SEP);

		/*
		 * String escapedThread = Transform.escapeTags(event.getThreadName());
		 * sbuf.append("<td title=\"" + escapedThread + " thread\">");
		 * sbuf.append(escapedThread); sbuf.append("</td>" + Layout.LINE_SEP);
		 */

		sbuf.append("<td title=\"Level\">");
		if (event.getLevel().equals(Level.DEBUG)) {
			sbuf.append("<font color=\"#339933\">");
			sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
			sbuf.append("</font>");
		} else if (event.getLevel().isGreaterOrEqual(Level.WARN)) {
			sbuf.append("<font color=\"#993300\"><strong>");
			sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
			sbuf.append("</strong></font>");
		} else {
			sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
		}
		sbuf.append("</td>" + Layout.LINE_SEP);

		String escapedLogger = Transform.escapeTags(event.getLoggerName());
		sbuf.append("<td title=\"" + escapedLogger + " category\">");
		sbuf.append(escapedLogger);
		sbuf.append("</td>" + Layout.LINE_SEP);

		if (locationInfo) {
			LocationInfo locInfo = event.getLocationInformation();
			sbuf.append("<td>");
			sbuf.append(Transform.escapeTags(locInfo.getFileName()));
			sbuf.append(':');
			sbuf.append(locInfo.getLineNumber());
			sbuf.append("</td>" + Layout.LINE_SEP);
		}

		sbuf.append("<td title=\"Message\">");

		if (event != null && event.getRenderedMessage() != null)
			sbuf.append(Transform.escapeTags(event.getRenderedMessage()).replace("\n", "<br/>"));
		sbuf.append("</td>" + Layout.LINE_SEP);
		sbuf.append("</tr>" + Layout.LINE_SEP);

		if (event.getNDC() != null) {
			sbuf.append(
					"<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">");
			sbuf.append("NDC: " + Transform.escapeTags(event.getNDC()));
			sbuf.append("</td></tr>" + Layout.LINE_SEP);
		}

		String[] s = event.getThrowableStrRep();
		if (s != null) {
			/*
			 * sbuf.append(
			 * "<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : xx-small;\" colspan=\"6\">"
			 * );
			 */
			sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : xx-small;\" colspan=\"5\">");
			appendThrowableAsHTML(s, sbuf);
			sbuf.append("</td></tr>" + Layout.LINE_SEP);
		}

		return sbuf.toString();
	}
 
Example 2
Source File: HTMLLayout.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public
String format(LoggingEvent event) {

  if(sbuf.capacity() > MAX_CAPACITY) {
    sbuf = new StringBuffer(BUF_SIZE);
  } else {
    sbuf.setLength(0);
  }

  sbuf.append(Layout.LINE_SEP + "<tr>" + Layout.LINE_SEP);

  sbuf.append("<td>");
  sbuf.append(event.timeStamp - LoggingEvent.getStartTime());
  sbuf.append("</td>" + Layout.LINE_SEP);

  String escapedThread = Transform.escapeTags(event.getThreadName());
  sbuf.append("<td title=\"" + escapedThread + " thread\">");
  sbuf.append(escapedThread);
  sbuf.append("</td>" + Layout.LINE_SEP);

  sbuf.append("<td title=\"Level\">");
  if (event.getLevel().equals(Level.DEBUG)) {
    sbuf.append("<font color=\"#339933\">");
    sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
    sbuf.append("</font>");
  }
  else if(event.getLevel().isGreaterOrEqual(Level.WARN)) {
    sbuf.append("<font color=\"#993300\"><strong>");
    sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
    sbuf.append("</strong></font>");
  } else {
    sbuf.append(Transform.escapeTags(String.valueOf(event.getLevel())));
  }
  sbuf.append("</td>" + Layout.LINE_SEP);

  String escapedLogger = Transform.escapeTags(event.getLoggerName());
  sbuf.append("<td title=\"" + escapedLogger + " category\">");
  sbuf.append(escapedLogger);
  sbuf.append("</td>" + Layout.LINE_SEP);

  if(locationInfo) {
    LocationInfo locInfo = event.getLocationInformation();
    sbuf.append("<td>");
    sbuf.append(Transform.escapeTags(locInfo.getFileName()));
    sbuf.append(':');
    sbuf.append(locInfo.getLineNumber());
    sbuf.append("</td>" + Layout.LINE_SEP);
  }

  sbuf.append("<td title=\"Message\">");
  sbuf.append(Transform.escapeTags(event.getRenderedMessage()));
  sbuf.append("</td>" + Layout.LINE_SEP);
  sbuf.append("</tr>" + Layout.LINE_SEP);

  if (event.getNDC() != null) {
    sbuf.append("<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">");
    sbuf.append("NDC: " + Transform.escapeTags(event.getNDC()));
    sbuf.append("</td></tr>" + Layout.LINE_SEP);
  }

  String[] s = event.getThrowableStrRep();
  if(s != null) {
    sbuf.append("<tr><td bgcolor=\"#993300\" style=\"color:White; font-size : xx-small;\" colspan=\"6\">");
    appendThrowableAsHTML(s, sbuf);
    sbuf.append("</td></tr>" + Layout.LINE_SEP);
  }

  return sbuf.toString();
}