Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qa: parametrize logger usages #5181

Merged
merged 6 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/terasology-metrics.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ dependencies {
pmd("net.sourceforge.pmd:pmd-core:7.0.0-rc4")
pmd("net.sourceforge.pmd:pmd-java:7.0.0-rc4")

testRuntimeOnly("ch.qos.logback:logback-classic:1.2.11") {
testRuntimeOnly("ch.qos.logback:logback-classic:1.2.12") {
because("runtime: to configure logging during tests with logback.xml")
}
testRuntimeOnly("org.codehaus.janino:janino:3.1.7") {
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/terasology-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ if (project.name == "ModuleTestingEnvironment") {
dependencies {
// MTE is a special snowflake, it gets these things as non-test dependencies
implementation(group = "org.terasology.engine", name = "engine-tests", version = moduleMetadata.engineVersion())
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("ch.qos.logback:logback-classic:1.2.12")
runtimeOnly("org.codehaus.janino:janino:3.1.3") {
because("logback filters")
}
Expand Down
6 changes: 1 addition & 5 deletions engine-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ dependencies {

implementation("org.terasology.joml-ext:joml-test:0.1.0")

implementation('org.slf4j:slf4j-api:1.7.36') {
because('a backend-independent Logger')
}
Comment on lines -65 to -67
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@soloturn why are we removing this here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only saw your comment now...

tested, and it is indeed not even used. so remove. also reverted back jul-to-slf4j.

so you're saying we don't use slf4j for our test stuff? interesting... what's used for logging in tests instead then? 🤔
I thought I saw logs in some tests, but maybe I misremember?

Copy link
Contributor

@soloturn soloturn Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

slf4j comes into engine-tests via engine whose version wins. a lot of tohers bring slf4j in differing version as well, like gestalt, jnbullet, nui, nui-reflect, nui-gestatl, etc etc says gralde -q dependencies in folder engine-tests, in both compile and runtime classpath. i will be more explicit in the commit comment next time, @jdrueckert .


testImplementation("ch.qos.logback:logback-classic:1.2.11") {
testImplementation("ch.qos.logback:logback-classic:1.4.11") {
because("implementation: a test directly uses logback.classic classes")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ TerasologyEngine createHost(NetworkMode hostNetworkMode) throws IOException {
doneLoading = false;
host.subscribeToStateChange(() -> {
GameState newState = host.getState();
logger.debug("New engine state is {}", host.getState());
logger.debug("New engine state is {}", newState);
if (newState instanceof StateIngame) {
hostContext = newState.getContext();
if (hostContext == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void registerCurrentDirectoryIfModule(ModuleManager moduleManager) {
logger.info("Install path does not appear to be a module: {}", installPath);
}
} catch (IOException e) {
logger.warn("Could not read install path as module at " + installPath);
logger.warn("Could not read install path as module at {}", installPath);
}
}
}
8 changes: 4 additions & 4 deletions engine/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ dependencies {
api "org.lwjgl:lwjgl-opengl"
implementation "org.lwjgl:lwjgl-stb"

implementation 'io.micrometer:micrometer-core:1.9.0'
implementation 'io.micrometer:micrometer-registry-jmx:1.9.0'
implementation 'io.micrometer:micrometer-core:1.9.12'
implementation 'io.micrometer:micrometer-registry-jmx:1.9.12'
api group: 'io.projectreactor', name: 'reactor-core', version: '3.4.18'
api group: 'io.projectreactor.addons', name: 'reactor-extra', version: '3.4.8'
implementation 'io.projectreactor.netty:reactor-netty-core:1.0.19'
Expand All @@ -118,7 +118,7 @@ dependencies {
implementation('org.slf4j:slf4j-api:1.7.36') {
because('a backend-independent Logger')
}
implementation("ch.qos.logback:logback-classic:1.2.11") {
implementation("ch.qos.logback:logback-classic:1.2.12") {
because("telemetry implementation uses logback to send to logstash " +
"and we bundle org.terasology.logback for the regex filter")
}
Expand All @@ -133,7 +133,7 @@ dependencies {
implementation(group: 'com.snowplowanalytics', name: 'snowplow-java-tracker', version: '0.12.1') {
exclude group: 'org.slf4j', module: 'slf4j-simple'
}
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.2'
implementation group: 'net.logstash.logback', name: 'logstash-logback-encoder', version: '7.4'

// Our developed libs
api group: 'org.terasology.gestalt', name: 'gestalt-asset-core', version: '7.2.0-SNAPSHOT'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ public void setRenderSkeletons(boolean renderSkeletons) {

@Override
public void propertyChange(PropertyChangeEvent evt) {
logger.info("Set {} property to {}. ", evt.getPropertyName().toUpperCase(), evt.getNewValue()); // for debugging purposes
logger.debug("Set {} property to {}.", evt.getPropertyName().toUpperCase(), evt.getNewValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private void verifyInitialisation() {
* Logs software, environment and hardware information.
*/
private void logEnvironmentInfo() {
logger.info(TerasologyVersion.getInstance().toString());
logger.info("{}", TerasologyVersion.getInstance());
logger.info("Home path: {}", PathManager.getInstance().getHomePath());
logger.info("Install path: {}", PathManager.getInstance().getInstallPath());
logger.info("Java: {} in {}", System.getProperty("java.version"), System.getProperty("java.home"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void popStep() {
current = null;
if (!loadProcesses.isEmpty()) {
current = loadProcesses.remove();
logger.debug(current.getMessage());
logger.debug("{}", current.getMessage());
current.begin();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public ModuleRegistry call() throws IOException {
}

int count = modules.size();
logger.info(String.format("Retrieved %d %s", count, (count == 1) ? "entry" : "entries"));
logger.info("Retrieved {} {}", count, (count == 1) ? "entry" : "entries");
}
return modules;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public void registerEvent(ResourceUrn uri, Class<? extends Event> eventType) {
public void registerEventHandler(ComponentSystem handler) {
Class handlerClass = handler.getClass();
if (!Modifier.isPublic(handlerClass.getModifiers())) {
logger.error("Cannot register handler {}, must be public", handler.getClass().getName());
logger.error("Cannot register handler {}, must be public", handlerClass.getName());
return;
}

logger.debug("Registering event handler " + handlerClass.getName());
logger.debug("Registering event handler {}", handlerClass.getName());
for (Method method : handlerClass.getMethods()) {
ReceiveEvent receiveEventAnnotation = method.getAnnotation(ReceiveEvent.class);
if (receiveEventAnnotation != null) {
Expand Down Expand Up @@ -127,7 +127,7 @@ public void registerEventHandler(ComponentSystem handler) {
method.setAccessible(true);
Class<?>[] types = method.getParameterTypes();

logger.debug("Found method: " + method.toString());
logger.debug("Found method: {}", method);
if (!Event.class.isAssignableFrom(types[0]) || !EntityRef.class.isAssignableFrom(types[1])) {
logger.error("Invalid event handler method: {}", method.getName());
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void refresh() {
TranslationProject proj = projects.computeIfAbsent(projectUrn, e -> new StandardTranslationProject());
proj.add(trans);
trans.subscribe(this::onAssetChanged);
logger.info("Discovered " + trans);
logger.info("Discovered {}", trans);
} else {
logger.warn("Ignoring invalid project projectUrn: {}", projectUrn);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void construct(Actor actor) {
try {
action.construct(actor);
} catch (Exception e) {
logger.debug("Exception while running construct() of action {} from entity {}: {}", action, actor.getEntity(), e.getMessage());
logger.debug("Exception while running construct() of action {} from entity {}: ", action, actor.getEntity(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public String getDamageTypeName(Prefab damageType) {
if (damageType.hasComponent(DisplayNameComponent.class)) {
return damageType.getComponent(DisplayNameComponent.class).name;
} else {
logger.info(String.format("%s is missing a readable DisplayName", damageType.getName()));
String damageTypeName = damageType.getName();
logger.info("{} is missing a readable DisplayName", damageTypeName);
//damageType.getName() returns a ResourceUrn String such as "engine:directDamage"
//The following calls change the damage type to be more readable
//For instance, "engine:directDamage" becomes "Direct Damage"
Expand Down Expand Up @@ -315,35 +315,35 @@ private boolean isPredictionOfEventCorrect(EntityRef character, ActivationReques

Vector3f originPos = location.getWorldPosition(new Vector3f());
if (!(event.getOrigin().equals(originPos, 0.0001f))) {
String msg = "Player {} seems to have cheated: It stated that it performed an action from {} but the predicted position is {}";
logger.info(msg, getPlayerNameFromCharacter(character), event.getOrigin(), originPos);
logger.info("Player {} seems to have cheated: It stated that it performed an action from {} but the predicted position is {}",
getPlayerNameFromCharacter(character), event.getOrigin(), originPos);
return false;
}

if (event.isOwnedEntityUsage()) {
if (!event.getUsedOwnedEntity().exists()) {
String msg = "Denied activation attempt by {} since the used entity does not exist on the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since the used entity does not exist on the authority",
getPlayerNameFromCharacter(character));
return false;
}
if (!networkSystem.getOwnerEntity(event.getUsedOwnedEntity()).equals(networkSystem.getOwnerEntity(character))) {
String msg = "Denied activation attempt by {} since it does not own the entity at the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since it does not own the entity at the authority",
getPlayerNameFromCharacter(character));
return false;
}
} else {
// check for cheats so that data can later be trusted:
if (event.getUsedOwnedEntity().exists()) {
String msg = "Denied activation attempt by {} since it is not properly marked as owned entity usage";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since it is not properly marked as owned entity usage",
getPlayerNameFromCharacter(character));
return false;
}
}

if (event.isEventWithTarget()) {
if (!event.getTarget().exists()) {
String msg = "Denied activation attempt by {} since the target does not exist on the authority";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since the target does not exist on the authority",
getPlayerNameFromCharacter(character));
return false; // can happen if target existed on client
}

Expand All @@ -360,8 +360,8 @@ private boolean isPredictionOfEventCorrect(EntityRef character, ActivationReques
HitResult result = physics.rayTrace(originPos, direction, interactionRange, Sets.newHashSet(character),
DEFAULTPHYSICSFILTER);
if (!result.isHit()) {
String msg = "Denied activation attempt by {} since at the authority there was nothing to activate at that place";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since at the authority there was nothing to activate at that place",
getPlayerNameFromCharacter(character));
return false;
}
EntityRef hitEntity = result.getEntity();
Expand All @@ -371,31 +371,31 @@ private boolean isPredictionOfEventCorrect(EntityRef character, ActivationReques
* server entity dump. When certain fields don't get replicated, then wrong entity might get hin in the
* hit test.
*/
String msg = "Denied activation attempt by {} since at the authority another entity would have been activated";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since at the authority another entity would have been activated",
getPlayerNameFromCharacter(character));
return false;
}

if (!(event.getHitPosition().equals(result.getHitPoint(), 0.0001f))) {
String msg = "Denied activation attempt by {} since at the authority the object got hit at a differnt position";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since at the authority the object got hit at a differnt position",
getPlayerNameFromCharacter(character));
return false;
}
} else {
// In order to trust the data later we need to verify it even if it should be correct if no one cheats:
if (event.getTarget().exists()) {
String msg = "Denied activation attempt by {} since the event was not properly labeled as having a target";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since the event was not properly labeled as having a target",
getPlayerNameFromCharacter(character));
return false;
}
if (event.getHitPosition() != null) {
String msg = "Denied activation attempt by {} since the event was not properly labeled as having a hit position";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since the event was not properly labeled as having a hit position",
getPlayerNameFromCharacter(character));
return false;
}
if (event.getHitNormal() != null) {
String msg = "Denied activation attempt by {} since the event was not properly labeled as having a hit delta";
logger.info(msg, getPlayerNameFromCharacter(character));
logger.info("Denied activation attempt by {} since the event was not properly labeled as having a hit delta",
getPlayerNameFromCharacter(character));
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public void preBegin() {
String moduleName = moduleConfig.moduleName;
Map<String, String> properties;
if (propertiesPerModule.containsKey(moduleName)) {
logger.error("Encountered more than one Module Config for module - " + moduleName +
", this is not recommended, as the property values visible are not going to be well defined.");
logger.error("Encountered more than one Module Config for module - {}, this is not recommended, " +
"as the property values visible are not going to be well defined.", moduleName);
properties = propertiesPerModule.get(moduleName);
} else {
properties = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void updateExtentsOnBlockItemBoxShape(OnAddedComponent event, EntityRef i
BlockFamily blockFamily = blockItemComponent.blockFamily;

if (blockFamily == null) {
LOGGER.warn("Prefab " + itemEntity.getParentPrefab().getName() + " does not have a block family");
LOGGER.warn("Prefab {} does not have a block family", itemEntity.getParentPrefab().getName());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ private void receiveModuleStart(ChannelHandlerContext channelHandlerContext,
joinStatus.setCurrentActivity(
"Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " ("
+ sizeString + "," + missingModules.size() + " modules remain)");
logger.info("Downloading " + moduleDataHeader.getId() + ":" + moduleDataHeader.getVersion() + " ("
+ sizeString + "," + missingModules.size() + " modules remain)");
logger.info("Downloading {}: {} ({}, {} modules remain)", moduleDataHeader.getId(), moduleDataHeader.getVersion(),
sizeString, missingModules.size());
receivingModule = moduleDataHeader;
lengthReceived = 0;
try {
Expand All @@ -176,8 +176,7 @@ private void receiveModuleStart(ChannelHandlerContext channelHandlerContext,
}
}
} else {
logger.error("Received unwanted module {}:{} from server", moduleDataHeader.getId(),
moduleDataHeader.getVersion());
logger.error("Received unwanted module {}:{} from server", moduleDataHeader.getId(), moduleDataHeader.getVersion());
joinStatus.setErrorMessage("Module download error");
channelHandlerContext.channel().close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ private void processRemovedClient(Client client) {
}
clientList.remove(client);
clientPlayerLookup.remove(client.getEntity());
logger.info("Client disconnected: " + client.getName());
logger.info("Client disconnected: {}", client.getName());
storageManager.deactivatePlayer(client);
client.getEntity().send(new DisconnectedEvent());
client.disconnect();
Expand Down Expand Up @@ -973,8 +973,7 @@ private <T> Map<Class<? extends T>, Integer> generateIds(ClassLibrary<T> classLi
int fieldId = 0;
for (FieldMetadata<?, ?> field : metadata.getFields()) {
if (fieldId >= 256) {
logger.error("Class {} has too many fields (>255), serialization will be incomplete",
metadata.getId());
logger.error("Class {} has too many fields (>255), serialization will be incomplete", metadata.getId());
break;
}
field.setId((byte) fieldId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ServerInfoRequestHandler extends ChannelInboundHandlerAdapter {

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.warn("Could not query server info: {}", cause.toString());
logger.warn("Could not query server info: ", cause);
}

@Override
Expand Down
Loading
Loading