[Major] Refactored LogMessage to use ResourceBundle, instead of bundleId
This commit is contained in:
parent
9251250949
commit
9b92d2fdbc
|
@ -1,5 +1,7 @@
|
|||
package li.strolch.handler.operationslog;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import li.strolch.model.Locator;
|
||||
|
@ -13,8 +15,8 @@ public class LogMessage extends I18nMessage {
|
|||
private final Locator locator;
|
||||
private final LogSeverity severity;
|
||||
|
||||
public LogMessage(String realm, Locator locator, LogSeverity logSeverity, String bundleId, String key) {
|
||||
super(bundleId, key);
|
||||
public LogMessage(String realm, Locator locator, LogSeverity logSeverity, ResourceBundle bundle, String key) {
|
||||
super(bundle, key);
|
||||
this.realm = realm;
|
||||
this.locator = locator;
|
||||
this.severity = logSeverity;
|
||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
@ -894,7 +895,8 @@ public abstract class AbstractTransaction implements StrolchTransaction {
|
|||
if (this.operationsLog != null) {
|
||||
this.operationsLog.addMessage(
|
||||
new LogMessage(this.realm.getRealm(), Locator.valueOf(AGENT, "tx", StrolchAgent.getUniqueId()),
|
||||
LogSeverity.EXCEPTION, "strolch-agent", "agent.tx.failed").value("reason", e));
|
||||
LogSeverity.EXCEPTION, ResourceBundle.getBundle("strolch-agent"), "agent.tx.failed")
|
||||
.value("reason", e));
|
||||
}
|
||||
|
||||
String msg = "Strolch Transaction for realm {0} failed due to {1}\n{2}"; //$NON-NLS-1$
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package li.strolch.execution;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
@ -128,7 +129,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class).addMessage(new LogMessage(realm, locator, LogSeverity.EXCEPTION,
|
||||
"strolch-service", "execution.handler.failed.execution").value("reason", e));
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.execution")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -146,7 +148,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class).addMessage(new LogMessage(realm, locator, LogSeverity.EXCEPTION,
|
||||
"strolch-service", "execution.handler.failed.executed").value("reason", e));
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.executed")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -164,7 +167,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class).addMessage(new LogMessage(realm, locator, LogSeverity.EXCEPTION,
|
||||
"strolch-service", "execution.handler.failed.stopped").value("reason", e));
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.stopped")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -182,7 +186,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class).addMessage(new LogMessage(realm, locator, LogSeverity.EXCEPTION,
|
||||
"strolch-service", "execution.handler.failed.error").value("reason", e));
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.error")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -200,7 +205,8 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class).addMessage(new LogMessage(realm, locator, LogSeverity.EXCEPTION,
|
||||
"strolch-service", "execution.handler.failed.warning").value("reason", e));
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.warning")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -236,8 +242,9 @@ public class EventBasedExecutionHandler extends ExecutionHandler {
|
|||
|
||||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class)
|
||||
.addMessage(new LogMessage(realm, activityLoc, LogSeverity.EXCEPTION, "strolch-service",
|
||||
"execution.handler.failed.archive").value("reason", e));
|
||||
.addMessage(new LogMessage(realm, activityLoc, LogSeverity.EXCEPTION,
|
||||
ResourceBundle.getBundle("strolch-service"), "execution.handler.failed.archive")
|
||||
.value("reason", e));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -20,10 +20,6 @@ public class SimpleExecution extends ExecutionPolicy {
|
|||
super(container, tx);
|
||||
}
|
||||
|
||||
protected void toStarting(Action action) {
|
||||
setActionState(action, State.STARTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toExecution(Action action) {
|
||||
setActionState(action, State.EXECUTION);
|
||||
|
|
|
@ -22,6 +22,7 @@ import java.util.HashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
|
@ -144,8 +145,8 @@ public class Migrations {
|
|||
List<Version> list = migrationsRan.getList(realm);
|
||||
for (Version version : list) {
|
||||
LogMessage logMessage = new LogMessage(realm, locator.append(StrolchAgent.getUniqueId()),
|
||||
LogSeverity.INFO, "strolch-service", "execution.handler.migrations.version")
|
||||
.value("version", version.toString());
|
||||
LogSeverity.INFO, ResourceBundle.getBundle("strolch-service"),
|
||||
"execution.handler.migrations.version").value("version", version.toString());
|
||||
operationsLog.addMessage(logMessage);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ package li.strolch.migrations;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
@ -202,8 +203,8 @@ public class MigrationsHandler extends StrolchComponent {
|
|||
if (getContainer().hasComponent(OperationsLog.class)) {
|
||||
getComponent(OperationsLog.class)
|
||||
.addMessage(new LogMessage(Tags.AGENT, getLocator().append(StrolchAgent.getUniqueId()),
|
||||
LogSeverity.EXCEPTION, "strolch-service", "execution.handler.failed.executed")
|
||||
.value("reason", e));
|
||||
LogSeverity.EXCEPTION, ResourceBundle.getBundle("strolch-service"),
|
||||
"execution.handler.failed.executed").value("reason", e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,22 +10,18 @@ import li.strolch.utils.helper.StringHelper;
|
|||
|
||||
public class I18nMessage {
|
||||
|
||||
private String bundleId;
|
||||
private ResourceBundle bundle;
|
||||
private String key;
|
||||
private Properties values;
|
||||
|
||||
public I18nMessage(String bundleId, String key) {
|
||||
DBC.INTERIM.assertNotEmpty("bundleId must be set!", bundleId);
|
||||
public I18nMessage(ResourceBundle bundle, String key) {
|
||||
DBC.INTERIM.assertNotNull("bundle must be set!", bundle);
|
||||
DBC.INTERIM.assertNotEmpty("key must be set!", key);
|
||||
this.bundleId = bundleId;
|
||||
this.bundle = bundle;
|
||||
this.key = key;
|
||||
this.values = new Properties();
|
||||
}
|
||||
|
||||
public String getBundleId() {
|
||||
return this.bundleId;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
@ -42,8 +38,7 @@ public class I18nMessage {
|
|||
}
|
||||
|
||||
public String formatMessage() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(this.bundleId);
|
||||
String string = bundle.getString(this.key);
|
||||
String string = this.bundle.getString(this.key);
|
||||
return StringHelper.replacePropertiesIn(this.values, EMPTY, string);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue