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

refactor: use logger instead of System.out.println #5188

Merged
merged 4 commits into from
Jan 21, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.google.common.collect.Multimaps;
import com.google.common.collect.SortedSetMultimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.core.module.ExternalApiWhitelist;
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.testUtil.ModuleManagerFactory;
Expand All @@ -18,7 +20,10 @@
/**
* Enumerates all classes and packages that are annotated with {@link API}.
*/
@SuppressWarnings("PMD.SystemPrintln") // main entrypoint used to generate documentation
public final class ApiScraper {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiScraper.class);
soloturn marked this conversation as resolved.
Show resolved Hide resolved

private ApiScraper() {
// Private constructor, utility class
}
Expand All @@ -35,7 +40,7 @@ public static void main(String[] args) throws Exception {
SortedSetMultimap<String, String> sortedApi = Multimaps.newSortedSetMultimap(new HashMap<>(), TreeSet::new);

for (Class<?> apiClass : environment.getTypesAnnotatedWith(API.class)) {
//System.out.println("Processing: " + apiClass);
LOGGER.debug("Processing: {}", apiClass);
soloturn marked this conversation as resolved.
Show resolved Hide resolved
boolean isPackage = apiClass.isSynthetic();
URL location;
String category;
Expand All @@ -49,7 +54,7 @@ public static void main(String[] args) throws Exception {
}

if (location == null) {
System.out.println("Failed to get a class/package location, skipping " + apiClass);
LOGGER.info("Failed to get a class/package location, skipping {}", apiClass);
continue;
}

Expand Down Expand Up @@ -91,7 +96,7 @@ public static void main(String[] args) throws Exception {
break;

default :
System.out.println("Unknown protocol for: " + apiClass + ", came from " + location);
LOGGER.info("Unknown protocol for: {}, came from {}", apiClass, location);
}
}
sortedApi.putAll("external", ExternalApiWhitelist.CLASSES.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.core.module.ModuleManager;
import org.terasology.engine.input.DefaultBinding;
import org.terasology.engine.input.DefaultBindings;
Expand All @@ -18,7 +20,9 @@
/**
* Enumerates all default key bindings and writes them sorted by ID to the console
*/
@SuppressWarnings("PMD.SystemPrintln") // main entrypoint used to generate documentation
public final class BindingScraper {
private static final Logger LOGGER = LoggerFactory.getLogger(BindingScraper.class);
soloturn marked this conversation as resolved.
Show resolved Hide resolved

private BindingScraper() {
// Utility class, no instances
Expand Down Expand Up @@ -55,14 +59,14 @@ public static void main(String[] args) throws Exception {
if (cat.isEmpty()) {
InputCategory inputCategory = findEntry(categories, id);
if (inputCategory == null) {
System.out.println("Invalid category for: " + info.id());
LOGGER.info("Invalid category for: {}", info.id());
}
} else {
InputCategory inputCategory = findCategory(categories, cat);
if (inputCategory != null) {
categories.put(inputCategory, id);
} else {
System.out.println("Invalid category for: " + info.id());
LOGGER.info("Invalid category for: {}", info.id());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
package org.terasology.documentation.apiScraper;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.documentation.apiScraper.util.ApiMethod;

import java.io.BufferedReader;
Expand All @@ -20,7 +22,7 @@
* Detects API changes between two instances of a scanned code base.
*/
public final class ApiComparator {
soloturn marked this conversation as resolved.
Show resolved Hide resolved

private static final Logger LOGGER = LoggerFactory.getLogger(ApiComparator.class);
private static final String ORIGINAL_API_FILE = "API_file.txt";
private static final String NEW_API_FILE = "New_API_file.txt";

Expand Down Expand Up @@ -54,10 +56,10 @@ public static void main(String[] args) throws Exception {
br2.close();

//Begins comparison and increases report
System.out.println("=================================================================");
LOGGER.info("=================================================================");
checkClassAdditionAndDeletion(originalApi, newApi);
checkMethodChanges(originalApi, newApi);
System.out.println("REPORT FINISHED");
LOGGER.info("REPORT FINISHED");
}
}

Expand Down Expand Up @@ -113,16 +115,16 @@ private static Map<String, Collection<ApiMethod>> getApi(BufferedReader br) thro
}

private static void checkClassAdditionAndDeletion(Map<String, Collection<ApiMethod>> originalApi, Map<String, Collection<ApiMethod>> newApi) {
System.out.println("Checking Class Addition and Deletion");
LOGGER.info("Checking Class Addition and Deletion");
for (String className : originalApi.keySet()) {
if (!newApi.containsKey(className)) {
System.out.println("MAJOR INCREASE, DELETION OF " + className);
LOGGER.info("MAJOR INCREASE, DELETION OF {}", className);
}
}

for (String className : newApi.keySet()) {
if (!originalApi.containsKey(className)) {
System.out.println("MINOR INCREASE, ADDITION OF " + className);
LOGGER.info("MINOR INCREASE, ADDITION OF {}", className);
}
}
}
Expand All @@ -134,7 +136,7 @@ private static void checkClassAdditionAndDeletion(Map<String, Collection<ApiMeth
*/
private static void checkMethodChanges(Map<String, Collection<ApiMethod>> originalApi,
Map<String, Collection<ApiMethod>> newApi) {
System.out.println("Checking Method Changes");
LOGGER.info("Checking Method Changes");
Collection<ApiMethod> originalMethods;
Collection<ApiMethod> newMethods;
for (String className : originalApi.keySet()) {
Expand All @@ -158,9 +160,9 @@ private static void checkMethodChanges(Map<String, Collection<ApiMethod>> origin
if (auxMethod2.getName().equals("")) {
checkMethodIncrease(method1, method2);
} else if (isInterfaceOrAbstract(method2.getClassName())) {
System.out.println("MINOR INCREASE, NEW OVERLOADED METHOD " + method2.getName() +
" ON " + method2.getClassName() + "\nNEW PARAMETERS: " + method2.getParametersType());
System.out.println("=================================================================");
LOGGER.info("MINOR INCREASE, NEW OVERLOADED METHOD {} ON {}\nNEW PARAMETERS: {}",
method2.getName(), method2.getClassName(), method2.getParametersType());
LOGGER.info("=================================================================");
}

} else {
Expand All @@ -173,7 +175,7 @@ private static void checkMethodChanges(Map<String, Collection<ApiMethod>> origin
if (!found) {
if (isInterfaceOrAbstract(method2.getClassName())) {
if (method2.getName().endsWith("(ABSTRACT METHOD)")) {
System.out.println("MAJOR INCREASE, NEW ABSTRACT METHOD " + method2.getName() + " ON " + method2.getClassName());
LOGGER.info("MAJOR INCREASE, NEW ABSTRACT METHOD {} ON {}", method2.getName(), method2.getClassName());
} else {
String minorOrMajor;
if (method2.getClassName().endsWith("(INTERFACE)")) {
Expand All @@ -185,12 +187,12 @@ private static void checkMethodChanges(Map<String, Collection<ApiMethod>> origin
} else {
minorOrMajor = "MINOR";
}
System.out.println(minorOrMajor + " INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName());
LOGGER.info(minorOrMajor + " INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName());
}
} else {
System.out.println("MINOR INCREASE, NEW METHOD " + method2.getName() + " ON " + method2.getClassName());
LOGGER.info("MINOR INCREASE, NEW METHOD {} ON {}", method2.getName(), method2.getClassName());
}
System.out.println("=================================================================");
LOGGER.info("=================================================================");
}
}
}
Expand Down Expand Up @@ -222,15 +224,15 @@ private static void checkMethodDeletion(Collection<ApiMethod> originalMethods, C
ApiMethod result = getMethodWithSameNameAndParameters(method, newMethodsWithSameName);
if (result.getName().equals("")) {
checkedMethods.add(method.getName());
System.out.println("MAJOR INCREASE, OVERLOADED METHOD DELETION: " + method.getName()
LOGGER.info("MAJOR INCREASE, OVERLOADED METHOD DELETION: " + method.getName()
+ " ON " + method.getClassName() + "\nPARAMETERS: " + method.getParametersType());

}
}
}
}
if (!found) {
System.out.println("MAJOR INCREASE, METHOD DELETION: " + method1.getName() + " ON " + method1.getClassName());
LOGGER.info("MAJOR INCREASE, METHOD DELETION: " + method1.getName() + " ON " + method1.getClassName());
}
}
}
Expand Down Expand Up @@ -260,10 +262,10 @@ private static void checkMethodIncrease(ApiMethod method1, ApiMethod method2) {
*/
private static void check(String s1, String s2, String methodName, String className) {
if (!s1.equals(s2)) {
System.out.println("MAJOR INCREASE ON : " + methodName + " " + className);
System.out.println("ORIGINAL: " + s1);
System.out.println("NEW: " + s2);
System.out.println("=================================================================");
LOGGER.info("MAJOR INCREASE ON : " + methodName + " " + className);
LOGGER.info("ORIGINAL: " + s1);
LOGGER.info("NEW: " + s2);
LOGGER.info("=================================================================");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: Apache-2.0
package org.terasology.documentation.apiScraper;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
Expand All @@ -10,6 +13,7 @@
* Saves the API generated by CompleteApiScraper in a txt file.
*/
public final class ApiSaver {
private static final Logger LOGGER = LoggerFactory.getLogger(ApiSaver.class);

private ApiSaver() {

Expand All @@ -21,6 +25,6 @@ public static void main(String[] args) throws Exception {
writer.write(api.toString());
writer.flush();
writer.close();
System.out.println("API file is ready!");
LOGGER.info("API file is ready!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.config.Config;
import org.terasology.engine.context.internal.ContextImpl;
import org.terasology.engine.context.internal.MockContext;
Expand All @@ -19,6 +21,7 @@


public class IntMathTest {
private static final Logger LOGGER = LoggerFactory.getLogger(IntMathTest.class);
public IntMathTest() {
}

Expand Down Expand Up @@ -128,7 +131,7 @@ private static List<Integer> generateAllPowersOfTwo() {
value <<= 1;
}

System.out.println(powersOfTwo.get(powersOfTwo.size() - 1));
LOGGER.info(String.valueOf(powersOfTwo.get(powersOfTwo.size() - 1)));

return powersOfTwo;
}
Expand Down
11 changes: 6 additions & 5 deletions engine/src/main/java/org/terasology/engine/core/PathManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.google.common.collect.ImmutableList;
import com.sun.jna.platform.win32.KnownFolders;
import com.sun.jna.platform.win32.Shell32Util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasology.engine.context.Context;
import org.terasology.engine.core.subsystem.DisplayDevice;
import org.terasology.engine.utilities.OS;
Expand All @@ -30,6 +32,7 @@
* Manager class that keeps track of the game's various paths and save directories.
*/
public final class PathManager {
private static final Logger LOGGER = LoggerFactory.getLogger(PathManager.class);
private static final String TERASOLOGY_FOLDER_NAME = "Terasology";
private static final Path LINUX_HOME_SUBPATH = Paths.get(".local", "share", "terasology");

Expand Down Expand Up @@ -75,11 +78,9 @@ private static Path findInstallPath() {
URI urlToSource = PathManager.class.getProtectionDomain().getCodeSource().getLocation().toURI();
Path codeLocation = Paths.get(urlToSource);
installationSearchPaths.add(codeLocation);
// Not using logger because it's usually initialized after PathManager.
System.out.println("PathManager: Initial code location is " + codeLocation.toAbsolutePath());
LOGGER.info("PathManager: Initial code location is " + codeLocation.toAbsolutePath());
} catch (URISyntaxException e) {
System.err.println("PathManager: Failed to convert code location to path.");
e.printStackTrace();
LOGGER.error("PathManager: Failed to convert code location to path.", e);
}

// But that's not always true. This jar may be loaded from somewhere else on the classpath.
Expand All @@ -89,7 +90,7 @@ private static Path findInstallPath() {
// Use the current directory as a fallback.
Path currentDirectory = Paths.get("").toAbsolutePath();
installationSearchPaths.add(currentDirectory);
System.out.println("PathManager: Working directory is " + currentDirectory);
LOGGER.info("PathManager: Working directory is " + currentDirectory);

for (Path startPath : installationSearchPaths) {
Path installationPath = findNativesHome(startPath, 5);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@

@RegisterSystem(RegisterMode.AUTHORITY)
public class PlayerSystem extends BaseComponentSystem implements UpdateSubscriberSystem {

private static final Logger logger = LoggerFactory.getLogger(PlayerSystem.class);
private static final Logger LOGGER = LoggerFactory.getLogger(PlayerSystem.class);
@In
private EntityManager entityManager;
@In
Expand Down Expand Up @@ -156,7 +155,7 @@ public void onConnect(ConnectedEvent connected, EntityRef entity) {
private void restoreCharacter(EntityRef entity, EntityRef character) {

Client clientListener = networkSystem.getOwner(entity);
System.out.println(clientListener);
LOGGER.info(clientListener.toString());
updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());

ClientComponent client = entity.getComponent(ClientComponent.class);
Expand Down Expand Up @@ -247,7 +246,7 @@ private void respawnPlayer(EntityRef clientEntity) {
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));

logger.debug("Re-spawing player at: {}", spawnPosition);
LOGGER.debug("Re-spawing player at: {}", spawnPosition);

Client clientListener = networkSystem.getOwner(clientEntity);
Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
Expand Down
Loading