From b01578ef57eb40feee791f8b043d2041cc0d536b Mon Sep 17 00:00:00 2001 From: parkera <parkera> Date: Tue, 16 Feb 2016 15:08:30 +0000 Subject: [PATCH] SSDM-3131 openBIS: Improve e-mail notification for admin SVN: 35692 --- ...dledTimestampTriggeringEventEvaluator.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 common/source/java/ch/systemsx/cisd/common/logging/BundledTimestampTriggeringEventEvaluator.java diff --git a/common/source/java/ch/systemsx/cisd/common/logging/BundledTimestampTriggeringEventEvaluator.java b/common/source/java/ch/systemsx/cisd/common/logging/BundledTimestampTriggeringEventEvaluator.java new file mode 100644 index 00000000000..725aa05f52b --- /dev/null +++ b/common/source/java/ch/systemsx/cisd/common/logging/BundledTimestampTriggeringEventEvaluator.java @@ -0,0 +1,53 @@ +/* + * Copyright 2007 ETH Zuerich, CISD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package ch.systemsx.cisd.common.logging; + +import java.util.Date; + +import org.apache.log4j.spi.LoggingEvent; +import org.apache.log4j.spi.TriggeringEventEvaluator; + +/** + * A {@link BundledTimestampTriggeringEventEvaluator} that triggers every 10 minutes. Can be used, e.g. to make the + * {@link org.apache.log4j.net.SMTPAppender} send email also on non-error conditions.; + * + * @author Althea Parker + */ +public class BundledTimestampTriggeringEventEvaluator implements TriggeringEventEvaluator +{ + + private long timestamp; + + public static long timePeriod = 10 * 60000; + + public BundledTimestampTriggeringEventEvaluator() { + timestamp = new Date().getTime(); + } + + @Override + public boolean isTriggeringEvent(LoggingEvent event) { + long current_time = new Date().getTime(); + if (current_time >= timestamp + timePeriod) { + timestamp = current_time; + return true; + } + else { + return false; + } + } + +} -- GitLab