Search in sources :

Example 1 with LogLevel

use of org.apache.log4j.lf5.LogLevel in project iaf by ibissource.

the class ServerStatistics method updateLogConfiguration.

@PUT
@RolesAllowed({ "IbisAdmin", "IbisTester" })
@Path("/server/log")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateLogConfiguration(LinkedHashMap<String, Object> json) throws ApiException {
    initBase(servletConfig);
    Level loglevel = null;
    Boolean logIntermediaryResults = true;
    int maxMessageLength = -1;
    StringBuilder msg = new StringBuilder();
    Logger rootLogger = LogUtil.getRootLogger();
    Appender appender = rootLogger.getAppender("appwrap");
    IbisAppenderWrapper iaw = null;
    if (appender != null && appender instanceof IbisAppenderWrapper) {
        iaw = (IbisAppenderWrapper) appender;
    }
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (key.equalsIgnoreCase("loglevel")) {
            loglevel = Level.toLevel("" + value);
        } else if (key.equalsIgnoreCase("logIntermediaryResults")) {
            logIntermediaryResults = Boolean.parseBoolean("" + value);
        } else if (key.equalsIgnoreCase("maxMessageLength")) {
            maxMessageLength = Integer.parseInt("" + value);
        }
    }
    if (loglevel != null && rootLogger.getLevel() != loglevel) {
        rootLogger.setLevel(loglevel);
        msg.append("LogLevel changed from [" + rootLogger.getLevel() + "] to [" + loglevel + "]");
    }
    boolean logIntermediary = AppConstants.getInstance().getBoolean("log.logIntermediaryResults", true);
    if (logIntermediary != logIntermediaryResults) {
        AppConstants.getInstance().put("log.logIntermediaryResults", "" + logIntermediaryResults);
        if (msg.length() > 0)
            msg.append(", logIntermediaryResults from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
        else
            msg.append("logIntermediaryResults changed from [" + logIntermediary + "] to [" + logIntermediaryResults + "]");
    }
    if (iaw != null) {
        if (iaw.getMaxMessageLength() != maxMessageLength) {
            if (msg.length() > 0)
                msg.append(", logMaxMessageLength from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
            else
                msg.append("logMaxMessageLength changed from [" + iaw.getMaxMessageLength() + "] to [" + maxMessageLength + "]");
            iaw.setMaxMessageLength(maxMessageLength);
        }
    }
    if (msg.length() > 0) {
        log.warn(msg.toString());
        LogUtil.getLogger("SEC").info(msg.toString());
    }
    return Response.status(Response.Status.NO_CONTENT).build();
}
Also used : Appender(org.apache.log4j.Appender) Level(org.apache.log4j.Level) LogLevel(org.apache.log4j.lf5.LogLevel) Logger(org.apache.log4j.Logger) IbisAppenderWrapper(nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with LogLevel

use of org.apache.log4j.lf5.LogLevel in project coprhd-controller by CoprHD.

the class DistributedKeyStoreImpl method checkCertificateDateValidity.

/**
 * checks if the certificate is about to expire, and alerts in case it is
 *
 * @param certificate
 *            the certificate to check
 */
private void checkCertificateDateValidity(X509Certificate certificate) {
    final String CERTIFICATE_EXPIRED_MESSAGE = "ViPR's certificate has expired. Please set a new one, or post a regenerate request";
    final String CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT = "ViPR's certificate will expire within %d %s. Please make arrangements to set a new certificate or to post a regenerate request";
    Date lastCertificateAlert = null;
    try {
        lastCertificateAlert = coordConfigStoringHelper.readConfig(coordConfigStoringHelper.getSiteId(), KEY_CERTIFICATE_PAIR_CONFIG_KIND, LAST_CERTIFICATE_ALERT_ID, LAST_CERTIFICATE_ALERT_KEY);
    } catch (Exception e) {
        // don't really care about the exception here
        log.warn(e.getMessage(), e);
    }
    Date notAfter = DateUtils.truncate(certificate.getNotAfter(), Calendar.DATE);
    Date today = DateUtils.truncate(new Date(), Calendar.DATE);
    Date nextWeek = DateUtils.addWeeks(today, 1);
    Date nextMonth = DateUtils.addMonths(today, 1);
    Date next3Months = DateUtils.addMonths(today, 3);
    Date next6Months = DateUtils.addMonths(today, 6);
    if (lastCertificateAlert == null || DateUtils.truncatedCompareTo(lastCertificateAlert, today, Calendar.DATE) < 0) {
        boolean logAlert = false;
        String messageToLog = CERTIFICATE_WILL_EXPIRE_MESSAGE_FORMAT;
        int timeAmount = 0;
        String timeType = null;
        LogLevel logLevel = LogLevel.WARN;
        if (notAfter.before(today)) {
            logLevel = LogLevel.FATAL;
            messageToLog = CERTIFICATE_EXPIRED_MESSAGE;
            logAlert = true;
        } else if (DateUtils.isSameDay(notAfter, today)) {
            timeType = "days";
            logLevel = LogLevel.ERROR;
            logAlert = true;
        } else if (notAfter.before(nextWeek)) {
            timeAmount = 1;
            timeType = "week";
            logAlert = true;
        } else if (notAfter.before(nextMonth)) {
            timeAmount = 1;
            timeType = "month";
            logAlert = true;
        } else if (notAfter.before(next3Months)) {
            timeAmount = 3;
            timeType = "months";
            logAlert = true;
        } else if (notAfter.before(next6Months)) {
            timeAmount = 6;
            timeType = "months";
            logAlert = true;
        }
        if (logAlert) {
            logAlert(messageToLog, timeAmount, timeType, logLevel);
            try {
                coordConfigStoringHelper.createOrUpdateConfig(today, KEY_CERTIFICATE_PAIR_LOCK, coordConfigStoringHelper.getSiteId(), KEY_CERTIFICATE_PAIR_CONFIG_KIND, LAST_CERTIFICATE_ALERT_ID, LAST_CERTIFICATE_ALERT_KEY);
            } catch (Exception e) {
                log.error("Could not set the time of last alert about certificate expiry", e);
            }
        }
    }
}
Also used : Date(java.util.Date) IOException(java.io.IOException) SecurityException(com.emc.storageos.security.exceptions.SecurityException) LogLevel(org.apache.log4j.lf5.LogLevel)

Aggregations

LogLevel (org.apache.log4j.lf5.LogLevel)2 SecurityException (com.emc.storageos.security.exceptions.SecurityException)1 IOException (java.io.IOException)1 Date (java.util.Date)1 RolesAllowed (javax.annotation.security.RolesAllowed)1 Consumes (javax.ws.rs.Consumes)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 IbisAppenderWrapper (nl.nn.adapterframework.extensions.log4j.IbisAppenderWrapper)1 Appender (org.apache.log4j.Appender)1 Level (org.apache.log4j.Level)1 Logger (org.apache.log4j.Logger)1