From 5c7fa2c49b4a45b840c4ddad178c8e6982211fda Mon Sep 17 00:00:00 2001 From: soloturn Date: Mon, 12 Feb 2024 11:34:53 +0100 Subject: [PATCH] feedback fluent-logger pr. except to make log line shorter. --- .../engine/audio/openAL/OpenALManager.java | 2 +- .../audio/openAL/staticSound/OpenALSound.java | 2 +- .../streamingSound/OpenALStreamingSound.java | 2 +- .../config/flexible/AutoConfigManager.java | 4 +-- .../engine/core/TerasologyEngine.java | 2 +- .../engine/core/module/ModuleInstaller.java | 2 +- .../common/ConfigurationSubsystem.java | 2 +- .../event/internal/EventSystemImpl.java | 8 ++--- .../entitySystem/metadata/EventMetadata.java | 3 +- .../characters/CharacterSoundSystem.java | 2 +- .../updating/ParticleUpdaterImpl.java | 3 +- .../serializers/EventSerializer.java | 2 +- .../serializers/PrefabSerializer.java | 3 +- .../engine/physics/bullet/BulletPhysics.java | 6 ++-- .../engine/rendering/dag/RenderGraph.java | 7 ++--- .../dag/RenderTaskListGenerator.java | 30 ++++++++----------- .../block/internal/BlockManagerImpl.java | 8 ++--- 17 files changed, 38 insertions(+), 50 deletions(-) diff --git a/engine/src/main/java/org/terasology/engine/audio/openAL/OpenALManager.java b/engine/src/main/java/org/terasology/engine/audio/openAL/OpenALManager.java index 2778f95fc3d..26be4ddca96 100644 --- a/engine/src/main/java/org/terasology/engine/audio/openAL/OpenALManager.java +++ b/engine/src/main/java/org/terasology/engine/audio/openAL/OpenALManager.java @@ -261,7 +261,7 @@ private void notifyEndListeners(boolean interrupted) { try { entry.getValue().onAudioEnd(interrupted); } catch (Exception e) { - logger.atError().addArgument(() -> entry.getValue()).addArgument(e).log("onAudioEnd() notification failed for {}"); + logger.error("onAudioEnd() notification failed for {}", entry.getValue(), e); //NOPMD } } } diff --git a/engine/src/main/java/org/terasology/engine/audio/openAL/staticSound/OpenALSound.java b/engine/src/main/java/org/terasology/engine/audio/openAL/staticSound/OpenALSound.java index 742cd18bef8..16e272881d9 100644 --- a/engine/src/main/java/org/terasology/engine/audio/openAL/staticSound/OpenALSound.java +++ b/engine/src/main/java/org/terasology/engine/audio/openAL/staticSound/OpenALSound.java @@ -104,7 +104,7 @@ protected void doReload(StaticSoundData newData) { length = (float) size / channels / (bits / 8) / frequency; }); } catch (InterruptedException e) { - logger.atError().addArgument(() -> getUrn()).addArgument(e).log("Failed to reload {}"); + logger.error("Failed to reload {}", getUrn(), e); //NOPMD } } diff --git a/engine/src/main/java/org/terasology/engine/audio/openAL/streamingSound/OpenALStreamingSound.java b/engine/src/main/java/org/terasology/engine/audio/openAL/streamingSound/OpenALStreamingSound.java index da21a199386..cd7ddd6bb56 100644 --- a/engine/src/main/java/org/terasology/engine/audio/openAL/streamingSound/OpenALStreamingSound.java +++ b/engine/src/main/java/org/terasology/engine/audio/openAL/streamingSound/OpenALStreamingSound.java @@ -123,7 +123,7 @@ protected void doReload(StreamingSoundData data) { try { GameThread.synch(this::initializeBuffers); } catch (InterruptedException e) { - logger.atError().addArgument(() -> getUrn()).addArgument(e).log("Failed to reload {}"); + logger.error("Failed to reload {}", getUrn(), e); //NOPMD } } diff --git a/engine/src/main/java/org/terasology/engine/config/flexible/AutoConfigManager.java b/engine/src/main/java/org/terasology/engine/config/flexible/AutoConfigManager.java index 98102c81ebb..aca5578844a 100644 --- a/engine/src/main/java/org/terasology/engine/config/flexible/AutoConfigManager.java +++ b/engine/src/main/java/org/terasology/engine/config/flexible/AutoConfigManager.java @@ -85,7 +85,7 @@ private void loadSettingsFromDisk(Class configClass, T T loadedConfig = (T) serializer.deserialize(TypeInfo.of(configClass), inputStream).get(); mergeConfig(configClass, loadedConfig, config); } catch (Exception e) { - logger.atError().addArgument(() -> config.getId()).addArgument(e).log("Error while loading config {} from disk"); + logger.error("Error while loading config {} from disk", config.getId(), e); //NOPMD } } @@ -116,7 +116,7 @@ private void saveConfigToDisk(AutoConfig config) { StandardOpenOption.CREATE)) { serializer.serialize(config, TypeInfo.of((Class) config.getClass()), output); } catch (IOException e) { - logger.atError().addArgument(() -> config.getId()).addArgument(e).log("Error while saving config {} to disk"); + logger.error("Error while saving config {} to disk", config.getId(), e); //NOPMD } } diff --git a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java index 404a6f02862..3b3b340ba08 100644 --- a/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java +++ b/engine/src/main/java/org/terasology/engine/core/TerasologyEngine.java @@ -253,7 +253,7 @@ public void initialize() { } double seconds = 0.001 * totalInitTime.elapsed(TimeUnit.MILLISECONDS); - logger.atInfo().addArgument(() -> String.format("%.2f", seconds)).log("Initialization completed in {}sec."); + logger.info("Initialization completed in {}sec.", String.format("%.2f", seconds)); //NOPMD } private void verifyInitialisation() { diff --git a/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java b/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java index 5dd1728367d..e0be03426f2 100644 --- a/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java +++ b/engine/src/main/java/org/terasology/engine/core/module/ModuleInstaller.java @@ -38,7 +38,7 @@ public class ModuleInstaller implements Callable> { @Override public List call() throws Exception { Map filesToDownload = getDownloadUrls(moduleList); - logger.atInfo().addArgument(() -> filesToDownload.size()).log("Started downloading {} modules"); + logger.info("Started downloading {} modules", filesToDownload.size()); //NOPMD MultiFileDownloader downloader = new MultiFileDownloader(filesToDownload, downloadProgressListener); List downloadedModulesPaths = downloader.call(); logger.info("Module download completed, loading the new modules..."); diff --git a/engine/src/main/java/org/terasology/engine/core/subsystem/common/ConfigurationSubsystem.java b/engine/src/main/java/org/terasology/engine/core/subsystem/common/ConfigurationSubsystem.java index d211194c8d0..08fd8fc866e 100644 --- a/engine/src/main/java/org/terasology/engine/core/subsystem/common/ConfigurationSubsystem.java +++ b/engine/src/main/java/org/terasology/engine/core/subsystem/common/ConfigurationSubsystem.java @@ -66,7 +66,7 @@ public void preInitialise(Context rootContext) { checkServerIdentity(); // TODO: Move to display subsystem - logger.atInfo().addArgument(() -> config.renderConfigAsJson(config.getRendering())).log("Video Settings: {}"); + logger.info("Video Settings: {}", config.renderConfigAsJson(config.getRendering())); //NOPMD rootContext.put(Config.class, config); //add facades diff --git a/engine/src/main/java/org/terasology/engine/entitySystem/event/internal/EventSystemImpl.java b/engine/src/main/java/org/terasology/engine/entitySystem/event/internal/EventSystemImpl.java index 72df42bc85b..0cb83bec51a 100644 --- a/engine/src/main/java/org/terasology/engine/entitySystem/event/internal/EventSystemImpl.java +++ b/engine/src/main/java/org/terasology/engine/entitySystem/event/internal/EventSystemImpl.java @@ -83,7 +83,7 @@ public void process() { @Override public void registerEvent(ResourceUrn uri, Class eventType) { eventIdMap.put(uri, eventType); - logger.atDebug().addArgument(() -> eventType.getSimpleName()).log("Registering event {}"); + logger.debug("Registering event {}", eventType.getSimpleName()); //NOPMD for (Class parent : ReflectionUtils.getAllSuperTypes(eventType, Predicates.subtypeOf(Event.class))) { if (!AbstractConsumableEvent.class.equals(parent) && !Event.class.equals(parent)) { childEvents.put(parent, eventType); @@ -95,11 +95,11 @@ public void registerEvent(ResourceUrn uri, Class eventType) { public void registerEventHandler(ComponentSystem handler) { Class handlerClass = handler.getClass(); if (!Modifier.isPublic(handlerClass.getModifiers())) { - logger.atError().addArgument(() -> handlerClass.getName()).log("Cannot register handler {}, must be public"); + logger.error("Cannot register handler {}, must be public", handlerClass.getName()); //NOPMD return; } - logger.atDebug().addArgument(() -> handlerClass.getName()).log("Registering event handler {}"); + logger.debug("Registering event handler {}", handlerClass.getName()); //NOPMD for (Method method : handlerClass.getMethods()) { ReceiveEvent receiveEventAnnotation = method.getAnnotation(ReceiveEvent.class); if (receiveEventAnnotation != null) { @@ -129,7 +129,7 @@ public void registerEventHandler(ComponentSystem handler) { logger.debug("Found method: {}", method); if (!Event.class.isAssignableFrom(types[0]) || !EntityRef.class.isAssignableFrom(types[1])) { - logger.atError().addArgument(() -> method.getName()).log("Invalid event handler method: {}"); + logger.error("Invalid event handler method: {}", method.getName()); //NOPMD return; } diff --git a/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventMetadata.java b/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventMetadata.java index 14f32cf21eb..0eb71a8ae1c 100644 --- a/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventMetadata.java +++ b/engine/src/main/java/org/terasology/engine/entitySystem/metadata/EventMetadata.java @@ -38,8 +38,7 @@ public EventMetadata(Class simpleClass, CopyStrategyLibrary copyStrategies, R skipInstigator = simpleClass.getAnnotation(BroadcastEvent.class).skipInstigator(); } if (networkEventType != NetworkEventType.NONE && !isConstructable() && !Modifier.isAbstract(simpleClass.getModifiers())) { - logger.atError().addArgument(() -> this). - log("Event '{}' is a network event but lacks a default constructor - will not be replicated"); + logger.error("Event '{}' is a network event but lacks a default constructor - will not be replicated", this); //NOPMD } } diff --git a/engine/src/main/java/org/terasology/engine/logic/characters/CharacterSoundSystem.java b/engine/src/main/java/org/terasology/engine/logic/characters/CharacterSoundSystem.java index 7429cd75040..0cee78267c6 100644 --- a/engine/src/main/java/org/terasology/engine/logic/characters/CharacterSoundSystem.java +++ b/engine/src/main/java/org/terasology/engine/logic/characters/CharacterSoundSystem.java @@ -60,7 +60,7 @@ public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent Block block = worldProvider.getBlock(blockPos); if (block != null) { if (block.getSounds() == null) { - logger.atError().addArgument(() -> block.getURI()).log("Block '{}' has no sounds"); + logger.error("Block '{}' has no sounds", block.getURI()); //NOPMD } else if (!block.getSounds().getStepSounds().isEmpty()) { footstepSounds = block.getSounds().getStepSounds(); } diff --git a/engine/src/main/java/org/terasology/engine/particles/updating/ParticleUpdaterImpl.java b/engine/src/main/java/org/terasology/engine/particles/updating/ParticleUpdaterImpl.java index dd5f1a3cadf..b5a1fd25845 100644 --- a/engine/src/main/java/org/terasology/engine/particles/updating/ParticleUpdaterImpl.java +++ b/engine/src/main/java/org/terasology/engine/particles/updating/ParticleUpdaterImpl.java @@ -125,8 +125,7 @@ public void initialize() { for (Class type : environment.getTypesAnnotatedWith(RegisterParticleSystemFunction.class)) { if (!ParticleSystemFunction.class.isAssignableFrom(type)) { - logger.atError().addArgument(() -> type.getSimpleName()). - log("Cannot register particle system function {}, must be a subclass of ParticleSystemFunction"); + logger.error("Cannot register particle system function {}, must be a subclass of ParticleSystemFunction", type.getSimpleName()); //NOPMD } else { try { ParticleSystemFunction function = (ParticleSystemFunction) type.newInstance(); diff --git a/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java b/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java index 98d7f15d526..a2913b8b503 100644 --- a/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java +++ b/engine/src/main/java/org/terasology/engine/persistence/serializers/EventSerializer.java @@ -154,7 +154,7 @@ public Class getEventClass(EntityData.Event eventData) { } } if (metadata == null) { - logger.atWarn().addArgument(() -> eventData.getType()).log("Unable to deserialize unknown event with id: {}"); + logger.warn("Unable to deserialize unknown event with id: {}", eventData.getType()); //NOPMD return null; } return metadata.getType(); diff --git a/engine/src/main/java/org/terasology/engine/persistence/serializers/PrefabSerializer.java b/engine/src/main/java/org/terasology/engine/persistence/serializers/PrefabSerializer.java index 1bb95f1b201..7c6028ac403 100644 --- a/engine/src/main/java/org/terasology/engine/persistence/serializers/PrefabSerializer.java +++ b/engine/src/main/java/org/terasology/engine/persistence/serializers/PrefabSerializer.java @@ -155,8 +155,7 @@ private void applyComponentChanges(Module context, EntityData.Prefab prefabData, } } } else if (componentData.hasType()) { - logger.atWarn().addArgument(() -> prefabData.getName()).addArgument(() -> componentData.getType()). - log("Prefab '{}' contains unknown component '{}'"); + logger.warn("Prefab '{}' contains unknown component '{}'", prefabData.getName(), componentData.getType()); //NOPMD } } } diff --git a/engine/src/main/java/org/terasology/engine/physics/bullet/BulletPhysics.java b/engine/src/main/java/org/terasology/engine/physics/bullet/BulletPhysics.java index cc2ba46f464..2b117ba1bae 100644 --- a/engine/src/main/java/org/terasology/engine/physics/bullet/BulletPhysics.java +++ b/engine/src/main/java/org/terasology/engine/physics/bullet/BulletPhysics.java @@ -241,8 +241,7 @@ public HitResult rayTrace(Vector3f from, Vector3f direction, float distance, Col hitNormalWorld, voxelPosition); } else { //we hit something we don't understand, assume its nothing and log a warning - logger.atWarn().addArgument(() -> collisionObject.userData). - log("Unidentified object was hit in the physics engine: {}"); + logger.warn("Unidentified object was hit in the physics engine: {}", collisionObject.userData); //NOPMD } } @@ -306,8 +305,7 @@ public HitResult rayTrace(Vector3f from, Vector3f direction, float distance, Set hitNormalWorld, voxelPosition); } else { //we hit something we don't understand, assume its nothing and log a warning - logger.atWarn().addArgument(() -> collisionObject.userData). - log("Unidentified object was hit in the physics engine: {}"); + logger.warn("Unidentified object was hit in the physics engine: {}", collisionObject.userData); //NOPMD } } } diff --git a/engine/src/main/java/org/terasology/engine/rendering/dag/RenderGraph.java b/engine/src/main/java/org/terasology/engine/rendering/dag/RenderGraph.java index 9e1e37951e4..aeaa87d8df8 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/dag/RenderGraph.java +++ b/engine/src/main/java/org/terasology/engine/rendering/dag/RenderGraph.java @@ -533,14 +533,13 @@ public void reconnectInputToOutput(String fromNodeUri, int outputId, Node toNode */ private void reconnectInputToOutput(Node toNode, int inputId, DependencyConnection fromConnection, ConnectionType connectionType, boolean disconnectPrevious) { - logger.atDebug().addArgument(() -> toNode.getUri()).addArgument(() -> fromConnection.getParentNode()). - log("Attempting reconnection of {} to {}'s output."); + logger.debug("Attempting reconnection of {} to {}'s output.", toNode.getUri(), fromConnection.getParentNode()); //NOPMD Node fromNode; fromNode = findNode(fromConnection.getParentNode()); if (!fromConnection.getConnectedConnections().isEmpty()) { - logger.atWarn().addArgument(fromConnection).addArgument(() -> fromConnection.getConnectedConnections()). - log("WARNING: destination connection ({}) is already connected to ({})"); + logger.warn("WARNING: destination connection ({}) is already connected to ({})", + fromConnection, fromConnection.getConnectedConnections()); //NOPMD // TODO update the hashmap to string to be pretty // throw new RuntimeException("Could not reconnect, destination connection (" + fromConnection + ") is already connected to (" // + fromConnection.getConnectedConnections() + "). Remove connection first."); diff --git a/engine/src/main/java/org/terasology/engine/rendering/dag/RenderTaskListGenerator.java b/engine/src/main/java/org/terasology/engine/rendering/dag/RenderTaskListGenerator.java index d00ad950fde..a3f99a95a74 100644 --- a/engine/src/main/java/org/terasology/engine/rendering/dag/RenderTaskListGenerator.java +++ b/engine/src/main/java/org/terasology/engine/rendering/dag/RenderTaskListGenerator.java @@ -42,21 +42,22 @@ public RenderTaskListGenerator() { taskList = Lists.newArrayList(); } + @SuppressWarnings("PMD.GuardLogStatement") private void logIntermediateRendererListForDebugging(List orderedNodes) { for (Node node : orderedNodes) { if (node.isEnabled()) { // printing out node name - logger.atInfo().addArgument(() -> node.getClass().getSimpleName()).log("----- {}"); + logger.info("----- {}", node.getClass().getSimpleName()); // printing out individual desired state changes for (StateChange desiredStateChange : node.getDesiredStateChanges()) { - logger.atInfo().addArgument(desiredStateChange).log("{}"); + logger.info("{}", desiredStateChange); } // printing out process() statement - logger.atInfo().addArgument(node).log("{}: process()"); + logger.info("{}: process()", node); } } } @@ -166,22 +167,17 @@ public List generateFrom(List orderedNodes) { long endTimeInNanoSeconds = System.nanoTime(); - // if (logger.isDebugEnabled()) { - logger.atDebug().log("===== INTERMEDIATE RENDERER LIST ========================="); + if (logger.isDebugEnabled()) { + logger.debug("===== INTERMEDIATE RENDERER LIST ========================="); logIntermediateRendererListForDebugging(orderedNodes); - logger.atDebug().log("===== RENDERER TASK LIST ================================="); + logger.debug("===== RENDERER TASK LIST ================================="); logList(taskList); - logger.atDebug().log("----------------------------------------------------------"); - logger.atDebug().addArgument(() -> String.format("%.3f", (endTimeInNanoSeconds - startTimeInNanoSeconds) / 1000000f)). - log("Task list generated in {} ms"); - logger.atDebug(). - addArgument(() -> nodeList.size()). - addArgument(enabledNodes). - addArgument(taskList.size() - enabledNodes). - addArgument(potentialTasks). - log("{} nodes, {} enabled - {} tasks (excluding marker tasks) out of {} potential tasks."); - logger.atDebug().log("----------------------------------------------------------"); - // } + logger.debug("----------------------------------------------------------"); + logger.debug(String.format("Task list generated in %.3f ms", (endTimeInNanoSeconds - startTimeInNanoSeconds) / 1000000f)); + logger.debug(String.format("%s nodes, %s enabled - %s tasks (excluding marker tasks) out of %s potential tasks.", + nodeList.size(), enabledNodes, taskList.size() - enabledNodes, potentialTasks)); + logger.debug("----------------------------------------------------------"); + } return taskList; } diff --git a/engine/src/main/java/org/terasology/engine/world/block/internal/BlockManagerImpl.java b/engine/src/main/java/org/terasology/engine/world/block/internal/BlockManagerImpl.java index 46832c13fc2..b5a768dfb96 100644 --- a/engine/src/main/java/org/terasology/engine/world/block/internal/BlockManagerImpl.java +++ b/engine/src/main/java/org/terasology/engine/world/block/internal/BlockManagerImpl.java @@ -95,8 +95,7 @@ public void initialise(List registeredBlockFamilies, if (id != null) { block.setId(id); } else { - logger.atError().addArgument(() -> block.getURI()).addArgument(() -> family.get().getURI()). - log("Missing id for block {} in provided family {}"); + logger.error("Missing id for block {} in provided family {}", block.getURI(), family.get().getURI()); //NOPMD if (generateNewIds) { block.setId(getNextId()); } else { @@ -157,8 +156,7 @@ public void receiveFamilyRegistration(BlockUri familyUri, Map r if (id != null) { block.setId((short) id.intValue()); } else { - logger.atError().addArgument(() -> block.getURI()).addArgument(() -> familyUri). - log("Missing id for block {} in registered family {}"); + logger.error("Missing id for block {} in registered family {}", block.getURI(), familyUri); //NOPMD block.setId(UNKNOWN_ID); } } @@ -191,7 +189,7 @@ protected void registerFamily(BlockFamily family) { private void registerBlock(Block block, RegisteredState newState) { if (block.getId() != UNKNOWN_ID) { - logger.atInfo().addArgument(() -> block).addArgument(() -> block.getId()).log("Registered Block {} with id {}"); + logger.info("Registered Block {} with id {}", block, block.getId()); //NOPMD newState.blocksById.put(block.getId(), block); newState.idByUri.put(block.getURI(), block.getId()); } else {