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
Co-authored-by: jdrueckert <jd.rueckert@googlemail.com>
  • Loading branch information
soloturn and jdrueckert committed Mar 3, 2024
1 parent a85dbe7 commit b34da80
Show file tree
Hide file tree
Showing 49 changed files with 112 additions and 141 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ public OpenALManager(AudioConfig config) throws OpenALException {
ALCCapabilities alcCapabilities = ALC.createCapabilities(device);
AL.createCapabilities(alcCapabilities);

logger.atInfo().addArgument(() -> AL10.alGetString(AL10.AL_VERSION)).log("OpenAL {} initialized!");

logger.info("OpenAL {} initialized!", AL10.alGetString(AL10.AL_VERSION));
logger.info("Using OpenAL: {} by {}", AL10.alGetString(AL10.AL_RENDERER), AL10.alGetString(AL10.AL_VENDOR));
logger.info("Using device: {}", ALC10.alcGetString(device, ALC10.ALC_DEVICE_SPECIFIER));
logger.info("Available AL extensions: {}", AL10.alGetString(AL10.AL_EXTENSIONS));
Expand Down Expand Up @@ -261,7 +260,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 @@ -31,12 +31,13 @@ public boolean isSatisfiedBy(Locale value) {
}

@Override
@SuppressWarnings("PMD.GuardLogStatement")
public void warnUnsatisfiedBy(Locale value) {
logger.atWarn().
addArgument(value).
addArgument(() -> locales.stream()
logger.warn("Locale {} should be one of {}",
value,
locales.stream()
.map(Locale::getLanguage)
.collect(Collectors.joining(",", "[", "]"))).
log("Locale {} should be one of {}");
.collect(Collectors.joining(",", "[", "]"))
);
}
}
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 @@ -30,8 +30,7 @@ public EventLibrary(ModuleEnvironment environment, ReflectFactory reflectFactory
try {
return new EventMetadata<>(type, copyStrategies, factory, uri);
} catch (NoSuchMethodException e) {
logger.atError().addArgument(() -> type.getSimpleName()).addArgument(() -> e).
log("Unable to register class {}: Default Constructor Required");
logger.error("Unable to register class {}: Default Constructor Required", type.getSimpleName(), e); //NOPMD
return null;
}
}
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 @@ -98,7 +98,7 @@ protected boolean condition(Actor actor) throws ClassNotFoundException, NoSuchFi
secondValue = "";
break;
default:
logger.atError().addArgument(() -> tokens[0]).log("Unsupported guard value type: {}");
logger.error("Unsupported guard value type: {}", tokens[0]); //NOPMD
secondValue = "";

}
Expand All @@ -115,7 +115,7 @@ protected boolean condition(Actor actor) throws ClassNotFoundException, NoSuchFi
passing = (Boolean) fieldValue != Boolean.parseBoolean(secondValue);
break;
default:
logger.atError().addArgument(() -> tokens[2]).log("Unsupported operation for boolean values: {}");
logger.error("Unsupported operation for boolean values: {}", tokens[2]); //NOPMD

}

Expand All @@ -142,7 +142,7 @@ protected boolean condition(Actor actor) throws ClassNotFoundException, NoSuchFi
passing = ((Number) fieldValue).doubleValue() < Double.parseDouble(secondValue);
break;
default:
logger.atError().addArgument(() -> tokens[2]).log("Unsupported operation for numeric values: {}");
logger.error("Unsupported operation for numeric values: {}", tokens[2]); //NOPMD

}

Expand All @@ -157,7 +157,7 @@ protected boolean condition(Actor actor) throws ClassNotFoundException, NoSuchFi
passing = !fieldValue.equals(secondValue);
break;
default:
logger.atError().addArgument(() -> tokens[2]).log("Unsupported operation for strings: {}");
logger.error("Unsupported operation for strings: {}", tokens[2]); //NOPMD

}
} else {
Expand Down Expand Up @@ -190,8 +190,7 @@ protected boolean condition(Actor actor) throws ClassNotFoundException, NoSuchFi
break;

default:
logger.atError().addArgument(() -> fieldValue.getClass()).addArgument(() -> tokens[2]).
log("Unknown field type or operation: {} {}");
logger.error("Unknown field type or operation: {} {}", fieldValue.getClass(), tokens[2]); //NOPMD
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ public void construct(Actor actor) {
try {
action.construct(actor);
} catch (Exception e) {
logger.atDebug().addArgument(() -> action).addArgument(() -> actor.getEntity()).addArgument(() -> e).
log("Exception while running construct() of action {} from entity {}: ");
logger.debug("Exception while running construct() of action {} from entity {}: ", action, actor.getEntity(), e); //NOPMD
}
}
}
Expand All @@ -68,8 +67,7 @@ public BehaviorState execute(Actor actor) {
try {
return action.modify(actor, BehaviorState.UNDEFINED);
} catch (Exception e) {
logger.atDebug().addArgument(() -> action).addArgument(() -> actor.getEntity()).addArgument(() -> e).
log("Exception while running action {} from entity {}: ");
logger.debug("Exception while running action {} from entity {}: ", action, actor.getEntity(), e); //NOPMD
// TODO maybe returning UNDEFINED would be more fitting?
return BehaviorState.FAILURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public void construct(Actor actor) {
try {
action.construct(actor);
} catch (Exception e) {
logger.atInfo().addArgument(() -> action).addArgument(() -> actor.getEntity()).
log("Exception while running construct() of action {} from entity {}:");
logger.info("Exception while running construct() of action {} from entity {}:", action, actor.getEntity()); //NOPMD
}
}
}
Expand Down Expand Up @@ -81,8 +80,7 @@ public BehaviorState execute(Actor actor) {
try {
modifiedState = action.modify(actor, lastState);
} catch (Exception e) {
logger.atInfo().addArgument(() -> action).addArgument(() -> actor.getEntity()).addArgument(() -> e.getStackTrace()).
log("Exception while running action {} from entity {}: {}");
logger.info("Exception while running action {} from entity {}: {}", action, actor.getEntity(), e.getStackTrace()); //NOPMD
// TODO maybe returning UNDEFINED would be more canonical?
return BehaviorState.FAILURE;
}
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 @@ -84,8 +84,7 @@ public void onDestroy(final BeforeDeactivateComponent event, final EntityRef ent
@ReceiveEvent(components = {CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class})
public void onCharacterStateReceived(CharacterStateEvent state, EntityRef entity) {
if (entity.equals(localPlayer.getCharacterEntity())) {
logger.atTrace().addArgument(() -> state.getSequenceNumber()).addArgument(() -> inputs.size()).
log("Received new state, sequence number: {}, buffered input size {}");
logger.trace("Received new state, sequence number: {}, buffered input size {}", state.getSequenceNumber(), inputs.size()); //NOPMD

playerStates.remove(entity);
authoritiveState = state;
Expand All @@ -99,7 +98,7 @@ public void onCharacterStateReceived(CharacterStateEvent state, EntityRef entity
newState = stepState(input, newState, entity);
}
}
logger.atTrace().addArgument(() -> inputs.size()).log("Resultant input size {}");
logger.trace("Resultant input size {}", inputs.size()); //NOPMD
characterMovementSystemUtility.setToState(entity, newState);
// TODO: soft correct predicted state
predictedState = newState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void addMessage(String message, MessageType type, boolean newLine) {
@Override
public void addMessage(Message message) {
String uncoloredText = FontUnderline.strip(FontColor.stripColor(message.getMessage()));
logger.atInfo().addArgument(() -> message.getType()).addArgument(() -> uncoloredText).log("[{}] {}");
logger.info("[{}] {}", message.getType(), uncoloredText); //NOPMD
messageHistory.add(message);
for (ConsoleSubscriber subscriber : messageSubscribers) {
subscriber.onNewConsoleMessage(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public String shutdownServer(@Sender EntityRef sender) {
EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);

logger.atInfo().addArgument(() -> name.name).log("Shutdown triggered by {}");
logger.info("Shutdown triggered by {}", name.name); //NOPMD

gameEngine.shutdown();

Expand Down Expand Up @@ -165,7 +165,7 @@ private String kick(EntityRef clientEntity) {
EntityRef clientInfo = clientEntity.getComponent(ClientComponent.class).clientInfo;
DisplayNameComponent name = clientInfo.getComponent(DisplayNameComponent.class);

logger.atInfo().addArgument(() -> name.name).log("Kicking user {}");
logger.info("Kicking user {}", name.name); //NOPMD

networkSystem.forceDisconnect(client);
return "User kick triggered for '" + name.name + "'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public class ChunkEventErrorLogger extends BaseComponentSystem {
@ReceiveEvent(components = WorldComponent.class)
public void onNewChunk(OnChunkLoaded chunkAvailable, EntityRef worldEntity) {
if (!loadedChunks.add(chunkAvailable.getChunkPos())) {
logger.atError().addArgument(() -> chunkAvailable.getChunkPos()).log("Multiple loads of chunk {}");
logger.error("Multiple loads of chunk {}", chunkAvailable.getChunkPos()); //NOPMD
}
}

@ReceiveEvent(components = WorldComponent.class)
public void onRemoveChunk(BeforeChunkUnload chunkUnload, EntityRef worldEntity) {
if (!loadedChunks.remove(chunkUnload.getChunkPos())) {
logger.atError().addArgument(() -> chunkUnload.getChunkPos()).log("Unload event for not loaded chunk {}");
logger.error("Unload event for not loaded chunk {}", chunkUnload.getChunkPos()); //NOPMD
}
}
}
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.atWarn().addArgument(() -> itemEntity.getParentPrefab().getName()).log("Prefab {} does not have a block family");
LOGGER.warn("Prefab {} does not have a block family", itemEntity.getParentPrefab().getName()); //NOPMD
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public void onConnect(ConnectedEvent connected, EntityRef entity) {
private void restoreCharacter(EntityRef entity, EntityRef character) {

Client clientListener = networkSystem.getOwner(entity);
LOGGER.atInfo().addArgument(() -> clientListener.toString()).log("{}");
LOGGER.info("{}", clientListener);
updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());

ClientComponent client = entity.getComponent(ClientComponent.class);
Expand Down
Loading

0 comments on commit b34da80

Please sign in to comment.