org.apache.log4j.spi.LocationInfo Java Examples
The following examples show how to use
org.apache.log4j.spi.LocationInfo.
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: EcsLayout.java From ecs-logging-java with Apache License 2.0 | 6 votes |
@Override public String format(LoggingEvent event) { StringBuilder builder = new StringBuilder(); EcsJsonSerializer.serializeObjectStart(builder, event.getTimeStamp()); EcsJsonSerializer.serializeLogLevel(builder, event.getLevel().toString()); EcsJsonSerializer.serializeFormattedMessage(builder, event.getRenderedMessage()); EcsJsonSerializer.serializeServiceName(builder, serviceName); EcsJsonSerializer.serializeEventDataset(builder, eventDataset); EcsJsonSerializer.serializeThreadName(builder, event.getThreadName()); EcsJsonSerializer.serializeLoggerName(builder, event.getLoggerName()); EcsJsonSerializer.serializeMDC(builder, event.getProperties()); EcsJsonSerializer.serializeTag(builder, event.getNDC()); if (includeOrigin) { LocationInfo locationInformation = event.getLocationInformation(); if (locationInformation != null) { EcsJsonSerializer.serializeOrigin(builder, locationInformation.getFileName(), locationInformation.getMethodName(), getLineNumber(locationInformation)); } } ThrowableInformation throwableInformation = event.getThrowableInformation(); if (throwableInformation != null) { EcsJsonSerializer.serializeException(builder, throwableInformation.getThrowable(), stackTraceAsArray); } EcsJsonSerializer.serializeObjectEnd(builder); return builder.toString(); }
Example #2
Source File: Console.java From olca-app with Mozilla Public License 2.0 | 6 votes |
@Override protected void append(LoggingEvent evt) { if (stream.isClosed()) return; String message; if (evt.getLevel().toInt() <= Level.DEBUG_INT) { LocationInfo info = evt.getLocationInformation(); message = "" + evt.getLevel().toString() + " [" + DateFormatUtils.format(evt.timeStamp, "HH:mm:ss.SS") + "]" + " @" + info.getClassName() + ">" + info.getMethodName() + ">" + info.getLineNumber() + " - " + evt.getMessage(); } else { message = "" + evt.getLevel().toString() + " - " + evt.getMessage(); } tryPrintMessage(message, evt.getThrowableInformation()); }
Example #3
Source File: LoggingEventTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Tests LoggingEvent.getLocationInfo() when no FQCN is specified. * See bug 41186. */ public void testLocationInfoNoFQCN() { Category root = Logger.getRootLogger(); Priority level = Level.INFO; LoggingEvent event = new LoggingEvent( null, root, 0L, level, "Hello, world.", null); LocationInfo info = event.getLocationInformation(); // // log4j 1.2 returns an object, its layout doesn't check for nulls. // log4j 1.3 returns a null. // assertNotNull(info); if (info != null) { assertEquals("?", info.getLineNumber()); assertEquals("?", info.getClassName()); assertEquals("?", info.getFileName()); assertEquals("?", info.getMethodName()); } }
Example #4
Source File: JulAppender.java From presto with Apache License 2.0 | 6 votes |
/** * Append a log event at the appropriate JUL level, depending on the log4j level. */ @Override protected void append(LoggingEvent loggingEvent) { java.util.logging.Logger logger = java.util.logging.Logger.getLogger(loggingEvent.getLoggerName()); if (logger == null) { LogLog.warn(format("Cannot obtain JUL %s. Verify that this appender is used while an appropriate LogManager is active.", loggingEvent.getLoggerName())); return; } Level level = loggingEvent.getLevel(); java.util.logging.Level julLevel = convertLog4jLevel(level); LogRecord record = new LogRecord(julLevel, loggingEvent.getRenderedMessage()); record.setMillis(loggingEvent.getTimeStamp()); LocationInfo location = loggingEvent.getLocationInformation(); if (location != null) { record.setSourceClassName(location.getClassName()); record.setSourceMethodName(location.getMethodName()); } logger.log(record); }
Example #5
Source File: Log4jLogEvent.java From xian with Apache License 2.0 | 5 votes |
private String getSourceLineNumber() { String lineNumber = loggingEvent.getLocationInformation().getLineNumber(); if (LocationInfo.NA.equals(lineNumber)) { return null; } return lineNumber; }
Example #6
Source File: SpectatorAppender.java From spectator with Apache License 2.0 | 5 votes |
@Override protected void append(LoggingEvent event) { final LevelTag level = LevelTag.get(event.getLevel()); registry.counter(numMessages[level.ordinal()]).increment(); ThrowableInformation info = event.getThrowableInformation(); if (info != null) { LocationInfo loc = event.getLocationInformation(); final String file = (loc == null) ? "unknown" : loc.getFileName(); Id stackTraceId = numStackTraces[level.ordinal()] .withTag("exception", info.getThrowable().getClass().getSimpleName()) .withTag("file", file); registry.counter(stackTraceId).increment(); } }
Example #7
Source File: CassandraAppender.java From cassandra-log4j-appender with Apache License 2.0 | 5 votes |
/** * Send one logging event to Cassandra. We just bind the new values into the preprocessed query * built by setupStatement */ private void createAndExecuteQuery(LoggingEvent event) { BoundStatement bound = new BoundStatement(statement); // A primary key combination of timestamp/hostname/threadname should be unique as long as the thread names // are set, but would not be backwards compatible. Do we care? bound.setUUID(0, UUID.randomUUID()); bound.setString(1, appName); bound.setString(2, ip); bound.setString(3, hostname); bound.setString(4, event.getLoggerName()); bound.setString(5, event.getLevel().toString()); LocationInfo locInfo = event.getLocationInformation(); if (locInfo != null) { bound.setString(6, locInfo.getClassName()); bound.setString(7, locInfo.getFileName()); bound.setString(8, locInfo.getLineNumber()); bound.setString(9, locInfo.getMethodName()); } bound.setString(10, event.getRenderedMessage()); bound.setString(11, event.getNDC()); bound.setLong(12, new Long(LoggingEvent.getStartTime())); bound.setString(13, event.getThreadName()); String[] throwableStrs = event.getThrowableStrRep(); bound.setString(14, throwableStrs == null ? null : Joiner.on(", ").join(throwableStrs)); bound.setLong(15, new Long(event.getTimeStamp())); session.execute(bound); }
Example #8
Source File: EcsLayout.java From ecs-logging-java with Apache License 2.0 | 5 votes |
private static int getLineNumber(LocationInfo locationInformation) { int lineNumber = -1; String lineNumberString = locationInformation.getLineNumber(); if (!LocationInfo.NA.equals(lineNumberString)) { try { lineNumber = Integer.parseInt(lineNumberString); } catch (NumberFormatException e) { // ignore } } return lineNumber; }
Example #9
Source File: LoggingEventTest.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Serialize a logging event with an exception and check it against * a witness. * @throws Exception if exception during test. * */ public void testSerializationWithLocation() throws Exception { Logger root = Logger.getRootLogger(); LoggingEvent event = new LoggingEvent( root.getClass().getName(), root, Level.INFO, "Hello, world.", null); LocationInfo info = event.getLocationInformation(); // event.prepareForDeferredProcessing(); int[] skip = new int[] { 352, 353, 354, 355, 356 }; SerializationTestHelper.assertSerializationEquals( "witness/serialization/location.bin", event, skip, 237); }
Example #10
Source File: PatternParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
public String convert(LoggingEvent event) { LocationInfo locationInfo = event.getLocationInformation(); switch(type) { case FULL_LOCATION_CONVERTER: return locationInfo.fullInfo; case METHOD_LOCATION_CONVERTER: return locationInfo.getMethodName(); case LINE_LOCATION_CONVERTER: return locationInfo.getLineNumber(); case FILE_LOCATION_CONVERTER: return locationInfo.getFileName(); default: return null; } }
Example #11
Source File: BenderLayout.java From bender with Apache License 2.0 | 5 votes |
@Override public String format(LoggingEvent event) { BenderLogEntry entry = new BenderLogEntry(); entry.threadName = event.getThreadName(); entry.posixTimestamp = event.getTimeStamp(); entry.timestamp = FORMATTER.print(entry.posixTimestamp); entry.message = event.getRenderedMessage(); entry.level = event.getLevel().toString(); entry.logger = event.getLogger().getName(); entry.alias = ALIAS; entry.version = VERSION; if (event.getThrowableInformation() != null) { final ThrowableInformation throwableInfo = event.getThrowableInformation(); ExceptionLog ex = new ExceptionLog(); if (throwableInfo.getThrowable().getClass().getCanonicalName() != null) { ex.clazz = throwableInfo.getThrowable().getClass().getCanonicalName(); } if (throwableInfo.getThrowable().getMessage() != null) { ex.message = throwableInfo.getThrowable().getMessage(); } if (throwableInfo.getThrowableStrRep() != null) { Arrays.asList(throwableInfo.getThrowableStrRep()).forEach(m -> { ex.stacktrace.add(m.replaceAll("\\t", " ")); }); } entry.exception = ex; } LocationInfo locinfo = event.getLocationInformation(); entry.file = locinfo.getFileName(); entry.lineNumber = Integer.parseInt(locinfo.getLineNumber()); entry.method = locinfo.getMethodName(); entry.clazz = locinfo.getClassName(); return GSON.toJson(entry) + "\n"; }
Example #12
Source File: LambdaLogger.java From tinkerpop3 with GNU General Public License v2.0 | 5 votes |
public LocationInfo getLocationInformation() { if (location == null) { Throwable t = new Throwable(); // t.printStackTrace(); location = new LambdaLocation(t); } return location; }
Example #13
Source File: Log4jLogEvent.java From xian with Apache License 2.0 | 5 votes |
private String getSourceMethodName() { String methodName = loggingEvent.getLocationInformation().getMethodName(); if (LocationInfo.NA.equals(methodName)) { return null; } return methodName; }
Example #14
Source File: SimpleLogEventTest.java From flogger with Apache License 2.0 | 5 votes |
@Test public void testLocationInfo() { LogData data = FakeLogData.of("foo"); SimpleLogEvent logEvent = newSimpleLogEvent(data); LocationInfo locationInfo = logEvent.asLoggingEvent().getLocationInformation(); assertThat(locationInfo.getClassName()).isEqualTo(data.getLogSite().getClassName()); assertThat(locationInfo.getMethodName()).isEqualTo(data.getLogSite().getMethodName()); assertThat(locationInfo.getFileName()).isEqualTo(data.getLogSite().getFileName()); assertThat(locationInfo.getLineNumber()) .isEqualTo(Integer.toString(data.getLogSite().getLineNumber())); }
Example #15
Source File: SimpleLogEvent.java From flogger with Apache License 2.0 | 5 votes |
private LocationInfo getLocationInfo() { LogSite logSite = logData.getLogSite(); return new LocationInfo( logSite.getFileName(), logSite.getClassName(), logSite.getMethodName(), Integer.toString(logSite.getLineNumber())); }
Example #16
Source File: Log4jLogEvent.java From xian with Apache License 2.0 | 5 votes |
private String getSourceClassName() { String className = loggingEvent.getLocationInformation().getClassName(); if (LocationInfo.NA.equals(className)) { return null; } return className; }
Example #17
Source File: LogEventAdapter.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** * Set the location information for this logging event. The collected * information is cached for future use. */ @Override public LocationInfo getLocationInformation() { return new LocationInfo(event.getSource()); }
Example #18
Source File: LogEventWrapper.java From logging-log4j2 with Apache License 2.0 | 4 votes |
@Override public StackTraceElement getSource() { LocationInfo info = event.getLocationInformation(); return new StackTraceElement(info.getClassName(), info.getMethodName(), info.getFileName(), Integer.parseInt(info.getLineNumber())); }
Example #19
Source File: PropertyRewritePolicy.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** * {@inheritDoc} */ public LoggingEvent rewrite(final LoggingEvent source) { if (!properties.isEmpty()) { Map<String, String> rewriteProps = source.getProperties() != null ? new HashMap<>(source.getProperties()) : new HashMap<>(); for (Map.Entry<String, String> entry : properties.entrySet()) { if (!rewriteProps.containsKey(entry.getKey())) { rewriteProps.put(entry.getKey(), entry.getValue()); } } LogEvent event; if (source instanceof LogEventAdapter) { event = new Log4jLogEvent.Builder(((LogEventAdapter) source).getEvent()) .setContextData(new SortedArrayStringMap(rewriteProps)) .build(); } else { LocationInfo info = source.getLocationInformation(); StackTraceElement element = new StackTraceElement(info.getClassName(), info.getMethodName(), info.getFileName(), Integer.parseInt(info.getLineNumber())); Thread thread = getThread(source.getThreadName()); long threadId = thread != null ? thread.getId() : 0; int threadPriority = thread != null ? thread.getPriority() : 0; event = Log4jLogEvent.newBuilder() .setContextData(new SortedArrayStringMap(rewriteProps)) .setLevel(OptionConverter.convertLevel(source.getLevel())) .setLoggerFqcn(source.getFQNOfLoggerClass()) .setMarker(null) .setMessage(new SimpleMessage(source.getRenderedMessage())) .setSource(element) .setLoggerName(source.getLoggerName()) .setThreadName(source.getThreadName()) .setThreadId(threadId) .setThreadPriority(threadPriority) .setThrown(source.getThrowableInformation().getThrowable()) .setTimeMillis(source.getTimeStamp()) .setNanoTime(0) .setThrownProxy(null) .build(); } return new LogEventAdapter(event); } return source; }
Example #20
Source File: PurgeUtilityHTMLLayout.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public String format( LoggingEvent event ) { Level logLevel = event.getLevel(); if ( sbuf.capacity() > MAX_CAPACITY ) { sbuf = new StringBuffer( BUF_SIZE ); } else { sbuf.setLength( 0 ); } if ( showTimeColumn() ) { DateFormat df = new SimpleDateFormat( "MM/dd/yyyy HH:mm:ss" ); Date date = new Date(); date.setTime( event.timeStamp ); String time = null; try { time = df.format( date ); } catch ( Exception ex ) { LogLog.error( "Error occured while converting date.", ex ); } sbuf.append( Layout.LINE_SEP + "<tr>" + Layout.LINE_SEP ); sbuf.append( "<td>" ); sbuf.append( Transform.escapeTags( time ) ); sbuf.append( "</td>" + Layout.LINE_SEP ); } sbuf.append( "<td title=\"Purge File/Folder\">" ); sbuf.append( Transform.escapeTags( MDC.get( PurgeUtilityLog.FILE_KEY ) ) ); sbuf.append( "</td>" + Layout.LINE_SEP ); if ( showLevelColumn() ) { sbuf.append( "<td title=\"Level\">" ); if ( logLevel.equals( Level.DEBUG ) ) { sbuf.append( "<font color=\"#339933\">" ); sbuf.append( Transform.escapeTags( String.valueOf( event.getLevel() ) ) ); sbuf.append( "</font>" ); } else if ( logLevel.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 ); } if ( showCodeLineColumn() ) { LocationInfo locInfo = event.getLocationInformation(); sbuf.append( "<td>" ); sbuf.append( Transform.escapeTags( MDC.get( PurgeUtilityLogger.CODE_LINE ) ) ); // 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(); }
Example #21
Source File: ExtendedSyslogAppender.java From primecloud-controller with GNU General Public License v2.0 | 4 votes |
@Override public LocationInfo getLocationInformation() { return event.getLocationInformation(); }
Example #22
Source File: LogEventAdapter.java From logging-log4j2 with Apache License 2.0 | 4 votes |
/** Set the location information for this logging event. The collected information is cached for future use. */ @Override public LocationInfo getLocationInformation() { return new LocationInfo(event.getSource()); }
Example #23
Source File: GlogLayout.java From xio with Apache License 2.0 | 4 votes |
@Override public String getMethodName(LoggingEvent record) { LocationInfo locationInformation = record.getLocationInformation(); return (locationInformation != null) ? record.getLocationInformation().getMethodName() : null; }
Example #24
Source File: GlogLayout.java From xio with Apache License 2.0 | 4 votes |
@Override public String getClassName(LoggingEvent record) { LocationInfo locationInformation = record.getLocationInformation(); return (locationInformation != null) ? locationInformation.getClassName() : null; }
Example #25
Source File: SocketCollectorTest.java From karaf-decanter with Apache License 2.0 | 4 votes |
private LoggingEvent newLoggingEvent(String message) { return new LoggingEvent(this.getClass().getName(), new NOPLogger(new NOPLoggerRepository(), "NOP"), System.currentTimeMillis(), Level.INFO, message, Thread.currentThread().getName(), new ThrowableInformation((Throwable)null), null, new LocationInfo(null, null), new Properties()); }
Example #26
Source File: SocketCollector.java From karaf-decanter with Apache License 2.0 | 4 votes |
private void putLocation(Map<String, Object> data, LocationInfo loc) { data.put("loc.class", loc.getClassName()); data.put("loc.file", loc.getFileName()); data.put("loc.line", loc.getLineNumber()); data.put("loc.method", loc.getMethodName()); }
Example #27
Source File: LoggingEventJsonSerde.java From samza with Apache License 2.0 | 4 votes |
/** * Encodes a LoggingEvent into a HashMap using the logstash JSON format. * * @param loggingEvent * The LoggingEvent to encode. * @param includeLocationInfo * Whether to include LocationInfo in the map, or not. * @return A Map representing the LoggingEvent, which is suitable to be * serialized by a JSON encoder such as Jackson. */ @SuppressWarnings("rawtypes") public static Map<String, Object> encodeToMap(LoggingEvent loggingEvent, boolean includeLocationInfo) { Map<String, Object> logstashEvent = new LoggingEventMap(); String threadName = loggingEvent.getThreadName(); long timestamp = loggingEvent.getTimeStamp(); HashMap<String, Object> exceptionInformation = new HashMap<String, Object>(); Map mdc = loggingEvent.getProperties(); String ndc = loggingEvent.getNDC(); logstashEvent.put("@version", VERSION); logstashEvent.put("@timestamp", dateFormat(timestamp)); logstashEvent.put("source_host", getHostname()); logstashEvent.put("message", loggingEvent.getRenderedMessage()); if (loggingEvent.getThrowableInformation() != null) { final ThrowableInformation throwableInformation = loggingEvent.getThrowableInformation(); if (throwableInformation.getThrowable().getClass().getCanonicalName() != null) { exceptionInformation.put("exception_class", throwableInformation.getThrowable().getClass().getCanonicalName()); } if (throwableInformation.getThrowable().getMessage() != null) { exceptionInformation.put("exception_message", throwableInformation.getThrowable().getMessage()); } if (throwableInformation.getThrowableStrRep() != null) { StringBuilder stackTrace = new StringBuilder(); for (String line : throwableInformation.getThrowableStrRep()) { stackTrace.append(line); stackTrace.append("\n"); } exceptionInformation.put("stacktrace", stackTrace); } logstashEvent.put("exception", exceptionInformation); } if (includeLocationInfo) { LocationInfo info = loggingEvent.getLocationInformation(); logstashEvent.put("file", info.getFileName()); logstashEvent.put("line_number", info.getLineNumber()); logstashEvent.put("class", info.getClassName()); logstashEvent.put("method", info.getMethodName()); } logstashEvent.put("logger_name", loggingEvent.getLoggerName()); logstashEvent.put("mdc", mdc); logstashEvent.put("ndc", ndc); logstashEvent.put("level", loggingEvent.getLevel().toString()); logstashEvent.put("thread_name", threadName); return logstashEvent; }
Example #28
Source File: HTMLLayout.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
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(); }
Example #29
Source File: LF5Appender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * Appends a <code>LoggingEvent</code> record to the * <code>LF5Appender</code>. * @param event The <code>LoggingEvent</code> * to be appended. */ public void append(LoggingEvent event) { // Retrieve the information from the log4j LoggingEvent. String category = event.getLoggerName(); String logMessage = event.getRenderedMessage(); String nestedDiagnosticContext = event.getNDC(); String threadDescription = event.getThreadName(); String level = event.getLevel().toString(); long time = event.timeStamp; LocationInfo locationInfo = event.getLocationInformation(); // Add the logging event information to a LogRecord Log4JLogRecord record = new Log4JLogRecord(); record.setCategory(category); record.setMessage(logMessage); record.setLocation(locationInfo.fullInfo); record.setMillis(time); record.setThreadDescription(threadDescription); if (nestedDiagnosticContext != null) { record.setNDC(nestedDiagnosticContext); } else { record.setNDC(""); } if (event.getThrowableInformation() != null) { record.setThrownStackTrace(event.getThrowableInformation()); } try { record.setLevel(LogLevel.valueOf(level)); } catch (LogLevelFormatException e) { // If the priority level doesn't match one of the predefined // log levels, then set the level to warning. record.setLevel(LogLevel.WARN); } if (_logMonitor != null) { _logMonitor.addMessage(record); } }
Example #30
Source File: HTMLLayout.java From document-management-software with GNU Lesser General Public License v3.0 | 4 votes |
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(); }