-
Notifications
You must be signed in to change notification settings - Fork 1.1k
did all required tsks #1254
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
base: master
Are you sure you want to change the base?
did all required tsks #1254
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .idea/* | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
| *.iml | ||
| target/* | ||
| logs/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,15 +6,19 @@ | |
| import mate.academy.service.AuthenticationServiceImpl; | ||
| import mate.academy.service.OrderService; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing logger configuration file. According to checklist item #1, you must configure the logger with File and Console appenders. |
||
| import mate.academy.service.OrderServiceImpl; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| public class Main { | ||
| private static final Logger logger = LogManager.getLogger(Main.class); | ||
|
|
||
| public static void main(String[] args) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: log messages should use parameterized form instead of string concatenation. Change to: logger.debug("Method completeOrder was called. Params: userId={}", userId); |
||
| AuthenticationService authenticationService = new AuthenticationServiceImpl(); | ||
| User user; | ||
| try { | ||
| user = authenticationService.login("bob", "1234"); | ||
| } catch (AuthenticationException e) { | ||
| e.printStackTrace(); | ||
| logger.error("Помилка операції", e); | ||
| return; | ||
| } | ||
| OrderService orderService = new OrderServiceImpl(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,15 @@ | |
| import java.util.List; | ||
| import mate.academy.model.Order; | ||
| import mate.academy.model.Product; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
|
|
||
| public class OrderServiceImpl implements OrderService { | ||
| private static final Logger logger = LogManager.getLogger(OrderServiceImpl.class); | ||
|
Comment on lines
+7
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing |
||
|
|
||
| @Override | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This uses string concatenation. According to the checklist's good example, use parameterized logging: logger.info("Method login was called. Params: login={}", login); |
||
| public Order completeOrder(Long userId) { | ||
| // TODO: add log message about method completeOrder was called | ||
| logger.info("Method completeOrder was called. Params: userId={}", userId); | ||
| List<Product> products = getAllProductsFromShoppingCart(userId); | ||
| Order order = new Order(products, userId); | ||
| // NOTE: In production ready code this order identifier should be generated by DB | ||
|
|
@@ -24,7 +28,7 @@ private List<Product> getAllProductsFromShoppingCart(Long userId) { | |
| Product macBook = new Product("MacBook Air 2020", BigDecimal.valueOf(1399)); | ||
| Product xiaomi = new Product("Xiaomi 12", BigDecimal.valueOf(499)); | ||
| List<Product> products = List.of(iphone, macBook, xiaomi); | ||
| // TODO: add log message about successful fetched data from DB | ||
| logger.info("Data was successfully fetched from DataBase for userId={}", userId); | ||
| return products; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
| <log4j:configuration> | ||
|
|
||
| <appender name="console" class="org.apache.log4j.ConsoleAppender"> | ||
| <layout class="org.apache.log4j.PatternLayout"> | ||
| <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/> | ||
| </layout> | ||
| </appender> | ||
|
|
||
| <appender name="file" class="org.apache.log4j.RollingFileAppender"> | ||
| <param name="file" value="logs/app.log"/> | ||
| <param name="maxFileSize" value="10MB"/> | ||
| <param name="maxBackupIndex" value="5"/> | ||
| <layout class="org.apache.log4j.PatternLayout"> | ||
| <param name="ConversionPattern" value="%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n"/> | ||
| </layout> | ||
| </appender> | ||
|
|
||
| <root> | ||
| <level value="INFO"/> | ||
| <appender-ref ref="console"/> | ||
| <appender-ref ref="file"/> | ||
| </root> | ||
|
|
||
| </log4j:configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The log4j.xml configuration file in
src/main/resources/is missing. Checklist item #1 requires configuring the logger with File and Console appenders. You need to create this configuration file to enable logging functionality.