Java Code Examples for org.apache.log4j.spi.LoggingEvent#getLoggerName()

The following examples show how to use org.apache.log4j.spi.LoggingEvent#getLoggerName() . 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: DBase.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void append (LoggingEvent e) {
	Level	l = e.getLevel ();
	int lvl = -1;

	if (l == Level.WARN) {
		lvl = Log.WARNING;
	} else if (l == Level.ERROR) {
		lvl = Log.ERROR;
	} else if (l == Level.FATAL) {
		lvl = Log.FATAL;
	}
	if (lvl != -1) {
		String	loggerName = e.getLoggerName ();

		if ((loggerName == null) || loggerName.startsWith ("org.springframework.jdbc")) {
			log.out (lvl, "jdbc", e.getRenderedMessage ());
		}
	}
}
 
Example 2
Source File: EclipseLogAppender.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void append(LoggingEvent event) {
	if (isDoLog(event.getLevel())) {
		String logString = layout.format(event);

		ILog myLog = getLog();
		if (myLog != null) {
			String loggerName = event.getLoggerName();
			int severity = mapLevel(event.getLevel());
			final Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation()
					.getThrowable() : null;
			IStatus status = createStatus(severity, loggerName, logString, throwable);

			// Injector injector = N4JSActivator.getInstance().getInjector(N4JSActivator.ORG_ECLIPSE_N4JS_N4JS);
			// if (injector != null) {
			getLog().log(status);
			// }
		} else {
			// nothing to do (message should be logged to stdout by default appender)
		}
	}
}
 
Example 3
Source File: EclipseLogAppender.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected void append(LoggingEvent event) {
	if (isDoLog(event.getLevel())) {
		String logString = layout.format(event);

		ILog myLog = getLog();
		if (myLog != null) {
			String loggerName = event.getLoggerName();
			int severity = mapLevel(event.getLevel());
			final Throwable throwable = event.getThrowableInformation() != null ? event.getThrowableInformation()
					.getThrowable() : null;
			IStatus status = createStatus(severity, loggerName, logString, throwable);
			getLog().log(status);
		} else {
			// nothing to do (message should be logged to stdout by default appender)
		}
	}
}
 
Example 4
Source File: Log4jConfigurationManager.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void doAppend(LoggingEvent arg0)
{
	String logger = arg0.getLoggerName();
	String message = arg0.getRenderedMessage();
	Level level = arg0.getLevel();

	Set toIgnore = (Set) m_ignore.get(logger);
	if (toIgnore != null)
	{
		// if any of the strings in the set start our message, skip it
		for (Iterator i = toIgnore.iterator(); i.hasNext();)
		{
			String start = (String) i.next();
			if (message.startsWith(start)) return;
		}
	}

	m_other.doAppend(arg0);
}
 
Example 5
Source File: Log4jConfigurationManager.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void doAppend(LoggingEvent arg0)
{
	String logger = arg0.getLoggerName();
	String message = arg0.getRenderedMessage();
	Level level = arg0.getLevel();

	Set toIgnore = (Set) m_ignore.get(logger);
	if (toIgnore != null)
	{
		// if any of the strings in the set start our message, skip it
		for (Iterator i = toIgnore.iterator(); i.hasNext();)
		{
			String start = (String) i.next();
			if (message.startsWith(start)) return;
		}
	}

	m_other.doAppend(arg0);
}
 
Example 6
Source File: Log4jRecord.java    From Sparkngin with GNU Affero General Public License v3.0 5 votes vote down vote up
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 7
Source File: Log.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void append (LoggingEvent e) {
	Level	l = e.getLevel ();
	int lvl = -1;

	if (l == Level.DEBUG) {
		lvl = DEBUG;
	} else if (l == Level.INFO) {
		lvl = INFO;
	} else if (l == Level.WARN) {
		lvl = WARNING;
	} else if (l == Level.ERROR) {
		lvl = ERROR;
	} else if (l == Level.FATAL) {
		lvl = FATAL;
	}
	if (lvl != -1) {
		String loggerName = e.getLoggerName ();
		boolean match = (loggerName == null) || (pattern == null) || (pattern.length == 0);

		if (! match) {
			for (int n = 0; n < pattern.length; ++n) {
				if (loggerName != null && loggerName.startsWith (pattern[n])) {
					match = true;
					break;
				}
			}
		}
		if (match) {
			log.out (lvl, id, e.getRenderedMessage ());
		}
	}
}
 
Example 8
Source File: MessageLogAppender.java    From unitime with Apache License 2.0 5 votes vote down vote up
@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: SpyAppender.java    From openpojo with Apache License 2.0 5 votes vote down vote up
public void doAppend(LoggingEvent event) {
  synchronized (this) {
    String loggerName = event.getLoggerName();
    if (eventMap.get(loggerName) != null)
      eventMap.get(loggerName).add(event);
    else {
      List<LoggingEvent> events = new ArrayList<LoggingEvent>();
      events.add(event);
      eventMap.put(loggerName, events);
    }
  }
}
 
Example 10
Source File: EventDetails.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * 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 11
Source File: LoggingTester.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public int decide(final LoggingEvent event) {
  int _xifexpression = (int) 0;
  String _loggerName = event.getLoggerName();
  String _name = this.source.getName();
  boolean _equals = Objects.equal(_loggerName, _name);
  if (_equals) {
    _xifexpression = Filter.DENY;
  } else {
    _xifexpression = Filter.NEUTRAL;
  }
  return _xifexpression;
}
 
Example 12
Source File: LoggingTester.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void append(final LoggingEvent event) {
  String _renderedMessage = event.getRenderedMessage();
  String _loggerName = event.getLoggerName();
  long _timeStamp = event.getTimeStamp();
  Level _level = event.getLevel();
  final LoggingTester.LogEntry entry = new LoggingTester.LogEntry(_renderedMessage, _loggerName, _timeStamp, _level);
  this.events.add(entry);
}
 
Example 13
Source File: LoggingTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public int decide(final LoggingEvent event) {
  int _xifexpression = (int) 0;
  String _loggerName = event.getLoggerName();
  String _name = this.source.getName();
  boolean _equals = Objects.equal(_loggerName, _name);
  if (_equals) {
    _xifexpression = Filter.DENY;
  } else {
    _xifexpression = Filter.NEUTRAL;
  }
  return _xifexpression;
}
 
Example 14
Source File: LoggingTester.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void append(final LoggingEvent event) {
  String _renderedMessage = event.getRenderedMessage();
  String _loggerName = event.getLoggerName();
  long _timeStamp = event.getTimeStamp();
  Level _level = event.getLevel();
  final LoggingTester.LogEntry entry = new LoggingTester.LogEntry(_renderedMessage, _loggerName, _timeStamp, _level);
  this.events.add(entry);
}
 
Example 15
Source File: LF5Appender.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * 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 16
Source File: PatternParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
String getFullyQualifiedName(LoggingEvent event) {
  return event.getLoggerName();
}
 
Example 17
Source File: AsyncAppender.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * {@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 18
Source File: MockAppenderLog4J.java    From openpojo with Apache License 2.0 4 votes vote down vote up
@Override
public final synchronized void append(final LoggingEvent event) {
  LogEvent le = new LogEvent(event.getLoggerName(), extractPriority(event), event.getRenderedMessage());
  EventLogger.registerEvent(this.getClass(), le);
}