Skip to content

Commit

Permalink
Merge pull request #6 from lucasponce/LOG
Browse files Browse the repository at this point in the history
Log
  • Loading branch information
jshaughn committed Feb 4, 2015
2 parents 708175c + be207cc commit 6340207
Show file tree
Hide file tree
Showing 55 changed files with 646 additions and 593 deletions.
5 changes: 0 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

1. `cd hawkular-bus ; mvn clean install -Pdev`

Note:

Verify that Bus is configured in failover mode due:
https://issues.jboss.org/browse/HAWKULAR-14

== hawkular-alerts

1. `cd hawkular-alerts ; mvn clean install -Pdev`
Expand Down
10 changes: 7 additions & 3 deletions hawkular-alerts-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@
<dependencies>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.org.slf4j}</version>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2015 Red Hat, Inc. and/or its affiliates
* and other contributors as indicated by the @author tags.
*
* 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 org.hawkular.alerts.api.log;

import org.jboss.logging.BasicLogger;
import org.jboss.logging.Logger;
import org.jboss.logging.Message;
import org.jboss.logging.annotations.LogMessage;
import org.jboss.logging.annotations.MessageLogger;
import org.jboss.logging.annotations.ValidIdRange;

/**
* Common log for INFO, WARN, ERROR and FATAL messages.
*
* @author Lucas Ponce
*/
@MessageLogger(projectCode = "HAWKALERT")
@ValidIdRange(min = 200000, max = 209999)
public interface MsgLogger extends BasicLogger {
MsgLogger LOGGER = Logger.getMessageLogger(MsgLogger.class, MsgLogger.class.getPackage().getName());

@LogMessage(level = Logger.Level.WARN)
@Message(id = 200001, value = "Unknown operator [%s] for condition [%s]")
void warnUnknowOperatorOnCondition(String operator, String condition);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.hawkular.alerts.api.log.MsgLogger;
import org.hawkular.alerts.api.model.data.Availability.AvailabilityType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* An availability condition definition.
Expand All @@ -27,7 +26,7 @@
* @author Lucas Ponce
*/
public class AvailabilityCondition extends Condition {
private static final Logger log = LoggerFactory.getLogger(AvailabilityCondition.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;

public enum Operator {
DOWN, NOT_UP, UP
Expand Down Expand Up @@ -79,7 +78,7 @@ public boolean match(AvailabilityType value) {
case NOT_UP:
return value != AvailabilityType.UP;
default:
log.warn("Unknown operator: " + operator.name());
msgLog.warnUnknowOperatorOnCondition(operator.name(), this.getClass().getName());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hawkular.alerts.api.log.MsgLogger;

/**
* A numeric comparison condition.
Expand All @@ -27,7 +26,7 @@
* @author Lucas Ponce
*/
public class CompareCondition extends Condition {
private static final Logger log = LoggerFactory.getLogger(CompareCondition.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;

public enum Operator {
LT, GT, LTE, GTE
Expand Down Expand Up @@ -104,7 +103,7 @@ public boolean match(double data1Value, double data2Value) {
case GTE:
return data1Value >= threshold;
default:
log.warn("Unknown operator: " + operator.name());
msgLog.warnUnknowOperatorOnCondition(operator.name(), this.getClass().getName());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hawkular.alerts.api.log.MsgLogger;

/**
* A string comparison condition.
Expand All @@ -26,7 +25,7 @@
* @author Lucas Ponce
*/
public class StringCondition extends Condition {
private static final Logger log = LoggerFactory.getLogger(StringCondition.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;

public enum Operator {
EQUAL, NOT_EQUAL, STARTS_WITH, ENDS_WITH, CONTAINS, MATCH
Expand Down Expand Up @@ -110,7 +109,7 @@ public boolean match(String value) {
case MATCH:
return value.matches(pattern);
default:
log.warn("Unknown operator: " + operator.name());
msgLog.warnUnknowOperatorOnCondition(operator.name(), this.getClass().getName());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hawkular.alerts.api.log.MsgLogger;

/**
* A numeric threshold condition.
Expand All @@ -26,7 +25,7 @@
* @author Lucas Ponce
*/
public class ThresholdCondition extends Condition {
private static final Logger log = LoggerFactory.getLogger(ThresholdCondition.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;

public enum Operator {
LT, GT, LTE, GTE
Expand Down Expand Up @@ -90,7 +89,7 @@ public boolean match(double value) {
case GTE:
return value >= threshold;
default:
log.warn("Unknown operator: " + operator.name());
msgLog.warnUnknowOperatorOnCondition(operator.name(), this.getClass().getName());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package org.hawkular.alerts.api.model.condition;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.hawkular.alerts.api.log.MsgLogger;

/**
* A numeric threshold range condition.
Expand All @@ -26,7 +25,7 @@
* @author Lucas Ponce
*/
public class ThresholdRangeCondition extends Condition {
private static final Logger log = LoggerFactory.getLogger(ThresholdRangeCondition.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;

public enum Operator {
INCLUSIVE("[", "]"), EXCLUSIVE("(", ")");
Expand Down Expand Up @@ -138,7 +137,7 @@ public boolean match(double value) {
aboveLow = value > thresholdLow;
break;
default:
log.warn("Unknown operator low: " + operatorLow.name());
msgLog.warnUnknowOperatorOnCondition(operatorLow.name(), this.getClass().getName());
return false;
}

Expand All @@ -154,7 +153,7 @@ public boolean match(double value) {
belowHigh = value < thresholdHigh;
break;
default:
log.warn("Unknown operator high: " + operatorHigh.name());
msgLog.warnUnknowOperatorOnCondition(operatorHigh.name(), this.getClass().getName());
return false;
}

Expand Down
10 changes: 7 additions & 3 deletions hawkular-alerts-bus/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,13 @@
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${version.org.slf4j}</version>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>

<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging-annotations</artifactId>
<scope>provided</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import org.hawkular.alerts.api.services.NotificationsService;
import org.hawkular.alerts.bus.sender.NotificationSender;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.logging.Logger;


import javax.annotation.PostConstruct;
import javax.ejb.EJB;
Expand All @@ -35,7 +35,7 @@
@Startup
@Singleton
public class AlertEngineRegister {
private final Logger log = LoggerFactory.getLogger(AlertEngineRegister.class);
private final Logger log = Logger.getLogger(AlertEngineRegister.class);

@EJB
NotificationsService notifications;
Expand All @@ -44,6 +44,6 @@ public class AlertEngineRegister {
public void init() {
NotificationSender sender = new NotificationSender();
notifications.register(sender);
log.info("Registering sender: " + sender);
log.debugf("Registering sender: [%s]", sender);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
import org.hawkular.alerts.api.services.AlertsService;
import org.hawkular.alerts.bus.messages.AlertDataMessage;
import org.hawkular.bus.common.consumer.BasicMessageListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
Expand All @@ -37,16 +36,14 @@
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "MetricsTopic")})
public class AlertDataListener extends BasicMessageListener<AlertDataMessage> {
private final Logger log = LoggerFactory.getLogger(AlertDataListener.class);
private final Logger log = Logger.getLogger(AlertDataListener.class);

@EJB
AlertsService alerts;

@Override
protected void onBasicMessage(AlertDataMessage msg) {
if (log.isDebugEnabled()) {
log.debug("Message received: [{}]", msg);
}
log.debugf("Message received: [%s]", msg);
alerts.sendData(msg.getData());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package org.hawkular.alerts.bus.listener;

import org.hawkular.alerts.api.services.DefinitionsService;
import org.hawkular.alerts.bus.log.MsgLogger;
import org.hawkular.bus.common.consumer.BasicMessageListener;
import org.hawkular.notifiers.api.model.NotifierTypeRegistrationMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jboss.logging.Logger;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
Expand All @@ -38,30 +38,29 @@
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "NotifierTypeRegisterQueue")})
public class NotifierTypeListener extends BasicMessageListener<NotifierTypeRegistrationMessage> {
private final Logger log = LoggerFactory.getLogger(NotifierTypeListener.class);
private final MsgLogger msgLog = MsgLogger.LOGGER;
private final Logger log = Logger.getLogger(NotifierTypeListener.class);

@EJB
DefinitionsService definitions;

@Override
protected void onBasicMessage(NotifierTypeRegistrationMessage msg) {
if (log.isDebugEnabled()) {
log.debug("Message received: [{}]", msg);
}
log.debugf("Message received: [%s]", msg);
String op = msg.getOp();
String notifierType = msg.getNotifierType();
if (op == null || op.isEmpty()) {
log.warn("Notifier type registration received without op.");
msgLog.warnNotifierTypeRegistrationWithoutOp();
} else if (op.equals("init")) {
String notifierType = msg.getNotifierType();
if (definitions.getNotifierType(notifierType) == null) {
Set<String> properties = msg.getProperties();
definitions.addNotifierType(notifierType, properties);
log.info("Notifier type {} registered.", notifierType);
msgLog.infoNotifierTypeRegistration(notifierType);
} else {
log.warn("Notifier type {} is already registered", notifierType);
msgLog.warnNotifierTypeAlreadyRegistered(notifierType);
}
} else {
log.warn("Notifier type registration received with unknown op {} ", op);
msgLog.warnNotifierTypeRegistrationWithUnknownOp(notifierType, op);
}
}
}

0 comments on commit 6340207

Please sign in to comment.