Search in sources :

Example 21 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.

the class SshLog method onAuthFail.

void onAuthFail(final SshSession sd) {
    final LoggingEvent event = new //
    LoggingEvent(// fqnOfCategoryClass
    Logger.class.getName(), // logger
    log, // when
    TimeUtil.nowMs(), // level
    Level.INFO, // message text
    "AUTH FAILURE FROM " + sd.getRemoteAddressAsString(), // thread name
    "SSHD", // exception information
    null, // current NDC string
    null, // caller location
    null, // MDC properties
    null);
    event.setProperty(P_SESSION, id(sd.getSessionId()));
    event.setProperty(P_USER_NAME, sd.getUsername());
    final String error = sd.getAuthenticationError();
    if (error != null) {
        event.setProperty(P_STATUS, error);
    }
    if (async != null) {
        async.append(event);
    }
    audit(null, "FAIL", "AUTH");
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) Logger(org.apache.log4j.Logger)

Example 22 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.

the class SshLog method log.

private LoggingEvent log(final String msg) {
    final SshSession sd = session.get();
    final CurrentUser user = sd.getUser();
    final LoggingEvent event = new //
    LoggingEvent(// fqnOfCategoryClass
    Logger.class.getName(), // logger
    log, // when
    TimeUtil.nowMs(), // level
    Level.INFO, // message text
    msg, // thread name
    "SSHD", // exception information
    null, // current NDC string
    null, // caller location
    null, // MDC properties
    null);
    event.setProperty(P_SESSION, id(sd.getSessionId()));
    String userName = "-";
    String accountId = "-";
    if (user != null && user.isIdentifiedUser()) {
        IdentifiedUser u = user.asIdentifiedUser();
        userName = u.getAccount().getUserName();
        accountId = "a/" + u.getAccountId().toString();
    } else if (user instanceof PeerDaemonUser) {
        userName = PeerDaemonUser.USER_NAME;
    }
    event.setProperty(P_USER_NAME, userName);
    event.setProperty(P_ACCOUNT_ID, accountId);
    return event;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) CurrentUser(com.google.gerrit.server.CurrentUser) Logger(org.apache.log4j.Logger) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) PeerDaemonUser(com.google.gerrit.server.PeerDaemonUser)

Example 23 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project gerrit by GerritCodeReview.

the class SshLog method onLogin.

void onLogin() {
    LoggingEvent entry = log("LOGIN FROM " + session.get().getRemoteAddressAsString());
    if (async != null) {
        async.append(entry);
    }
    audit(context.get(), "0", "LOGIN");
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 24 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project JMRI by JMRI.

the class JLogoutputFrame method log.

/**
     * Outputs a message only to the appender which belongs to this frame
     *
     * @param aLevel logging level
     * @param aMsg   logging message
     */
public void log(Level aLevel, String aMsg) {
    if (myAppender == null) {
        return;
    }
    // if myAppender == null
    LoggingEvent event = new LoggingEvent(this.getClass().getName(), myLog, aLevel, aMsg, null);
    myAppender.append(event);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Example 25 with LoggingEvent

use of org.apache.log4j.spi.LoggingEvent in project JMRI by JMRI.

the class JUnitAppender method verifyNoBacklog.

/**
     * Verify that no messages were emitted, logging any that were. Does not
     * stop the logging. Clears the accumulated list.
     *
     * @return true if no messages logged
     */
public static boolean verifyNoBacklog() {
    if (list.isEmpty()) {
        return true;
    }
    while (!list.isEmpty()) {
        // should probably add a skip of lower levels?
        LoggingEvent evt = list.remove(0);
        instance().superappend(evt);
    }
    return false;
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent)

Aggregations

LoggingEvent (org.apache.log4j.spi.LoggingEvent)48 Test (org.junit.Test)21 Logger (org.apache.log4j.Logger)12 Pattern (java.util.regex.Pattern)7 Matcher (java.util.regex.Matcher)6 ByteArrayOutputStream (org.apache.commons.io.output.ByteArrayOutputStream)6 AppenderSkeleton (org.apache.log4j.AppenderSkeleton)3 LoggingException (com.axway.ats.log.autodb.exceptions.LoggingException)2 AbstractLoggingEvent (com.axway.ats.log.autodb.model.AbstractLoggingEvent)2 IOException (java.io.IOException)2 Appender (org.apache.log4j.Appender)2 Category (org.apache.log4j.Category)2 Level (org.apache.log4j.Level)2 Filter (org.apache.log4j.spi.Filter)2 LocationInfo (org.apache.log4j.spi.LocationInfo)2 InsertMessageEvent (com.axway.ats.log.autodb.events.InsertMessageEvent)1 CacheableEvent (com.axway.ats.log.autodb.model.CacheableEvent)1 SystemLogLevel (com.axway.ats.log.model.SystemLogLevel)1 CurrentUser (com.google.gerrit.server.CurrentUser)1 IdentifiedUser (com.google.gerrit.server.IdentifiedUser)1