-
Notifications
You must be signed in to change notification settings - Fork 1k
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
first_try #1069
base: master
Are you sure you want to change the base?
first_try #1069
Changes from all 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/* | ||
*.iml | ||
target/* | ||
src/main/resources/log4j2.xml | ||
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
pattern 2025-01-06 00:34:46,015 INFO mate.academy.service.AuthenticationServiceImpl Method login was called : bob | ||
pattern 2025-01-06 00:34:46,023 INFO mate.academy.service.OrderServiceImpl Method completeOrder was called : 2 | ||
pattern 2025-01-06 00:34:46,026 INFO mate.academy.service.OrderServiceImpl Data was successfully fetched from DB | ||
pattern 2025-01-06 00:41:54,983 INFO mate.academy.service.AuthenticationServiceImpl Method login was called : bob | ||
pattern 2025-01-06 00:41:54,992 INFO mate.academy.service.OrderServiceImpl Method completeOrder was called : 2 | ||
pattern 2025-01-06 00:41:54,995 INFO mate.academy.service.OrderServiceImpl Data was successfully fetched from DB | ||
pattern 2025-01-06 00:50:08,730 INFO mate.academy.service.AuthenticationServiceImpl Method login was called : bob | ||
pattern 2025-01-06 00:50:08,752 INFO mate.academy.service.OrderServiceImpl Method completeOrder was called : 2 | ||
pattern 2025-01-06 00:50:08,756 INFO mate.academy.service.OrderServiceImpl Data was successfully fetched from DB |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,15 +6,19 @@ | |
import mate.academy.service.AuthenticationServiceImpl; | ||
import mate.academy.service.OrderService; | ||
import mate.academy.service.OrderServiceImpl; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.core.Logger; | ||
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. Consider using 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. It is recommended to use |
||
|
||
public class Main { | ||
private static final Logger logger = (Logger) LogManager.getLogger(Main.class); | ||
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. Casting |
||
|
||
public static void main(String[] args) { | ||
AuthenticationService authenticationService = new AuthenticationServiceImpl(); | ||
User user; | ||
try { | ||
user = authenticationService.login("bob", "1234"); | ||
} catch (AuthenticationException e) { | ||
e.printStackTrace(); | ||
logger.error("Failed login attempt for user: bob"); | ||
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 log message could be more informative by including details such as the reason for the failure or additional context. Consider adding more information to help with debugging and monitoring. |
||
return; | ||
} | ||
OrderService orderService = new OrderServiceImpl(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,16 @@ | |
|
||
import mate.academy.exception.AuthenticationException; | ||
import mate.academy.model.User; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class AuthenticationServiceImpl implements AuthenticationService { | ||
private static final Logger logger = | ||
LogManager.getLogger(AuthenticationServiceImpl.class); | ||
|
||
@Override | ||
public User login(String login, String password) throws AuthenticationException { | ||
//TODO: add corresponding log message about method login was called | ||
logger.info("Method login was called : {}", login); | ||
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 log message 'Method login was called : {}' is not very informative. According to the checklist, log messages should be more descriptive. Consider changing it to something like 'Method login was called. Params: login={}'. 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 log message 'Method login was called' is informative, but consider adding more context, such as the timestamp or additional user information, to make it more useful for debugging. |
||
User user = findByLogin(login); | ||
if (!user.getPassword().equals(password)) { | ||
throw new AuthenticationException("Username or password are incorrect"); | ||
|
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); | ||
|
||
@Override | ||
public Order completeOrder(Long userId) { | ||
// TODO: add log message about method completeOrder was called | ||
logger.info("Method completeOrder was called : {}", userId); | ||
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 log message 'Method completeOrder was called : {}' is not very informative. According to the checklist, log messages should be more descriptive. Consider changing it to something like 'Method completeOrder was called. Params: userId={}'. 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 log message 'Method completeOrder was called' is informative, but consider adding more context, such as the timestamp or additional user information, to make it more useful for debugging. |
||
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 DB"); | ||
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 log message 'Data was successfully fetched from DB' is informative, but since this is a dummy implementation, consider clarifying in the log that this is simulated data for testing purposes. |
||
return products; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Configuration status="WARN"> | ||
<Appenders> | ||
<Console name="Console" target="SYSTEM_OUT"> | ||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/> | ||
</Console> | ||
<File name="File" fileName="logs/app.log"> | ||
<PatternLayout> | ||
<Pattern>pattern %d %p %c %m%n</Pattern> | ||
</PatternLayout> | ||
</File> | ||
</Appenders> | ||
<Loggers> | ||
<Logger name="mate.academy" level="info" additivity="false"> | ||
<AppenderRef ref="File"/> | ||
<AppenderRef ref="Console"/> | ||
</Logger> | ||
<Root level="error"> | ||
<AppenderRef ref="Console"/> | ||
<AppenderRef ref="File"/> | ||
</Root> | ||
</Loggers> | ||
</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 line
src/main/resources/log4j2.xml
is set to be ignored. If this file contains sensitive information or is environment-specific, it's appropriate to ignore it. However, if it's a crucial part of the application's configuration that should be versioned, consider removing this line.