Skip to content

Commit b3feed8

Browse files
committed
feat: VRNSKY-18. Drop dependency of the Apache Logging
1 parent 8e4f109 commit b3feed8

File tree

33 files changed

+149
-196
lines changed

33 files changed

+149
-196
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Java](https://img.shields.io/badge/Java-17-%23ED8B00.svg?logo=openjdk&logoColor=white)](#)
44
[![Spring Boot](https://img.shields.io/badge/Spring%20Boot-3.2.5-6DB33F?logo=springboot&logoColor=fff)](#)
55
[![JUnit5](https://img.shields.io/badge/Tested_with-JUnit_5-1?logo=junit5)](#)
6-
[![Linear](https://img.shields.io/badge/Task_tracker_we_prefer-Linear-5E6AD2?logo=linear&logoColor=fff)](#)
6+
[![Quality gate](https://sonarcloud.io/api/project_badges/quality_gate?project=vrnsky_java-a-to-z)](https://sonarcloud.io/summary/new_code?id=vrnsky_java-a-to-z)[![Linear](https://img.shields.io/badge/Task_tracker_we_prefer-Linear-5E6AD2?logo=linear&logoColor=fff)](#)
77

88
This repository contains solution of task from courses at the job4j.ru course.
99
In course use next technology :

chapter10/Mapping/src/main/java/controllers/Adverter.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
import org.apache.commons.fileupload.FileUploadException;
88
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
99
import org.apache.commons.fileupload.servlet.ServletFileUpload;
10-
import org.apache.log4j.Level;
11-
import org.apache.log4j.Logger;
1210
import repos.AdvertRepo;
1311
import repos.CarRepo;
1412
import javax.servlet.ServletContext;
@@ -23,6 +21,8 @@
2321
import java.util.List;
2422
import java.util.concurrent.ConcurrentHashMap;
2523
import java.util.concurrent.ConcurrentMap;
24+
import java.util.logging.Level;
25+
import java.util.logging.Logger;
2626

2727
/**
2828
* @author evrnsky(vrnsky at protonmail.ch)
@@ -37,7 +37,7 @@ public class Adverter extends HttpServlet {
3737
/**
3838
* Instance of logger.
3939
*/
40-
private static final Logger LOG = Logger.getLogger(Adverter.class);
40+
private static final Logger LOG = Logger.getLogger(Adverter.class.getSimpleName());
4141

4242
/**
4343
* Contains data which collected from the form.
@@ -77,7 +77,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws S
7777
fillMapFromParsedRequest((User) session.getAttribute("user"), items);
7878
FORM.clear();
7979
} catch (FileUploadException fue) {
80-
LOG.log(Level.ERROR, fue.getMessage(), fue);
80+
LOG.log(Level.SEVERE, fue.getMessage(), fue);
8181
}
8282

8383
}

chapter10/Mapping/src/main/java/controllers/Index.java

-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.databind.SerializationFeature;
55
import model.Advert;
6-
import org.apache.log4j.Logger;
76
import repos.AdvertRepo;
87
import javax.servlet.ServletException;
98
import javax.servlet.annotation.WebServlet;
@@ -22,12 +21,6 @@
2221
*/
2322
@WebServlet("/index")
2423
public class Index extends HttpServlet {
25-
26-
/**
27-
* Logger.
28-
*/
29-
private static final Logger LOG = Logger.getLogger(Index.class);
30-
3124
/**
3225
* Return all advert in json string.
3326
* @param req from client to server.

chapter10/Mapping/src/main/java/controllers/Producers.java

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import model.CarInfo;
5-
import org.apache.log4j.Logger;
65
import repos.CarRepo;
6+
77
import javax.servlet.ServletException;
88
import javax.servlet.annotation.WebServlet;
99
import javax.servlet.http.HttpServlet;
@@ -17,24 +17,19 @@
1717
* @author evrnsky <[email protected]>
1818
* @version 0.1
1919
* @since 30.03.2017
20-
*
20+
* <p>
2121
* This controllers push to the client producers of car.
2222
*/
2323

2424
@WebServlet("/producers")
2525
public class Producers extends HttpServlet {
26-
27-
/**
28-
* Instance of logger.
29-
*/
30-
private static final Logger LOG = Logger.getLogger(Producers.class);
31-
3226
/**
3327
* Flush to client part of app json string about car producers.
34-
* @param req from client to server.
28+
*
29+
* @param req from client to server.
3530
* @param resp from server to client.
3631
* @throws ServletException if request could not be handled.
37-
* @throws IOException if a/n error detected.
32+
* @throws IOException if a/n error detected.
3833
*/
3934
@Override
4035
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

chapter10/Mapping/src/main/java/repos/AdvertRepo.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import jakarta.persistence.criteria.Root;
77
import model.Advert;
88
import model.Car;
9-
import org.apache.log4j.Logger;
109
import org.hibernate.Session;
1110
import org.hibernate.query.Query;
11+
1212
import java.util.ArrayList;
1313
import java.util.List;
1414
import java.util.Map;
@@ -20,11 +20,6 @@
2020
*/
2121
public class AdvertRepo extends CommonRepo<Advert> {
2222

23-
/**
24-
* Logger.
25-
*/
26-
private static final Logger LOG = Logger.getLogger(AdvertRepo.class);
27-
2823
/**
2924
* It is singleton.
3025
*/

chapter10/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646
<groupId>org.slf4j</groupId>
4747
<artifactId>slf4j-api</artifactId>
4848
</dependency>
49-
<dependency>
50-
<groupId>org.slf4j</groupId>
51-
<artifactId>slf4j-log4j12</artifactId>
52-
</dependency>
5349
<dependency>
5450
<groupId>javax.xml.bind</groupId>
5551
<artifactId>jaxb-api</artifactId>

chapter7/Monitor/src/main/java/file/TextSearcher.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,24 @@
77
import java.util.ArrayList;
88
import java.util.List;
99
import java.util.concurrent.atomic.AtomicBoolean;
10-
import org.apache.log4j.Level;
11-
import org.apache.log4j.Logger;
10+
import java.util.logging.Logger;
1211

1312

1413
/**
1514
* @author evrnsky
1615
* @version 0.1
1716
* @since 17.11.2016
1817
* Implementation of searching text from file system.
19-
* It search in readable and not hidden files.
18+
* It searches in readable and not hidden files.
2019
* Also check that contains file path searching text.
2120
*/
21+
2222
public class TextSearcher extends Thread {
2323

2424
/**
2525
* Logger for this class.
2626
*/
27-
private static final Logger LOG = Logger.getLogger(TextSearcher.class);
27+
private static final Logger LOG = Logger.getLogger(TextSearcher.class.getSimpleName());
2828

2929
/**
3030
* Flag which signal about find text or not.
@@ -140,9 +140,9 @@ private boolean search(String disk) {
140140
*/
141141
private void processingFile(File file, String text) {
142142
this.founded = readFile(file.getAbsolutePath(), text);
143-
LOG.log(Level.INFO, String.format("SEARCH AT: %s", file.getAbsolutePath()));
143+
LOG.info(String.format("SEARCH AT: %s", file.getAbsolutePath()));
144144
if (this.founded) {
145-
LOG.log(Level.INFO, String.format("FOUND AT: %s", file.getAbsolutePath()));
145+
LOG.info(String.format("FOUND AT: %s", file.getAbsolutePath()));
146146
synchronized (this.resultFiles) {
147147
this.resultFiles.add(file.getAbsolutePath());
148148
}

chapter7/Wait-notify-notifyAll/src/main/java/pool/ThreadPool.java

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package pool;
22

3-
import org.apache.log4j.Level;
4-
import org.apache.log4j.Logger;
53

64
import java.util.LinkedList;
5+
import java.util.logging.Logger;
76

87

98
/**
@@ -18,7 +17,7 @@ public class ThreadPool {
1817
/**
1918
* Instance of logger.
2019
*/
21-
private static final Logger LOG = Logger.getLogger(ThreadPool.class);
20+
private static final Logger LOG = Logger.getLogger(ThreadPool.class.getSimpleName());
2221

2322
/**
2423
* Boundary for count of thread which may accept this queue.
@@ -70,13 +69,13 @@ public void run() {
7069
synchronized (queue) {
7170
while (queue.isEmpty()) {
7271
try {
73-
LOG.log(Level.INFO, "Pool at this moment is empty and wait task.");
72+
LOG.info("Pool at this moment is empty and wait task.");
7473
queue.wait();
7574
} catch (InterruptedException e) {
7675
e.printStackTrace();
7776
}
7877
}
79-
LOG.log(Level.INFO, "Pool going execute head of the list async task.");
78+
LOG.info("Pool going execute head of the list async task.");
8079
r = queue.removeFirst();
8180
}
8281

@@ -95,12 +94,7 @@ public void run() {
9594
*/
9695
public static void main(String[] args) {
9796
ThreadPool pool = new ThreadPool();
98-
Runnable timer = new Runnable() {
99-
@Override
100-
public void run() {
101-
System.out.println(System.currentTimeMillis());
102-
}
103-
};
97+
Runnable timer = () -> System.out.println(System.currentTimeMillis());
10498
pool.execute(timer);
10599
}
106100
}

chapter7/Wait-notify-notifyAll/src/main/java/queue/BlockingQueue.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package queue;
22

3-
import org.apache.log4j.Level;
4-
import org.apache.log4j.Logger;
53

64
import java.util.ArrayList;
5+
import java.util.logging.Logger;
76

87
/**
98
* @author evrnsky
109
* @version 0.1
1110
* @since 23.11.2016
1211
* @param <T> type of data which may contain this queue.
13-
* This is thread safe queue. It block access to the storage of objects.
12+
* This is thread safe queue. It blocks access to the storage of objects.
1413
* Thread safe provide by synchronize blocks on the inner lock.
1514
*/
1615
public class BlockingQueue<T> {
1716

1817
/**
1918
* Instance of logger.
2019
*/
21-
private static final Logger LOG = Logger.getLogger(BlockingQueue.class);
20+
private static final Logger LOG = Logger.getLogger(BlockingQueue.class.getSimpleName());
2221

2322
/**
2423
* Head of the queue.
@@ -61,11 +60,11 @@ public void add(T data) {
6160
if (this.tail == 0) {
6261
this.tail++;
6362
this.objects.add(data);
64-
LOG.log(Level.INFO, "Now all threads get signal about resource is free.");
63+
LOG.info("Now all threads get signal about resource is free.");
6564
lock.notifyAll();
6665
} else if (this.tail != this.objects.size()) {
6766
this.objects.add(data);
68-
LOG.log(Level.INFO, "Now all threads get signal about resource is free.");
67+
LOG.info("Now all threads get signal about resource is free.");
6968
this.lock.notifyAll();
7069
} else {
7170
throw new IllegalStateException("Queue is full.");
@@ -82,7 +81,7 @@ public T poll() {
8281
synchronized (lock) {
8382
while (this.isEmpty()) {
8483
try {
85-
LOG.log(Level.INFO, "Wait until producer put data to the queue.");
84+
LOG.info("Wait until producer put data to the queue.");
8685
lock.wait();
8786
} catch (InterruptedException e) {
8887
e.printStackTrace();

chapter7/Wait-notify-notifyAll/src/main/java/queue/ProducerCustomer.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package queue;
22

3-
import org.apache.log4j.Level;
4-
import org.apache.log4j.Logger;
5-
63
import java.util.concurrent.atomic.AtomicInteger;
4+
import java.util.logging.Logger;
75

86
/**
97
* @author evrnsky
@@ -16,7 +14,7 @@ public class ProducerCustomer {
1614
/**
1715
* Instance of logger, show usefully information about program execution.
1816
*/
19-
private static final Logger LOG = Logger.getLogger(ProducerCustomer.class);
17+
private static final Logger LOG = Logger.getLogger(ProducerCustomer.class.getSimpleName());
2018

2119
/**
2220
* Instance of blocking queue which provide a thread safe access to the elements.
@@ -32,7 +30,7 @@ public class ProducerCustomer {
3230
* Producer method which put data to the end of the queue.
3331
*/
3432
public void produce() {
35-
LOG.log(Level.INFO, String.format("%s %s", "Now push to the end of queue is", number.get()));
33+
LOG.info(String.format("%s %s", "Now push to the end of queue is", number.get()));
3634
queue.add(String.format("%s", number.get()));
3735
number.incrementAndGet();
3836
}
@@ -41,7 +39,7 @@ public void produce() {
4139
* Consume method which takes data from the head of the queue.
4240
*/
4341
public void consume() {
44-
LOG.log(Level.INFO, String.format("%s %s", "Received from producer: ", queue.poll()));
42+
LOG.info(String.format("%s %s", "Received from producer: ", queue.poll()));
4543
}
4644

4745
/**
@@ -71,6 +69,4 @@ public void run() {
7169
subscriber.start();
7270
publisher.start();
7371
}
74-
75-
7672
}

chapter7/pom.xml

-4
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@
4242
<groupId>org.slf4j</groupId>
4343
<artifactId>slf4j-api</artifactId>
4444
</dependency>
45-
<dependency>
46-
<groupId>org.slf4j</groupId>
47-
<artifactId>slf4j-log4j12</artifactId>
48-
</dependency>
4945
</dependencies>
5046

5147
</project>

chapter8/JDBC/start/src/main/java/ru/evrnsky/start/Settings.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package ru.evrnsky.start;
22

3-
import org.apache.log4j.Level;
4-
import org.apache.log4j.Logger;
53
import java.io.IOException;
64
import java.io.InputStream;
75
import java.util.Properties;
6+
import java.util.logging.Logger;
87

98
/**
109
* @author evrnsky
@@ -18,7 +17,7 @@ public class Settings {
1817
/**
1918
* Instance of logger.
2019
*/
21-
private static final Logger LOG = Logger.getLogger(Settings.class);
20+
private static final Logger LOG = Logger.getLogger(Settings.class.getSimpleName());
2221

2322
/**
2423
* Properties.
@@ -33,7 +32,7 @@ public void load(InputStream load) {
3332
try {
3433
this.properties.load(load);
3534
} catch (IOException ioe) {
36-
LOG.log(Level.WARN, ioe.getMessage(), ioe);
35+
LOG.info(ioe.getMessage());
3736
}
3837
}
3938

chapter8/Parser/pom.xml

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
<groupId>org.quartz-scheduler</groupId>
2626
<artifactId>quartz</artifactId>
2727
</dependency>
28+
<dependency>
29+
<groupId>ru.evrnsky.chapter3.consoleChat</groupId>
30+
<artifactId>consoleChat</artifactId>
31+
<version>1.0.0</version>
32+
<scope>compile</scope>
33+
</dependency>
2834
</dependencies>
2935
<build>
3036
<plugins>

0 commit comments

Comments
 (0)