Skip to content
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/*
*.iml
logs/
target/*
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/mate/academy/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@
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.Logger;

public class Main {
public static void main(String[] args) {
Logger logger = LogManager.getLogger(Main.class);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1: "Configure the logger in this project. Add appenders for File and Console" — I don't see any Log4j2 configuration file (e.g., src/main/resources/log4j2.xml or log4j2.properties) in the project. Add a logger configuration that defines a Console appender and a File appender (writing to the ignored logs/ folder), and configure a root logger or package logger to use them so logs are written both to console and to a file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1: "the project does not contain a Log4j2 configuration file that defines both Console and File appenders [CHECKLIST ITEM #1]". Add a Log4j2 configuration (for example src/main/resources/log4j2.xml) that declares a Console appender and a File appender (e.g., logs/app.log) and configure the root logger or the mate.academy package logger to use both appenders so LogManager.getLogger(...) actually writes to console and the log file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a mistake, because i already have example src/main/resources/log4j2.xml

image

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the checklist: "Add a Log4j2 configuration file that declares both a Console appender and a File appender and configures the root logger or the mate.academy logger to use both appenders, so logging actually goes to the log file as required [CHECKLIST ITEM #1]." There's no src/main/resources/log4j2.xml (or other Log4j2 config) in the project, so LogManager.getLogger(...) calls won't write to a log file. Please add a configuration file (e.g. src/main/resources/log4j2.xml) that declares a Console and a File appender and binds them to the root or mate.academy logger (for example writing to logs/app.log), and ensure logs/ is in .gitignore.

AuthenticationService authenticationService = new AuthenticationServiceImpl();
User user;
try {
user = authenticationService.login("bob", "1234");
} catch (AuthenticationException e) {
e.printStackTrace();
logger.error("Authentication exception while logging in", e);
return;
}
OrderService orderService = new OrderServiceImpl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project is missing the required Log4j2 configuration. Specifically: "the project does not contain a Log4j2 configuration file that defines both Console and File appenders [CHECKLIST ITEM #1]". Add a configuration file (e.g. src/main/resources/log4j2.xml) that declares a Console appender and a File appender (writing to something like logs/app.log) and configure the root logger or the mate.academy package logger to use both appenders so logs are output to console and file.


@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: {}", login);
User user = findByLogin(login);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1: "Configure the logger in this project and add appenders for File and Console". I don't see a Log4j2 configuration (e.g., log4j2.xml or log4j2.properties) in the project. Add a logger configuration file (for example src/main/resources/log4j2.xml) that defines a Console appender and a File appender so logs are written to both console and a file.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the checklist item: "Configure the logger in this project. Add appenders for File and Console" — I cannot find a Log4j2 configuration file (for example src/main/resources/log4j2.xml) that declares a Console appender and a File appender and binds them to the root or mate.academy logger. Add such a config so LogManager.getLogger(...) actually writes to a log file (for example a File appender writing to logs/app.log).

if (!user.getPassword().equals(password)) {
throw new AuthenticationException("Username or password are incorrect");
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/mate/academy/service/OrderServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates checklist item #1: "Configure the logger in this project and add appenders for File and Console." I do not see any Log4j2 configuration file (for example, src/main/resources/log4j2.xml or log4j2.properties) in the project, so Console and File appenders are not defined. Add a configuration file that declares both a Console and a File appender (writing to a file inside the ignored logs/ folder) so the logger behavior matches the task requirement.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing Log4j2 configuration file. This violates the requirement: "A Log4j2 configuration file must be present that defines both a Console appender and a File appender and binds them to the root logger or the mate.academy logger, so that LogManager.getLogger(...) calls actually write to a log file [CHECKLIST ITEM #1]". Please add a config (for example, src/main/resources/log4j2.xml) declaring a Console appender and a File appender (e.g. writing to logs/app.log) and bind them to the root or mate.academy logger so logs are written to file.

// TODO: add log message about method completeOrder was called
logger.info("method completeOrder was called. User id: {} ", 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
Expand All @@ -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 from DB fetched successful. User id: {} ", userId);
return products;
}
}
23 changes: 23 additions & 0 deletions src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
<Appenders>
<Console name="LogToConsole" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<File name="LogToFile" fileName="logs/app.log">
<PatternLayout>
<Pattern>%d %p %c:%L %m%n</Pattern>
</PatternLayout>
</File>
</Appenders>
<Loggers>
<Logger name="mate.academy" level="info" additivity="false">
<AppenderRef ref="LogToFile"/>
<AppenderRef ref="LogToConsole"/>
</Logger>
<Root level="error">
<AppenderRef ref="LogToFile"/>
<AppenderRef ref="LogToConsole"/>
</Root>
</Loggers>
</Configuration>
Loading