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();
}
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);
}
}
}
}
Aggregations