From cfdfedbd2e2ed4b140c0f82e6322d335a1e4f39d Mon Sep 17 00:00:00 2001 From: Joshua Jimenez Date: Mon, 14 Oct 2019 04:41:11 +0800 Subject: [PATCH] #970 single logging framework should be enforced (#982) * #496 Add pipeline module to parent pom :sparkles: * #496: Add main application class and test for pipeline * #496: Checkstyle format and add log messages on pipeline stages :art: * #496: Fill readme sections of pipeline :sparkles: * #496: Javadocs and checkstyle formatting :art: * #496: Follow PMD checks and add more explanation as block comment on App.java * #496: Apply requested PR changes by iluwatar :art: * #970: Replace log4j usage on commander pattern to Slf4j API :art: * #970: Replace log4j usage on dao pattern to Slf4j API :art: * #970: Replace log4j usage on data mapper pattern to Slf4j API :art: * #970: Remove log4j dependency on data transfer object pom :fire: * #970: Replace log4j usage on module pattern to Slf4j API :art: * #970: Replace log4j usage on serverless pattern to Slf4j API :art: This also removes the aws log4j dependency * #970: Remove unnecessary gitignore line for log4j.xml :fire: * #970: Remove remaining remnants of log4j :fire: * #970: Replace System.out logging with appropriate logging methods :art: * #970: Replace System.out method references to Logger::info :art: --- .gitignore | 1 - .../iluwatar/collectionpipeline/AppTest.java | 7 ++- commander/pom.xml | 5 -- commander/properties/log4j.properties | 41 ---------------- .../com/iluwatar/commander/Commander.java | 19 +++---- .../messagingservice/MessagingService.java | 5 +- .../main/java/com/iluwatar/converter/App.java | 14 ++++-- dao/pom.xml | 49 ------------------- dao/src/main/java/com/iluwatar/dao/App.java | 9 ++-- .../java/com/iluwatar/dao/DbCustomerDao.java | 7 +-- dao/src/main/resources/log4j.xml | 41 ---------------- data-mapper/pom.xml | 4 -- .../java/com/iluwatar/datamapper/App.java | 7 +-- data-mapper/src/main/resources/log4j.xml | 41 ---------------- data-transfer-object/pom.xml | 4 -- .../main/java/com/iluwatar/dirtyflag/App.java | 9 +++- .../com/iluwatar/dirtyflag/DataFetcher.java | 8 ++- .../java/com/iluwatar/event/queue/App.java | 7 ++- .../administration/ConsoleAdministration.java | 2 +- .../hexagonal/service/ConsoleLottery.java | 2 +- .../service/LotteryConsoleServiceImpl.java | 2 +- .../java/com/iluwatar/masterworker/App.java | 8 +-- .../masterworker/ArrayUtilityMethods.java | 10 ++-- module/pom.xml | 4 -- .../iluwatar/module/ConsoleLoggerModule.java | 7 +-- .../com/iluwatar/module/FileLoggerModule.java | 7 +-- module/src/main/resources/log4j.xml | 41 ---------------- .../iluwatar/module/FileLoggerModuleTest.java | 5 +- naked-objects/dom/exclude-pmd.properties | 24 --------- naked-objects/dom/pom.xml | 1 - .../bootstrap/SimpleAppSystemInitializer.java | 1 - .../specglue/BootstrappingGlue.java | 1 - .../integtests/tests/SimpleAppIntegTest.java | 1 - naked-objects/webapp/pom.xml | 20 -------- .../domainapp/webapp/SimpleApplication.java | 5 +- .../ConvertToCharArrayHandler.java | 4 +- .../RemoveAlphabetsHandler.java | 4 +- .../RemoveDigitsHandler.java | 4 +- pom.xml | 7 --- serverless/pom.xml | 5 -- .../baas/api/FindPersonApiHandler.java | 11 +++-- .../baas/api/SavePersonApiHandler.java | 5 +- .../faas/api/LambdaInfoApiHandler.java | 7 ++- .../src/main/resources/log4j.properties | 29 ----------- .../com/iluwatar/spatialpartition/App.java | 14 ++++-- .../com/iluwatar/spatialpartition/Bubble.java | 6 ++- tls/src/main/java/com/iluwatar/tls/App.java | 15 ++++-- .../com/iluwatar/tls/DateFormatCallable.java | 9 +++- .../java/com/iluwatar/typeobject/App.java | 17 ++++--- .../com/iluwatar/typeobject/CandyGame.java | 17 ++++--- 50 files changed, 163 insertions(+), 410 deletions(-) delete mode 100644 commander/properties/log4j.properties delete mode 100644 dao/src/main/resources/log4j.xml delete mode 100644 data-mapper/src/main/resources/log4j.xml delete mode 100644 module/src/main/resources/log4j.xml delete mode 100644 naked-objects/dom/exclude-pmd.properties delete mode 100644 serverless/src/main/resources/log4j.properties diff --git a/.gitignore b/.gitignore index fd0bb7810..ada1e7d10 100644 --- a/.gitignore +++ b/.gitignore @@ -16,5 +16,4 @@ datanucleus.log /bin/ /bin/ *.log -data-mapper/src/main/resources/log4j.xml event-sourcing/Journal.json diff --git a/collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java b/collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java index 83756985f..938cce195 100644 --- a/collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java +++ b/collection-pipeline/src/test/java/com/iluwatar/collectionpipeline/AppTest.java @@ -30,12 +30,15 @@ import java.util.List; import java.util.Map; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Tests that Collection Pipeline methods work as expected. */ public class AppTest { - + private static final Logger LOGGER = LoggerFactory.getLogger(AppTest.class); + private List cars = CarFactory.createCars(); @Test @@ -61,7 +64,7 @@ public class AppTest { new Car("Jeep", "Comanche", 1990, Category.JEEP))); Map> modelsFunctional = FunctionalProgramming.getGroupingOfCarsByCategory(cars); Map> modelsImperative = ImperativeProgramming.getGroupingOfCarsByCategory(cars); - System.out.println("Category " + modelsFunctional); + LOGGER.info("Category " + modelsFunctional); assertEquals(modelsExpected, modelsFunctional); assertEquals(modelsExpected, modelsImperative); } diff --git a/commander/pom.xml b/commander/pom.xml index 4db6b12e7..fbe453377 100644 --- a/commander/pom.xml +++ b/commander/pom.xml @@ -36,10 +36,5 @@ junit-jupiter-engine test - - log4j - log4j - 1.2.17 - diff --git a/commander/properties/log4j.properties b/commander/properties/log4j.properties deleted file mode 100644 index 656901554..000000000 --- a/commander/properties/log4j.properties +++ /dev/null @@ -1,41 +0,0 @@ -# -# The MIT License -# Copyright © 2014-2019 Ilkka Seppälä -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -#Define root logger options -log4j.rootLogger=TRACE, file, console - -#Define console appender -log4j.appender.console=org.apache.log4j.ConsoleAppender -logrj.appender.console.Target=System.out -log4j.appender.console.layout=org.apache.log4j.PatternLayout -log4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd} %d{HH:mm:ss} %5p[%t] %m%n - -#Define rolling file appender -log4j.appender.file=org.apache.log4j.RollingFileAppender -log4j.appender.file.File=/log/logFile.log -log4j.appender.file.Append=true -log4j.appender.file.ImmediateFlush=true -log4j.appender.file.MaxFileSize=10MB -log4j.appender.file.MaxBackupIndex=5 -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d %d{HH:mm:ss} %5p[%t] %m%n diff --git a/commander/src/main/java/com/iluwatar/commander/Commander.java b/commander/src/main/java/com/iluwatar/commander/Commander.java index 8729ea75a..dee12df1c 100644 --- a/commander/src/main/java/com/iluwatar/commander/Commander.java +++ b/commander/src/main/java/com/iluwatar/commander/Commander.java @@ -23,7 +23,6 @@ package com.iluwatar.commander; import java.util.ArrayList; -import org.apache.log4j.Logger; import com.iluwatar.commander.employeehandle.EmployeeHandle; import com.iluwatar.commander.exceptions.DatabaseUnavailableException; import com.iluwatar.commander.exceptions.ItemUnavailableException; @@ -37,6 +36,8 @@ import com.iluwatar.commander.queue.QueueDatabase; import com.iluwatar.commander.queue.QueueTask; import com.iluwatar.commander.queue.QueueTask.TaskType; import com.iluwatar.commander.shippingservice.ShippingService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

Commander pattern is used to handle all issues that can come up while making a @@ -86,7 +87,7 @@ public class Commander { private final long messageTime; private final long employeeTime; private boolean finalSiteMsgShown; - static final Logger LOG = Logger.getLogger(Commander.class); + static final Logger LOG = LoggerFactory.getLogger(Commander.class); //we could also have another db where it stores all orders Commander(EmployeeHandle empDb, PaymentService pService, ShippingService sService, @@ -125,27 +126,27 @@ public class Commander { String transactionId = shippingService.receiveRequest(order.item, order.user.address); //could save this transaction id in a db too LOG.info("Order " + order.id + ": Shipping placed successfully, transaction id: " + transactionId); - System.out.println("Order has been placed and will be shipped to you. Please wait while we make your" + LOG.info("Order has been placed and will be shipped to you. Please wait while we make your" + " payment... "); sendPaymentRequest(order); return; }; Retry.HandleErrorIssue handleError = (o,err) -> { if (ShippingNotPossibleException.class.isAssignableFrom(err.getClass())) { - System.out.println("Shipping is currently not possible to your address. We are working on the problem " + LOG.info("Shipping is currently not possible to your address. We are working on the problem " + "and will get back to you asap."); finalSiteMsgShown = true; LOG.info("Order " + order.id + ": Shipping not possible to address, trying to add problem to employee db.."); employeeHandleIssue(o); } else if (ItemUnavailableException.class.isAssignableFrom(err.getClass())) { - System.out.println("This item is currently unavailable. We will inform you as soon as the item becomes " + LOG.info("This item is currently unavailable. We will inform you as soon as the item becomes " + "available again."); finalSiteMsgShown = true; LOG.info("Order " + order.id + ": Item " + order.item + " unavailable, trying to add problem to employee " + "handle.."); employeeHandleIssue(o); } else { - System.out.println("Sorry, there was a problem in creating your order. Please try later."); + LOG.info("Sorry, there was a problem in creating your order. Please try later."); LOG.error("Order " + order.id + ": Shipping service unavailable, order not placed.."); finalSiteMsgShown = true; } @@ -183,7 +184,7 @@ public class Commander { order.paid = PaymentStatus.Done; LOG.info("Order " + order.id + ": Payment successful, transaction Id: " + transactionId); if (!finalSiteMsgShown) { - System.out.println("Payment made successfully, thank you for shopping with us!!"); + LOG.info("Payment made successfully, thank you for shopping with us!!"); finalSiteMsgShown = true; } sendSuccessMessage(order); @@ -193,7 +194,7 @@ public class Commander { Retry.HandleErrorIssue handleError = (o,err) -> { if (PaymentDetailsErrorException.class.isAssignableFrom(err.getClass())) { if (!finalSiteMsgShown) { - System.out.println("There was an error in payment. Your account/card details may have been incorrect. " + LOG.info("There was an error in payment. Your account/card details may have been incorrect. " + "Meanwhile, your order has been converted to COD and will be shipped."); finalSiteMsgShown = true; } @@ -204,7 +205,7 @@ public class Commander { try { if (o.messageSent.equals(MessageSent.NoneSent)) { if (!finalSiteMsgShown) { - System.out.println("There was an error in payment. We are on it, and will get back to you " + LOG.info("There was an error in payment. We are on it, and will get back to you " + "asap. Don't worry, your order has been placed and will be shipped."); finalSiteMsgShown = true; } diff --git a/commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java b/commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java index 27c1eee3f..5023cfa1f 100644 --- a/commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java +++ b/commander/src/main/java/com/iluwatar/commander/messagingservice/MessagingService.java @@ -24,6 +24,8 @@ package com.iluwatar.commander.messagingservice; import com.iluwatar.commander.Service; import com.iluwatar.commander.exceptions.DatabaseUnavailableException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The MessagingService is used to send messages to user regarding their order and @@ -32,6 +34,7 @@ import com.iluwatar.commander.exceptions.DatabaseUnavailableException; */ public class MessagingService extends Service { + private static final Logger LOGGER = LoggerFactory.getLogger(MessagingService.class); enum MessageToSend { PaymentFail, PaymentTrying, PaymentSuccessful @@ -74,7 +77,7 @@ public class MessagingService extends Service { MessageRequest req = (MessageRequest) parameters[0]; if (this.database.get(req.reqId) == null) { //idempotence, in case db fails here database.add(req); //if successful: - System.out.println(sendMessage(req.msg)); + LOGGER.info(sendMessage(req.msg)); return req.reqId; } return null; diff --git a/converter/src/main/java/com/iluwatar/converter/App.java b/converter/src/main/java/com/iluwatar/converter/App.java index 7d0821c5b..b21d4dd6a 100644 --- a/converter/src/main/java/com/iluwatar/converter/App.java +++ b/converter/src/main/java/com/iluwatar/converter/App.java @@ -24,6 +24,8 @@ package com.iluwatar.converter; import com.google.common.collect.Lists; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.List; @@ -35,6 +37,8 @@ import java.util.List; * objects between types. */ public class App { + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program entry point * @@ -45,16 +49,16 @@ public class App { UserDto dtoUser = new UserDto("John", "Doe", true, "whatever[at]wherever.com"); User user = userConverter.convertFromDto(dtoUser); - System.out.println("Entity converted from DTO:" + user); + LOGGER.info("Entity converted from DTO:" + user); ArrayList users = Lists.newArrayList(new User("Camile", "Tough", false, "124sad"), new User("Marti", "Luther", true, "42309fd"), new User("Kate", "Smith", true, "if0243")); - System.out.println("Domain entities:"); - users.forEach(System.out::println); + LOGGER.info("Domain entities:"); + users.stream().map(User::toString).forEach(LOGGER::info); - System.out.println("DTO entities converted from domain:"); + LOGGER.info("DTO entities converted from domain:"); List dtoEntities = userConverter.createFromEntities(users); - dtoEntities.forEach(System.out::println); + dtoEntities.stream().map(UserDto::toString).forEach(LOGGER::info); } } diff --git a/dao/pom.xml b/dao/pom.xml index b8453f6a5..5d6bc9454 100644 --- a/dao/pom.xml +++ b/dao/pom.xml @@ -40,10 +40,6 @@ junit-jupiter-engine test - - log4j - log4j - com.h2database h2 @@ -53,49 +49,4 @@ mockito-core - - - - - - - - src/main/resources - - - src/main/resources - - log4j.xml - - .. - - - - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.6 - - - log4j.xml - - - - true - - - - - - - diff --git a/dao/src/main/java/com/iluwatar/dao/App.java b/dao/src/main/java/com/iluwatar/dao/App.java index 5824d48cf..08d0a42bd 100644 --- a/dao/src/main/java/com/iluwatar/dao/App.java +++ b/dao/src/main/java/com/iluwatar/dao/App.java @@ -31,8 +31,9 @@ import java.util.stream.Stream; import javax.sql.DataSource; -import org.apache.log4j.Logger; import org.h2.jdbcx.JdbcDataSource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Data Access Object (DAO) is an object that provides an abstract interface to some type of @@ -50,7 +51,7 @@ import org.h2.jdbcx.JdbcDataSource; */ public class App { private static final String DB_URL = "jdbc:h2:~/dao"; - private static Logger log = Logger.getLogger(App.class); + private static Logger log = LoggerFactory.getLogger(App.class); private static final String ALL_CUSTOMERS = "customerDao.getAllCustomers(): "; /** @@ -94,7 +95,7 @@ public class App { addCustomers(customerDao); log.info(ALL_CUSTOMERS); try (Stream customerStream = customerDao.getAll()) { - customerStream.forEach((customer) -> log.info(customer)); + customerStream.forEach((customer) -> log.info(customer.toString())); } log.info("customerDao.getCustomerById(2): " + customerDao.getById(2)); final Customer customer = new Customer(4, "Dan", "Danson"); @@ -105,7 +106,7 @@ public class App { customerDao.update(customer); log.info(ALL_CUSTOMERS); try (Stream customerStream = customerDao.getAll()) { - customerStream.forEach((cust) -> log.info(cust)); + customerStream.forEach((cust) -> log.info(cust.toString())); } customerDao.delete(customer); log.info(ALL_CUSTOMERS + customerDao.getAll()); diff --git a/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java b/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java index 9d183e912..d8640dcb9 100644 --- a/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java +++ b/dao/src/main/java/com/iluwatar/dao/DbCustomerDao.java @@ -22,6 +22,9 @@ */ package com.iluwatar.dao; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -35,15 +38,13 @@ import java.util.stream.StreamSupport; import javax.sql.DataSource; -import org.apache.log4j.Logger; - /** * An implementation of {@link CustomerDao} that persists customers in RDBMS. * */ public class DbCustomerDao implements CustomerDao { - private static final Logger LOGGER = Logger.getLogger(DbCustomerDao.class); + private static final Logger LOGGER = LoggerFactory.getLogger(DbCustomerDao.class); private final DataSource dataSource; diff --git a/dao/src/main/resources/log4j.xml b/dao/src/main/resources/log4j.xml deleted file mode 100644 index 5c7e49d51..000000000 --- a/dao/src/main/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/data-mapper/pom.xml b/data-mapper/pom.xml index cf53fdf65..7da70f8fd 100644 --- a/data-mapper/pom.xml +++ b/data-mapper/pom.xml @@ -37,9 +37,5 @@ junit-jupiter-engine test - - log4j - log4j - diff --git a/data-mapper/src/main/java/com/iluwatar/datamapper/App.java b/data-mapper/src/main/java/com/iluwatar/datamapper/App.java index 3504ebbe1..6b1d99253 100644 --- a/data-mapper/src/main/java/com/iluwatar/datamapper/App.java +++ b/data-mapper/src/main/java/com/iluwatar/datamapper/App.java @@ -22,9 +22,10 @@ */ package com.iluwatar.datamapper; -import java.util.Optional; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import org.apache.log4j.Logger; +import java.util.Optional; /** * The Data Mapper (DM) is a layer of software that separates the in-memory objects from the @@ -39,7 +40,7 @@ import org.apache.log4j.Logger; */ public final class App { - private static Logger log = Logger.getLogger(App.class); + private static Logger log = LoggerFactory.getLogger(App.class); private static final String STUDENT_STRING = "App.main(), student : "; diff --git a/data-mapper/src/main/resources/log4j.xml b/data-mapper/src/main/resources/log4j.xml deleted file mode 100644 index 5c7e49d51..000000000 --- a/data-mapper/src/main/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/data-transfer-object/pom.xml b/data-transfer-object/pom.xml index 20c8a52f6..ebdb15afa 100644 --- a/data-transfer-object/pom.xml +++ b/data-transfer-object/pom.xml @@ -37,9 +37,5 @@ junit-jupiter-engine test - - log4j - log4j - diff --git a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java index af95b57bc..e5368bc3a 100644 --- a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java +++ b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/App.java @@ -22,6 +22,9 @@ */ package com.iluwatar.dirtyflag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.List; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -48,6 +51,8 @@ import java.util.concurrent.TimeUnit; * when needed. {@link World} mainly serves the data to the front-end. */ public class App { + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program execution point */ @@ -59,9 +64,9 @@ public class App { @Override public void run() { List countries = world.fetch(); - System.out.println("Our world currently has the following countries:-"); + LOGGER.info("Our world currently has the following countries:-"); for (String country : countries) { - System.out.println("\t" + country); + LOGGER.info("\t" + country); } } }, 0, 15, TimeUnit.SECONDS); // Run at every 15 seconds. diff --git a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/DataFetcher.java b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/DataFetcher.java index 3b91ccd7d..eca422a86 100644 --- a/dirty-flag/src/main/java/com/iluwatar/dirtyflag/DataFetcher.java +++ b/dirty-flag/src/main/java/com/iluwatar/dirtyflag/DataFetcher.java @@ -22,6 +22,10 @@ */ package com.iluwatar.dirtyflag; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.xml.crypto.Data; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; @@ -37,6 +41,8 @@ import java.util.List; */ public class DataFetcher { + private static final Logger LOGGER = LoggerFactory.getLogger(DataFetcher.class); + private final String filename = "world.txt"; private long lastFetched; @@ -62,7 +68,7 @@ public class DataFetcher { File file = new File(classLoader.getResource(filename).getFile()); if (isDirty(file.lastModified())) { - System.out.println(filename + " is dirty! Re-fetching file content..."); + LOGGER.info(filename + " is dirty! Re-fetching file content..."); List data = new ArrayList(); try (BufferedReader br = new BufferedReader(new FileReader(file))) { diff --git a/event-queue/src/main/java/com/iluwatar/event/queue/App.java b/event-queue/src/main/java/com/iluwatar/event/queue/App.java index 88cc0bf57..87ad78ae6 100644 --- a/event-queue/src/main/java/com/iluwatar/event/queue/App.java +++ b/event-queue/src/main/java/com/iluwatar/event/queue/App.java @@ -22,6 +22,9 @@ */ package com.iluwatar.event.queue; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -39,6 +42,8 @@ import javax.sound.sampled.UnsupportedAudioFileException; * items from the queue at a later time. */ public class App { + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program entry point. * @@ -51,7 +56,7 @@ public class App { audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f); audio.playSound(audio.getAudioStream("./etc/Closed-Hi-Hat-1.wav"), -8.0f); - System.out.println("Press Enter key to stop the program..."); + LOGGER.info("Press Enter key to stop the program..."); try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) { br.read(); } diff --git a/hexagonal/src/main/java/com/iluwatar/hexagonal/administration/ConsoleAdministration.java b/hexagonal/src/main/java/com/iluwatar/hexagonal/administration/ConsoleAdministration.java index f2aa6d681..4d51710b9 100644 --- a/hexagonal/src/main/java/com/iluwatar/hexagonal/administration/ConsoleAdministration.java +++ b/hexagonal/src/main/java/com/iluwatar/hexagonal/administration/ConsoleAdministration.java @@ -81,7 +81,7 @@ public class ConsoleAdministration { } private static String readString(Scanner scanner) { - System.out.print("> "); + LOGGER.info("> "); return scanner.next(); } } diff --git a/hexagonal/src/main/java/com/iluwatar/hexagonal/service/ConsoleLottery.java b/hexagonal/src/main/java/com/iluwatar/hexagonal/service/ConsoleLottery.java index 583bf348f..3a41e1ef3 100644 --- a/hexagonal/src/main/java/com/iluwatar/hexagonal/service/ConsoleLottery.java +++ b/hexagonal/src/main/java/com/iluwatar/hexagonal/service/ConsoleLottery.java @@ -82,7 +82,7 @@ public class ConsoleLottery { } private static String readString(Scanner scanner) { - System.out.print("> "); + LOGGER.info("> "); return scanner.next(); } } diff --git a/hexagonal/src/main/java/com/iluwatar/hexagonal/service/LotteryConsoleServiceImpl.java b/hexagonal/src/main/java/com/iluwatar/hexagonal/service/LotteryConsoleServiceImpl.java index 17f5f1a9b..d61ec9108 100644 --- a/hexagonal/src/main/java/com/iluwatar/hexagonal/service/LotteryConsoleServiceImpl.java +++ b/hexagonal/src/main/java/com/iluwatar/hexagonal/service/LotteryConsoleServiceImpl.java @@ -122,7 +122,7 @@ public class LotteryConsoleServiceImpl implements LotteryConsoleService { } private String readString(Scanner scanner) { - System.out.print( "> " ); + logger.info( "> " ); return scanner.next(); } } diff --git a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java index ce1f7b625..46c0baf8d 100644 --- a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java +++ b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/App.java @@ -23,6 +23,8 @@ package com.iluwatar.masterworker; import com.iluwatar.masterworker.system.ArrayTransposeMasterWorker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** *

The Master-Worker pattern is used when the problem at hand can be solved by dividing into @@ -45,7 +47,8 @@ import com.iluwatar.masterworker.system.ArrayTransposeMasterWorker; */ public class App { - + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program entry point. * @param args command line args @@ -60,10 +63,9 @@ public class App { ArrayResult result = (ArrayResult) mw.getResult(input); if (result != null) { ArrayUtilityMethods.printMatrix(inputMatrix); - System.out.println(""); ArrayUtilityMethods.printMatrix(result.data); } else { - System.out.println("Please enter non-zero input"); + LOGGER.info("Please enter non-zero input"); } } diff --git a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayUtilityMethods.java b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayUtilityMethods.java index e3125abe8..fb27e5b48 100644 --- a/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayUtilityMethods.java +++ b/master-worker-pattern/src/main/java/com/iluwatar/masterworker/ArrayUtilityMethods.java @@ -22,6 +22,9 @@ */ package com.iluwatar.masterworker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Random; /** @@ -29,7 +32,8 @@ import java.util.Random; */ public class ArrayUtilityMethods { - + + private static final Logger LOGGER = LoggerFactory.getLogger(ArrayUtilityMethods.class); /** * Method arraysSame compares 2 arrays @param a1 and @param a2 * and @return whether their values are equal (boolean). @@ -100,9 +104,9 @@ public class ArrayUtilityMethods { //prints out int[][] for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { - System.out.print(matrix[i][j] + " "); + LOGGER.info(matrix[i][j] + " "); } - System.out.println(""); + LOGGER.info(""); } } diff --git a/module/pom.xml b/module/pom.xml index 920efc01c..0a60960b5 100644 --- a/module/pom.xml +++ b/module/pom.xml @@ -37,9 +37,5 @@ junit-jupiter-engine test - - log4j - log4j - diff --git a/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java b/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java index 6ab358777..12eaae1d9 100644 --- a/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java +++ b/module/src/main/java/com/iluwatar/module/ConsoleLoggerModule.java @@ -22,9 +22,10 @@ */ package com.iluwatar.module; -import java.io.PrintStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -import org.apache.log4j.Logger; +import java.io.PrintStream; /** * The ConsoleLoggerModule is responsible for showing logs on System Console @@ -34,7 +35,7 @@ import org.apache.log4j.Logger; */ public final class ConsoleLoggerModule { - private static final Logger LOGGER = Logger.getLogger(ConsoleLoggerModule.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ConsoleLoggerModule.class); private static ConsoleLoggerModule singleton = null; diff --git a/module/src/main/java/com/iluwatar/module/FileLoggerModule.java b/module/src/main/java/com/iluwatar/module/FileLoggerModule.java index 1ec85ea47..65f954b6c 100644 --- a/module/src/main/java/com/iluwatar/module/FileLoggerModule.java +++ b/module/src/main/java/com/iluwatar/module/FileLoggerModule.java @@ -22,12 +22,13 @@ */ package com.iluwatar.module; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; -import org.apache.log4j.Logger; - /** * The FileLoggerModule is responsible for showing logs on File System *

@@ -36,7 +37,7 @@ import org.apache.log4j.Logger; */ public final class FileLoggerModule { - private static final Logger LOGGER = Logger.getLogger(FileLoggerModule.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FileLoggerModule.class); private static FileLoggerModule singleton = null; diff --git a/module/src/main/resources/log4j.xml b/module/src/main/resources/log4j.xml deleted file mode 100644 index 5c7e49d51..000000000 --- a/module/src/main/resources/log4j.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java index 5f7616f02..30f0baae5 100644 --- a/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java +++ b/module/src/test/java/com/iluwatar/module/FileLoggerModuleTest.java @@ -22,8 +22,9 @@ */ package com.iluwatar.module; -import org.apache.log4j.Logger; import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.BufferedReader; import java.io.FileNotFoundException; @@ -45,7 +46,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; */ public final class FileLoggerModuleTest { - private static final Logger LOGGER = Logger.getLogger(FileLoggerModuleTest.class); + private static final Logger LOGGER = LoggerFactory.getLogger(FileLoggerModuleTest.class); private static final String OUTPUT_FILE = "output.txt"; private static final String ERROR_FILE = "error.txt"; diff --git a/naked-objects/dom/exclude-pmd.properties b/naked-objects/dom/exclude-pmd.properties deleted file mode 100644 index e281170f7..000000000 --- a/naked-objects/dom/exclude-pmd.properties +++ /dev/null @@ -1,24 +0,0 @@ -# -# The MIT License -# Copyright © 2014-2019 Ilkka Seppälä -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -domainapp.dom.modules.simple.QSimpleObject=UnusedFormalParameter \ No newline at end of file diff --git a/naked-objects/dom/pom.xml b/naked-objects/dom/pom.xml index b8a04a53b..2709edda0 100644 --- a/naked-objects/dom/pom.xml +++ b/naked-objects/dom/pom.xml @@ -143,7 +143,6 @@ ${datanucleus-maven-plugin.version} false - ${basedir}/log4j.properties true ${basedir}/datanucleus.properties diff --git a/naked-objects/integtests/src/test/java/domainapp/integtests/bootstrap/SimpleAppSystemInitializer.java b/naked-objects/integtests/src/test/java/domainapp/integtests/bootstrap/SimpleAppSystemInitializer.java index d5f0cd552..930a805d5 100644 --- a/naked-objects/integtests/src/test/java/domainapp/integtests/bootstrap/SimpleAppSystemInitializer.java +++ b/naked-objects/integtests/src/test/java/domainapp/integtests/bootstrap/SimpleAppSystemInitializer.java @@ -49,7 +49,6 @@ public final class SimpleAppSystemInitializer { private static class SimpleAppSystemBuilder extends IsisSystemForTest.Builder { public SimpleAppSystemBuilder() { - withLoggingAt(org.apache.log4j.Level.INFO); with(testConfiguration()); with(new DataNucleusPersistenceMechanismInstaller()); diff --git a/naked-objects/integtests/src/test/java/domainapp/integtests/specglue/BootstrappingGlue.java b/naked-objects/integtests/src/test/java/domainapp/integtests/specglue/BootstrappingGlue.java index b53e88af0..4b22615ec 100644 --- a/naked-objects/integtests/src/test/java/domainapp/integtests/specglue/BootstrappingGlue.java +++ b/naked-objects/integtests/src/test/java/domainapp/integtests/specglue/BootstrappingGlue.java @@ -36,7 +36,6 @@ public class BootstrappingGlue extends CukeGlueAbstract { @Before(value = {"@integration"}, order = 100) public void beforeScenarioIntegrationScope() { - org.apache.log4j.PropertyConfigurator.configure("logging.properties"); SimpleAppSystemInitializer.initIsft(); before(ScenarioExecutionScope.INTEGRATION); diff --git a/naked-objects/integtests/src/test/java/domainapp/integtests/tests/SimpleAppIntegTest.java b/naked-objects/integtests/src/test/java/domainapp/integtests/tests/SimpleAppIntegTest.java index 0db09fceb..0c1971425 100644 --- a/naked-objects/integtests/src/test/java/domainapp/integtests/tests/SimpleAppIntegTest.java +++ b/naked-objects/integtests/src/test/java/domainapp/integtests/tests/SimpleAppIntegTest.java @@ -36,7 +36,6 @@ public abstract class SimpleAppIntegTest extends IntegrationTestAbstract { @BeforeClass public static void initClass() { - org.apache.log4j.PropertyConfigurator.configure("logging.properties"); SimpleAppSystemInitializer.initIsft(); // instantiating will install onto ThreadLocal diff --git a/naked-objects/webapp/pom.xml b/naked-objects/webapp/pom.xml index e26c5f561..e0697b855 100644 --- a/naked-objects/webapp/pom.xml +++ b/naked-objects/webapp/pom.xml @@ -216,26 +216,6 @@ hsqldb - - - - - - - org.lazyluke - log4jdbc-remix - - - org.slf4j - slf4j-api - - - - - junit junit diff --git a/naked-objects/webapp/src/main/java/domainapp/webapp/SimpleApplication.java b/naked-objects/webapp/src/main/java/domainapp/webapp/SimpleApplication.java index cf15632fa..875212963 100644 --- a/naked-objects/webapp/src/main/java/domainapp/webapp/SimpleApplication.java +++ b/naked-objects/webapp/src/main/java/domainapp/webapp/SimpleApplication.java @@ -50,6 +50,8 @@ import de.agilecoders.wicket.core.Bootstrap; import de.agilecoders.wicket.core.settings.IBootstrapSettings; import de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchTheme; import de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -72,6 +74,7 @@ import de.agilecoders.wicket.themes.markup.html.bootswatch.BootswatchThemeProvid */ public class SimpleApplication extends IsisWicketApplication { + private static final Logger LOGGER = LoggerFactory.getLogger(SimpleApplication.class); private static final long serialVersionUID = 1L; /** @@ -124,7 +127,7 @@ public class SimpleApplication extends IsisWicketApplication { servletRequest.getSession().invalidate(); } } catch (Exception e) { - System.out.println(e); + LOGGER.error(e.getMessage()); } return super.newWebRequest(servletRequest, filterPath); } diff --git a/pipeline/src/main/java/com.iluwatar.pipeline/ConvertToCharArrayHandler.java b/pipeline/src/main/java/com.iluwatar.pipeline/ConvertToCharArrayHandler.java index 3e8df8eef..6a418fef4 100644 --- a/pipeline/src/main/java/com.iluwatar.pipeline/ConvertToCharArrayHandler.java +++ b/pipeline/src/main/java/com.iluwatar.pipeline/ConvertToCharArrayHandler.java @@ -32,12 +32,12 @@ import java.util.Arrays; */ class ConvertToCharArrayHandler implements Handler { - private final Logger logger = LoggerFactory.getLogger(ConvertToCharArrayHandler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ConvertToCharArrayHandler.class); @Override public char[] process(String input) { char[] characters = input.toCharArray(); - logger.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", + LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", ConvertToCharArrayHandler.class, input, String.class, Arrays.toString(characters), Character[].class)); return characters; diff --git a/pipeline/src/main/java/com.iluwatar.pipeline/RemoveAlphabetsHandler.java b/pipeline/src/main/java/com.iluwatar.pipeline/RemoveAlphabetsHandler.java index 76219249d..342ed86c2 100644 --- a/pipeline/src/main/java/com.iluwatar.pipeline/RemoveAlphabetsHandler.java +++ b/pipeline/src/main/java/com.iluwatar.pipeline/RemoveAlphabetsHandler.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; */ class RemoveAlphabetsHandler implements Handler { - private final Logger logger = LoggerFactory.getLogger(RemoveAlphabetsHandler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RemoveAlphabetsHandler.class); @Override public String process(String input) { @@ -46,7 +46,7 @@ class RemoveAlphabetsHandler implements Handler { } String inputWithoutAlphabetsStr = inputWithoutAlphabets.toString(); - logger.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", + LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", RemoveAlphabetsHandler.class, input, String.class, inputWithoutAlphabetsStr, String.class)); return inputWithoutAlphabetsStr; diff --git a/pipeline/src/main/java/com.iluwatar.pipeline/RemoveDigitsHandler.java b/pipeline/src/main/java/com.iluwatar.pipeline/RemoveDigitsHandler.java index d1785c340..a5320a0a5 100644 --- a/pipeline/src/main/java/com.iluwatar.pipeline/RemoveDigitsHandler.java +++ b/pipeline/src/main/java/com.iluwatar.pipeline/RemoveDigitsHandler.java @@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory; */ class RemoveDigitsHandler implements Handler { - private final Logger logger = LoggerFactory.getLogger(RemoveDigitsHandler.class); + private static final Logger LOGGER = LoggerFactory.getLogger(RemoveDigitsHandler.class); @Override public String process(String input) { @@ -46,7 +46,7 @@ class RemoveDigitsHandler implements Handler { } String inputWithoutDigitsStr = inputWithoutDigits.toString(); - logger.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", + LOGGER.info(String.format("Current handler: %s, input is %s of type %s, output is %s, of type %s", RemoveDigitsHandler.class, input, String.class, inputWithoutDigitsStr, String.class)); return inputWithoutDigitsStr; diff --git a/pom.xml b/pom.xml index d6cd3a6e6..50e7c7de5 100644 --- a/pom.xml +++ b/pom.xml @@ -56,10 +56,8 @@ 1.2.3 1.1.0 1.11.289 - 1.0.0 2.0.1 2.8.5 - 1.2.17 2.3.1 2.3.2 1.3.2 @@ -304,11 +302,6 @@ mongo-java-driver ${mongo-java-driver.version} - - log4j - log4j - ${log4j.version} - javax.xml.bind jaxb-api diff --git a/serverless/pom.xml b/serverless/pom.xml index 9e142cb3a..292df78c5 100644 --- a/serverless/pom.xml +++ b/serverless/pom.xml @@ -60,11 +60,6 @@ aws-lambda-java-events ${aws-lambda-java-events.version} - - com.amazonaws - aws-lambda-java-log4j - ${aws-lambda-log4j.version} - com.fasterxml.jackson.core jackson-core diff --git a/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java b/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java index 0dac4c614..14f2b25a5 100644 --- a/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java +++ b/serverless/src/main/java/com/iluwatar/serverless/baas/api/FindPersonApiHandler.java @@ -27,7 +27,10 @@ import com.amazonaws.services.lambda.runtime.RequestHandler; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.iluwatar.serverless.baas.model.Person; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; /** * find person from persons collection @@ -36,13 +39,15 @@ import org.apache.log4j.Logger; public class FindPersonApiHandler extends AbstractDynamoDbHandler implements RequestHandler { - private static final Logger LOG = Logger.getLogger(FindPersonApiHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(FindPersonApiHandler.class); private static final Integer SUCCESS_STATUS_CODE = 200; @Override public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent apiGatewayProxyRequestEvent, Context context) { - LOG.info(apiGatewayProxyRequestEvent.getPathParameters()); + Map pathParameters = apiGatewayProxyRequestEvent.getPathParameters(); + pathParameters.keySet().stream().map(key -> key + "=" + pathParameters.get(key)).forEach(LOG::info); + Person person = this.getDynamoDbMapper().load(Person.class, apiGatewayProxyRequestEvent .getPathParameters().get("id")); diff --git a/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java b/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java index d77687d23..8ef4b839e 100644 --- a/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java +++ b/serverless/src/main/java/com/iluwatar/serverless/baas/api/SavePersonApiHandler.java @@ -27,7 +27,8 @@ import com.amazonaws.services.lambda.runtime.RequestHandler; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent; import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent; import com.iluwatar.serverless.baas.model.Person; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.IOException; @@ -38,7 +39,7 @@ import java.io.IOException; public class SavePersonApiHandler extends AbstractDynamoDbHandler implements RequestHandler { - private static final Logger LOG = Logger.getLogger(SavePersonApiHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(SavePersonApiHandler.class); private static final Integer CREATED_STATUS_CODE = 201; private static final Integer BAD_REQUEST_STATUS_CODE = 400; diff --git a/serverless/src/main/java/com/iluwatar/serverless/faas/api/LambdaInfoApiHandler.java b/serverless/src/main/java/com/iluwatar/serverless/faas/api/LambdaInfoApiHandler.java index 1157c962c..174e409c3 100644 --- a/serverless/src/main/java/com/iluwatar/serverless/faas/api/LambdaInfoApiHandler.java +++ b/serverless/src/main/java/com/iluwatar/serverless/faas/api/LambdaInfoApiHandler.java @@ -27,8 +27,8 @@ import com.iluwatar.serverless.faas.ApiGatewayResponse; import com.amazonaws.services.lambda.runtime.Context; import com.amazonaws.services.lambda.runtime.RequestHandler; import com.iluwatar.serverless.faas.LambdaInfo; -import org.apache.log4j.BasicConfigurator; -import org.apache.log4j.Logger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.HashMap; import java.util.Map; @@ -39,13 +39,12 @@ import java.util.Map; */ public class LambdaInfoApiHandler implements RequestHandler, ApiGatewayResponse> { - private static final Logger LOG = Logger.getLogger(LambdaInfoApiHandler.class); + private static final Logger LOG = LoggerFactory.getLogger(LambdaInfoApiHandler.class); private static final Integer SUCCESS_STATUS_CODE = 200; @Override public ApiGatewayResponse handleRequest(Map input, Context context) { - BasicConfigurator.configure(); LOG.info("received: " + input); return new ApiGatewayResponse diff --git a/serverless/src/main/resources/log4j.properties b/serverless/src/main/resources/log4j.properties deleted file mode 100644 index 2c666e286..000000000 --- a/serverless/src/main/resources/log4j.properties +++ /dev/null @@ -1,29 +0,0 @@ -# -# The MIT License -# Copyright © 2014-2019 Ilkka Seppälä -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -log = . -log4j.rootLogger = DEBUG, LAMBDA - -log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender -log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout -log4j.appender.LAMBDA.layout.conversionPattern=%d{yyyy-MM-dd HH:mm:ss} <%X{AWSRequestId}> %-5p %c:%L - %m%n diff --git a/spatial-partition/src/main/java/com/iluwatar/spatialpartition/App.java b/spatial-partition/src/main/java/com/iluwatar/spatialpartition/App.java index 179f11d04..f6a07de62 100644 --- a/spatial-partition/src/main/java/com/iluwatar/spatialpartition/App.java +++ b/spatial-partition/src/main/java/com/iluwatar/spatialpartition/App.java @@ -22,6 +22,9 @@ */ package com.iluwatar.spatialpartition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Enumeration; import java.util.Hashtable; @@ -52,6 +55,7 @@ import java.util.Random; */ public class App { + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); static void noSpatialPartition(int height, int width, int numOfMovements, Hashtable bubbles) { @@ -73,7 +77,7 @@ public class App { } for (Integer key : bubbles.keySet()) { //bubbles not popped - System.out.println("Bubble " + key + " not popped"); + LOGGER.info("Bubble " + key + " not popped"); } } @@ -101,7 +105,7 @@ public class App { } for (Integer key : bubbles.keySet()) { //bubbles not popped - System.out.println("Bubble " + key + " not popped"); + LOGGER.info("Bubble " + key + " not popped"); } } @@ -119,7 +123,7 @@ public class App { Bubble b = new Bubble(rand.nextInt(300), rand.nextInt(300), i, rand.nextInt(2) + 1); bubbles1.put(i, b); bubbles2.put(i, b); - System.out.println("Bubble " + i + " with radius " + b.radius + " added at (" + b.x + "," + b.y + ")"); + LOGGER.info("Bubble " + i + " with radius " + b.radius + " added at (" + b.x + "," + b.y + ")"); } long start1 = System.currentTimeMillis(); @@ -128,8 +132,8 @@ public class App { long start2 = System.currentTimeMillis(); App.withSpatialPartition(300,300,20,bubbles2); long end2 = System.currentTimeMillis(); - System.out.println("Without spatial partition takes " + (end1 - start1) + "ms"); - System.out.println("With spatial partition takes " + (end2 - start2) + "ms"); + LOGGER.info("Without spatial partition takes " + (end1 - start1) + "ms"); + LOGGER.info("With spatial partition takes " + (end2 - start2) + "ms"); } } diff --git a/spatial-partition/src/main/java/com/iluwatar/spatialpartition/Bubble.java b/spatial-partition/src/main/java/com/iluwatar/spatialpartition/Bubble.java index 3e3d41837..01faa8371 100644 --- a/spatial-partition/src/main/java/com/iluwatar/spatialpartition/Bubble.java +++ b/spatial-partition/src/main/java/com/iluwatar/spatialpartition/Bubble.java @@ -22,6 +22,9 @@ */ package com.iluwatar.spatialpartition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.Hashtable; import java.util.Random; @@ -32,6 +35,7 @@ import java.util.Random; */ public class Bubble extends Point { + private static final Logger LOGGER = LoggerFactory.getLogger(Bubble.class); final int radius; @@ -54,7 +58,7 @@ public class Bubble extends Point { } void pop(Hashtable allBubbles) { - System.out.println("Bubble " + this.id + " popped at (" + this.x + "," + this.y + ")!"); + LOGGER.info("Bubble " + this.id + " popped at (" + this.x + "," + this.y + ")!"); allBubbles.remove(this.id); } diff --git a/tls/src/main/java/com/iluwatar/tls/App.java b/tls/src/main/java/com/iluwatar/tls/App.java index cd216ac75..33f8c3129 100644 --- a/tls/src/main/java/com/iluwatar/tls/App.java +++ b/tls/src/main/java/com/iluwatar/tls/App.java @@ -22,6 +22,9 @@ */ package com.iluwatar.tls; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.Calendar; import java.util.Date; import java.util.concurrent.ExecutorService; @@ -64,6 +67,8 @@ import java.util.concurrent.Future; * @author Thomas Bauer, 2017 */ public class App { + + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program entry point * @@ -99,11 +104,11 @@ public class App { // a correct run should deliver 20 times 15.12.2015 // and a correct run shouldn't deliver any exception - System.out.println("The List dateList contains " + counterDateValues + " date values"); - System.out.println("The List exceptionList contains " + counterExceptions + " exceptions"); + LOGGER.info("The List dateList contains " + counterDateValues + " date values"); + LOGGER.info("The List exceptionList contains " + counterExceptions + " exceptions"); } catch (Exception e) { - System.out.println("Abnormal end of program. Program throws exception: " + e); + LOGGER.info("Abnormal end of program. Program throws exception: " + e); } executor.shutdown(); } @@ -121,7 +126,7 @@ public class App { Calendar cal = Calendar.getInstance(); cal.setTime(dt); // Formatted output of the date value: DD.MM.YYYY - System.out.println( + LOGGER.info( cal.get(Calendar.DAY_OF_MONTH) + "." + cal.get(Calendar.MONTH) + "." + +cal.get(Calendar.YEAR)); } return counter; @@ -138,7 +143,7 @@ public class App { int counter = 0; for (String ex : res.getExceptionList()) { counter++; - System.out.println(ex); + LOGGER.info(ex); } return counter; } diff --git a/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java b/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java index 8018e7996..a047828ce 100644 --- a/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java +++ b/tls/src/main/java/com/iluwatar/tls/DateFormatCallable.java @@ -22,6 +22,9 @@ */ package com.iluwatar.tls; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.concurrent.Callable; @@ -40,6 +43,8 @@ import java.util.concurrent.Callable; * @author Thomas Bauer, 2017 */ public class DateFormatCallable implements Callable { + + private static final Logger LOGGER = LoggerFactory.getLogger(DateFormatCallable.class); // class variables (members) private ThreadLocal df; //TLTL // private DateFormat df; //NTLNTL @@ -72,7 +77,7 @@ public class DateFormatCallable implements Callable { */ @Override public Result call() { - System.out.println(Thread.currentThread() + " started executing..."); + LOGGER.info(Thread.currentThread() + " started executing..."); Result result = new Result(); // Convert date value to date 5 times @@ -90,7 +95,7 @@ public class DateFormatCallable implements Callable { } - System.out.println(Thread.currentThread() + " finished processing part of the thread"); + LOGGER.info(Thread.currentThread() + " finished processing part of the thread"); return result; } diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java index 93e7a4ea8..2e6db9dd6 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/App.java @@ -25,6 +25,8 @@ package com.iluwatar.typeobject; import java.io.FileNotFoundException; import java.io.IOException; import org.json.simple.parser.ParseException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /**

Type object pattern is the pattern we use when the OOP concept of creating a base class and * inheriting from it just doesn't work for the case in hand. This happens when we either don't know @@ -45,6 +47,7 @@ import org.json.simple.parser.ParseException; public class App { + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); /** * Program entry point. * @param args command line args @@ -62,9 +65,9 @@ public class App { CellPool pool = new CellPool(numOfRows * numOfRows + 5); CandyGame cg = new CandyGame(numOfRows, pool); if (round > 1) { - System.out.println("Refreshing.."); + LOGGER.info("Refreshing.."); } else { - System.out.println("Starting game.."); + LOGGER.info("Starting game.."); } cg.printGameStatus(); end = System.currentTimeMillis(); @@ -72,13 +75,13 @@ public class App { pointsWon += cg.totalPoints; end = System.currentTimeMillis(); } - System.out.println("Game Over"); + LOGGER.info("Game Over"); if (pointsWon >= toWin) { - System.out.println(pointsWon); - System.out.println("You win!!"); + LOGGER.info("" + pointsWon); + LOGGER.info("You win!!"); } else { - System.out.println(pointsWon); - System.out.println("Sorry, you lose!"); + LOGGER.info("" + pointsWon); + LOGGER.info("Sorry, you lose!"); } } } diff --git a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java index 200a96f8b..516b4cf76 100644 --- a/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java +++ b/typeobjectpattern/src/main/java/com/iluwatar/typeobject/CandyGame.java @@ -24,6 +24,8 @@ package com.iluwatar.typeobject; import java.util.ArrayList; import com.iluwatar.typeobject.Candy.Type; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * The CandyGame class contains the rules for the continuation of the game and has @@ -31,6 +33,9 @@ import com.iluwatar.typeobject.Candy.Type; */ public class CandyGame { + + private static final Logger LOGGER = LoggerFactory.getLogger(CandyGame.class); + Cell[][] cells; CellPool pool; int totalPoints; @@ -57,21 +62,21 @@ public class CandyGame { } void printGameStatus() { - System.out.println(""); + LOGGER.info(""); for (int i = 0; i < cells.length; i++) { for (int j = 0; j < cells.length; j++) { String candyName = cells[i][j].candy.name; if (candyName.length() < 20) { int totalSpaces = 20 - candyName.length(); - System.out.print(numOfSpaces(totalSpaces / 2) + cells[i][j].candy.name + LOGGER.info(numOfSpaces(totalSpaces / 2) + cells[i][j].candy.name + numOfSpaces(totalSpaces - totalSpaces / 2) + "|"); } else { - System.out.print(candyName + "|"); + LOGGER.info(candyName + "|"); } } - System.out.println(""); + LOGGER.info(""); } - System.out.println(""); + LOGGER.info(""); } ArrayList adjacentCells(int yIndex, int xIndex) { @@ -121,7 +126,7 @@ public class CandyGame { } void handleChange(int points) { - System.out.println("+" + points + " points!"); + LOGGER.info("+" + points + " points!"); this.totalPoints += points; printGameStatus(); }