Java Code Examples for org.apache.log4j.spi.LoggingEvent#getThreadName()
The following examples show how to use
org.apache.log4j.spi.LoggingEvent#getThreadName() .
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: PatternParser.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public String convert(LoggingEvent event) { switch(type) { case RELATIVE_TIME_CONVERTER: return (Long.toString(event.timeStamp - LoggingEvent.getStartTime())); case THREAD_CONVERTER: return event.getThreadName(); case LEVEL_CONVERTER: return event.getLevel().toString(); case NDC_CONVERTER: return event.getNDC(); case MESSAGE_CONVERTER: { return event.getRenderedMessage(); } default: return null; } }
Example 2
Source File: SMTPAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
/** Perform SMTPAppender specific appending actions, mainly adding the event to a cyclic buffer and checking if the event triggers an e-mail to be sent. */ public void append(LoggingEvent event) { if(!checkEntryConditions()) { return; } event.getThreadName(); event.getNDC(); event.getMDCCopy(); if(locationInfo) { event.getLocationInformation(); } cb.add(event); if(evaluator.isTriggeringEvent(event)) { sendBuffer(); } }
Example 3
Source File: JListView.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public void run() { while(true) { synchronized(this) { try { this.wait(); } catch(Exception e) { } } for(int i = 0; i < burst; i++) { LoggingEvent event = new LoggingEvent("x", cat, Priority.DEBUG, "Message "+counter, null); event.getThreadName(); if(counter % 50 == 0) { //event.throwable = new Exception("hello "+counter); } counter++; view.add(event); } } }
Example 4
Source File: LoggingReceiver.java From JVoiceXML with GNU Lesser General Public License v2.1 | 6 votes |
/** * Convenience method to send a log message to the debug pane. The event is * displayed, if a session exists and the configured logging level is equal * or greater to the level of the <code>logevent</code>. * * @param logevent * The received logging message. */ private void logMessage(final LoggingEvent logevent) { if (session == null) { return; } final String id = session.getSessionID(); final String threadName = logevent.getThreadName(); if (!id.equalsIgnoreCase(threadName)) { return; } final Level currentLevel = logevent.getLevel(); if (!currentLevel.isGreaterOrEqual(level)) { return; } final long timestamp = logevent.timeStamp; final Date date = new Date(timestamp); final String message = logevent.getMessage().toString(); browser.logMessage(date, message); }
Example 5
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 6
Source File: JDBCLog.java From MultimediaDesktop with Apache License 2.0 | 5 votes |
public void append(LoggingEvent event) { event.getNDC(); event.getThreadName(); // Get a copy of this thread's MDC. event.getMDCCopy(); if (locationInfo) { event.getLocationInformation(); } event.getRenderedMessage(); event.getThrowableStrRep(); buffer.add(event); if (buffer.size() >= bufferSize) flushBuffer(); }
Example 7
Source File: EventDetails.java From cacheonix-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * Creates a new <code>EventDetails</code> instance. * * @param aEvent a <code>LoggingEvent</code> value */ EventDetails(LoggingEvent aEvent) { this(aEvent.timeStamp, aEvent.getLevel(), aEvent.getLoggerName(), aEvent.getNDC(), aEvent.getThreadName(), aEvent.getRenderedMessage(), aEvent.getThrowableStrRep(), (aEvent.getLocationInformation() == null) ? null : aEvent.getLocationInformation().fullInfo); }
Example 8
Source File: MessageLogAppender.java From unitime with Apache License 2.0 | 5 votes |
@Override protected void append(LoggingEvent event) { if (!event.getLevel().isGreaterOrEqual(getMinLevel())) return; if (event.getLogger().equals(MessageLogAppender.class.getName())) return; MessageLog m = new MessageLog(); m.setLevel(event.getLevel().toInt()); String logger = event.getLoggerName(); if (logger.indexOf('.') >= 0) logger = logger.substring(logger.lastIndexOf('.') + 1); m.setLogger(logger.length() > 255 ? logger.substring(0, 255) : logger); m.setMessage(event.getMessage() == null ? null : event.getMessage().toString()); m.setTimeStamp(new Date(event.getTimeStamp())); m.setNdc(event.getNDC()); String thread = event.getThreadName(); m.setThread(thread == null ? null : thread.length() > 100 ? thread.substring(0, 100) : thread); Throwable t = (event.getThrowableInformation() != null ? event.getThrowableInformation().getThrowable() : null); if (t != null) { String ex = ""; while (t != null) { String clazz = t.getClass().getName(); if (clazz.indexOf('.') >= 0) clazz = clazz.substring(1 + clazz.lastIndexOf('.')); if (!ex.isEmpty()) ex += "\n"; ex += clazz + ": " + t.getMessage(); if (t.getStackTrace() != null && t.getStackTrace().length > 0) ex += " (at " + t.getStackTrace()[0].getFileName() + ":" + t.getStackTrace()[0].getLineNumber() + ")"; t = t.getCause(); } if (!ex.isEmpty()) m.setException(ex); } getSaver().add(m); }
Example 9
Source File: Log4JAppenderWrapper.java From mrgeo with Apache License 2.0 | 5 votes |
@Override public void doAppend(LoggingEvent event) { assert (wrappedAppender != null); String msg = event.getMessage().toString(); Matcher m = crlf.matcher(msg); if (m.find()) { String lines[] = msg.split("\r\n|\n|\r"); //msg.split("\\r?\\n"); for (String line : lines) { String clean = "(Encoded) " + line; LoggingEvent encoded = new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), clean, event.getThreadName(), event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(), event.getProperties()); wrappedAppender.doAppend(encoded); } } else { wrappedAppender.doAppend(event); } }
Example 10
Source File: Log4jRecord.java From Sparkngin with GNU Affero General Public License v3.0 | 5 votes |
public Log4jRecord(LoggingEvent event) { this.timestamp = event.getTimeStamp(); this.threadName = event.getThreadName() ; this.loggerName = event.getLoggerName(); this.level = event.getLevel().toString(); this.message = event.getRenderedMessage(); }
Example 11
Source File: AsyncAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
/** * {@inheritDoc} */ public void append(final LoggingEvent event) { // // if dispatcher thread has died then // append subsequent events synchronously // See bug 23021 if ((dispatcher == null) || !dispatcher.isAlive() || (bufferSize <= 0)) { synchronized (appenders) { appenders.appendLoopOnAppenders(event); } return; } // Set the NDC and thread name for the calling thread as these // LoggingEvent fields were not set at event creation time. event.getNDC(); event.getThreadName(); // Get a copy of this thread's MDC. event.getMDCCopy(); if (locationInfo) { event.getLocationInformation(); } synchronized (buffer) { while (true) { int previousSize = buffer.size(); if (previousSize < bufferSize) { buffer.add(event); // // if buffer had been empty // signal all threads waiting on buffer // to check their conditions. // if (previousSize == 0) { buffer.notifyAll(); } break; } // // Following code is only reachable if buffer is full // // // if blocking and thread is not already interrupted // and not the dispatcher then // wait for a buffer notification boolean discard = true; if (blocking && !Thread.interrupted() && Thread.currentThread() != dispatcher) { try { buffer.wait(); discard = false; } catch (InterruptedException e) { // // reset interrupt status so // calling code can see interrupt on // their next wait or sleep. Thread.currentThread().interrupt(); } } // // if blocking is false or thread has been interrupted // add event to discard map. // if (discard) { String loggerName = event.getLoggerName(); DiscardSummary summary = (DiscardSummary) discardMap.get(loggerName); if (summary == null) { summary = new DiscardSummary(event); discardMap.put(loggerName, summary); } else { summary.add(event); } break; } } } }
Example 12
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 13
Source File: JListView.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
static public void main(String[] args) { JFrame frame = new JFrame("JListView test"); Container container = frame.getContentPane(); JListView view = new JListView(new JListViewModel(Integer.parseInt(args[0]))); JScrollPane sp = new JScrollPane(view); sp.setPreferredSize(new Dimension(250, 80)); container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); //container.add(view); container.add(sp); JButton b1 = new JButton("Add 1"); JButton b10 = new JButton("Add 10"); JButton b100 = new JButton("Add 100"); JButton b1000 = new JButton("Add 1000"); JButton b10000 = new JButton("Add 10000"); JPanel panel = new JPanel(new GridLayout(0,1)); container.add(panel); panel.add(b1); panel.add(b10); panel.add(b100); panel.add(b1000); panel.add(b10000); AddAction a1 = new AddAction(view, 1); AddAction a10 = new AddAction(view, 10); AddAction a100 = new AddAction(view, 100); AddAction a1000 = new AddAction(view, 1000); AddAction a10000 = new AddAction(view, 10000); b1.addActionListener(a1); b10.addActionListener(a10); b100.addActionListener(a100); b1000.addActionListener(a1000); b10000.addActionListener(a10000); frame.setVisible(true); frame.setSize(new Dimension(700,700)); long before = System.currentTimeMillis(); int RUN = 1000; int i = 0; while(i++ < RUN) { LoggingEvent event0 = new LoggingEvent("x", cat, Priority.ERROR, "Message "+i, null); Throwable t = new Exception("hello "+i); LoggingEvent event1 = new LoggingEvent("x", cat, Priority.ERROR, "Message "+i, t); if(i % 10 == 0) { event1.getThreadName(); view.add(event1); } else { event0.getThreadName(); view.add(event0); } } long after = System.currentTimeMillis(); System.out.println("Time taken :"+ ((after-before)*1000/RUN)); }
Example 14
Source File: JTableAppender.java From cacheonix-core with GNU Lesser General Public License v2.1 | 4 votes |
static public void main(String[] args) { JFrame frame = new JFrame("JListView test"); Container container = frame.getContentPane(); JTableAppender appender = new JTableAppender(); JTableAppenderModel model = new JTableAppenderModel(Integer.parseInt(args[0])); appender.setModel(model); //appender.createDefaultColumnsFromModel(); JScrollPane sp = new JScrollPane(appender); sp.setPreferredSize(new Dimension(250, 80)); container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); //container.add(view); container.add(sp); JButton button = new JButton("ADD"); container.add(button); button.addActionListener(new JTableAddAction(appender)); frame.setVisible(true); frame.setSize(new Dimension(700,700)); long before = System.currentTimeMillis(); int RUN = 10000; int i = 0; while(i++ < RUN) { LoggingEvent event = new LoggingEvent("x", cat, Priority.ERROR, "Message "+i, null); event.getThreadName(); if(i % 10 == 0) { //event.throwable = new Exception("hello "+i); } appender.add(event); } long after = System.currentTimeMillis(); System.out.println("Time taken :"+ ((after-before)*1000/RUN)); }
Example 15
Source File: StreamAppender.java From samza with Apache License 2.0 | 4 votes |
private LoggingEvent subLog(LoggingEvent event) { return new LoggingEvent(event.getFQNOfLoggerClass(), event.getLogger(), event.getTimeStamp(), event.getLevel(), subAppend(event), event.getThreadName(), event.getThrowableInformation(), event.getNDC(), event.getLocationInformation(), event.getProperties()); }
Example 16
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; }