Skip to content

Commit

Permalink
feedback fluent-logger pr. except to make log line shorter.
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Feb 24, 2024
1 parent 7493a30 commit 5c7fa2c
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private <T extends AutoConfig> void loadSettingsFromDisk(Class<T> 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
}
}

Expand Down Expand Up @@ -116,7 +116,7 @@ private void saveConfigToDisk(AutoConfig config) {
StandardOpenOption.CREATE)) {
serializer.serialize(config, TypeInfo.of((Class<AutoConfig>) 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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ModuleInstaller implements Callable<List<Module>> {
@Override
public List<Module> call() throws Exception {
Map<URI, Path> 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<Path> downloadedModulesPaths = downloader.call();
logger.info("Module download completed, loading the new modules...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void process() {
@Override
public void registerEvent(ResourceUrn uri, Class<? extends Event> 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);
Expand All @@ -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.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) {
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public EventMetadata(Class<T> 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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public Class<? extends Event> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ public RenderTaskListGenerator() {
taskList = Lists.newArrayList();
}

@SuppressWarnings("PMD.GuardLogStatement")
private void logIntermediateRendererListForDebugging(List<Node> 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);
}
}
}
Expand Down Expand Up @@ -166,22 +167,17 @@ public List<RenderPipelineTask> generateFrom(List<Node> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ public void initialise(List<String> 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 {
Expand Down Expand Up @@ -157,8 +156,7 @@ public void receiveFamilyRegistration(BlockUri familyUri, Map<String, Integer> 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);
}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 5c7fa2c

Please sign in to comment.