GitHub user DennisYudin edited a discussion: [ERROR]   class file for 
org.apache.logging.log4j.Logger not found

Hi there i've got some troubles with log4j2 and I hope someone will help me.

Here's a thing.
I've got a small multi-module jakartaEE project and I'm getting Compilation 
failure which says:
>  error: cannot access Logger
> [ERROR]   class file for org.apache.logging.log4j.Logger not found

This happends when I try to compile one of my module.

The Idea is simple I've got a log4j2 wrapper in one module which looks like 
this:
```
public class Log4jHelper implements LogHelper {
        private static final String TR_EXT_ID_NAME = "[extTrId: %d] ";
        private static final String TR_ID_N_EXT_ID_NAME = "[trId: %d, extTrId: 
%d] ";
        private static final String TR_ID_NAME = "[trId: %d] ";

        private static final Map<Class<? extends Throwable>, Level> exceptions 
= new ConcurrentHashMap<>();

        private final Logger log;

        private Log4jHelper(Logger log) {
                this.log = log;
        }
        public static LogHelper getLogger(Class<?> clazz) {
                return new Log4jHelper(LogManager.getLogger(clazz));
        }
        public static LogHelper getLogger(Logger log) {
                return new Log4jHelper(log);
        }
        public static void registerException(Class<? extends Throwable> clazz, 
Level level) {
                exceptions.put(clazz, level);
        }
        @Override
        public void debug(Long trId, Long extTrId, String msg, Object... 
params) {
                log(Level.DEBUG, trId, extTrId, null, msg, params);
        }
   // and other methods
```

And in another module I try to use it 

I added module with logging as dependecy to another module where I wanna use it
```
 <dependency>
            <groupId>com.packt.cookbook.libraries</groupId>
            <artifactId>common</artifactId>
            <version>${project.version}</version>
        </dependency>
```
and after that Im trying to use it 

```
@Path("members")
@RequestScoped
public class MemberRESTService {

        private static final LogHelper log = 
Log4jHelper.getLogger(MemberRESTService.class);
        @Inject
        private Validator validator;
        @Inject
        private MemberRepository repository;
        @Inject
        private Registration registration;

        @PostConstruct
        public void init() {
                log.info("WEB module: logging is working...");
        } 
```
and when I run `mvn clean compile` command Im getting Compilation failure. 

When I add to the pom of my second module log4j-api dependency, problem is gone.
```
<dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <scope>provided</scope>
        </dependency>
```
But when I run `mvn dependency:analyze` I can see the message:
```
Unused declared dependencies found:
[WARNING]    org.apache.logging.log4j:log4j-api:jar:2.23.1:provided
```
I think is not OK.

[Project repo: ]https://github.com/DennisYudin/simple-ear-jakartaee10

I would appreciate for any help!





GitHub link: https://github.com/apache/logging-log4j2/discussions/4046

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]

Reply via email to