Skip to content

Commit

Permalink
Replace a global static logger with a local logger
Browse files Browse the repository at this point in the history
So we have now better traces of which exact class is called.
And now for production code as well.
  • Loading branch information
dadoonet committed Jan 17, 2025
1 parent 05429ed commit 71b59c3
Show file tree
Hide file tree
Showing 42 changed files with 52 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
Expand All @@ -35,7 +36,7 @@
*/
public class BootstrapChecks {

private static final Logger logger = LogManager.getLogger(BootstrapChecks.class);
private static final Logger logger = LogManager.getLogger();

public static void check() {
checkJvm();
Expand Down Expand Up @@ -64,7 +65,7 @@ static Percentage computePercentage(ByteSizeValue current, ByteSizeValue max) {
}

private static void checkUTF8() {
String encoding = System.getProperty("file.encoding");
String encoding = Charset.defaultCharset().displayName();
if (!encoding.equals(StandardCharsets.UTF_8.name())) {
logger.warn("[file.encoding] should be [{}] but is [{}]", StandardCharsets.UTF_8.name(), encoding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class FsCrawlerCli {

private static final long CLOSE_POLLING_WAIT_MS = 100;

private static final Logger logger = LogManager.getLogger(FsCrawlerCli.class);
private static final Logger logger = LogManager.getLogger();
private static FsCrawlerPluginsManager pluginsManager;

@SuppressWarnings("CanBeFinal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

public class FsCrawlerJobsUtil {

private static final Logger logger = LogManager.getLogger(FsCrawlerJobsUtil.class);
private static final Logger logger = LogManager.getLogger();

public static List<String> listExistingJobs(Path configDir) {
List<String> files = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class FsCrawlerImpl implements AutoCloseable {
@Deprecated
public static final String INDEX_TYPE_FOLDER = "folder";

private static final Logger logger = LogManager.getLogger(FsCrawlerImpl.class);
private static final Logger logger = LogManager.getLogger();

public static final int LOOP_INFINITE = -1;
public static final long MAX_SLEEP_RETRY_TIME = TimeValue.timeValueSeconds(30).millis();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
import static fr.pilato.elasticsearch.crawler.fs.framework.JsonUtil.asMap;

public abstract class FsParserAbstract extends FsParser {
private static final Logger logger = LogManager.getLogger(FsParserAbstract.class);
private static final Logger logger = LogManager.getLogger();

private static final String FSCRAWLER_IGNORE_FILENAME = ".fscrawlerignore";

Expand Down Expand Up @@ -224,7 +224,7 @@ private void updateFsJob(String jobName, LocalDateTime scanDate) throws Exceptio
// We need to round that latest date to the lower second and
// remove 2 seconds.
// See #82: https://github.com/dadoonet/fscrawler/issues/82
scanDate = scanDate.minus(2, ChronoUnit.SECONDS);
scanDate = scanDate.minusSeconds(2);
FsJob fsJob = FsJob.builder()
.setName(jobName)
.setLastrun(scanDate)
Expand Down Expand Up @@ -523,7 +523,7 @@ private String read(InputStream input) throws IOException {
* @param id id of the folder
* @param folder path object
*/
private void indexDirectory(String id, Folder folder) throws IOException {
private void indexDirectory(String id, Folder folder) {
if (!closed) {
managementService.storeVisitedDirectory(fsSettings.getElasticsearch().getIndexFolder(), id, folder);
} else {
Expand Down Expand Up @@ -575,7 +575,7 @@ private void removeEsDirectoryRecursively(final String path) throws Exception {
/**
* Remove a document with the document service
*/
private void esDelete(FsCrawlerDocumentService service, String index, String id) throws IOException {
private void esDelete(FsCrawlerDocumentService service, String index, String id) {
logger.debug("Deleting {}/{}", index, id);
if (!closed) {
service.delete(index, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.logging.log4j.Logger;

public class FsParserNoop extends FsParser {
private static final Logger logger = LogManager.getLogger(FsParserNoop.class);
private static final Logger logger = LogManager.getLogger();
private final FsSettings fsSettings;

public FsParserNoop(FsSettings fsSettings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

public class FsCrawlerDocumentServiceElasticsearchImpl implements FsCrawlerDocumentService {

private static final Logger logger = LogManager.getLogger(FsCrawlerDocumentServiceElasticsearchImpl.class);
private static final Logger logger = LogManager.getLogger();

private final IElasticsearchClient client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

public class FsCrawlerManagementServiceElasticsearchImpl implements FsCrawlerManagementService {

private static final Logger logger = LogManager.getLogger(FsCrawlerManagementServiceElasticsearchImpl.class);
private static final Logger logger = LogManager.getLogger();

// TODO Optimize it. We can probably use a search for a big array of filenames instead of
// searching fo 10000 files (which is somehow limited).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand All @@ -45,7 +44,7 @@
import static fr.pilato.elasticsearch.crawler.fs.framework.FsCrawlerUtil.getOwnerName;

public class FileAbstractorFile extends FileAbstractor<File> {
private final Logger logger = LogManager.getLogger(FileAbstractorFile.class);
private static final Logger logger = LogManager.getLogger();

public FileAbstractorFile(FsSettings fsSettings) {
super(fsSettings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.logging.log4j.Logger;

public class FTPUtils {
private static final Logger logger = LogManager.getLogger(FTPUtils.class);
private static final Logger logger = LogManager.getLogger();

/**
* Determines FTPFile permissions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
import java.util.stream.Collectors;

public class FileAbstractorFTP extends FileAbstractor<FTPFile> {
private final Logger logger = LogManager.getLogger(FileAbstractorFTP.class);
private static final Logger logger = LogManager.getLogger();

private FTPClient ftp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import java.util.stream.StreamSupport;

public class FileAbstractorSSH extends FileAbstractor<SftpClient.DirEntry> {
private final Logger logger = LogManager.getLogger(FileAbstractorSSH.class);
private static final Logger logger = LogManager.getLogger();

private final FsCrawlerSshClient fsCrawlerSshClient;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
import java.security.KeyPair;

public class FsCrawlerSshClient implements AutoCloseable {
private final Logger logger = LogManager.getLogger(FsCrawlerSshClient.class);
private static final Logger logger = LogManager.getLogger();

private final String host;
private final int port;
private final String username;
private final String password;
private final String pemPath;

private ClientSession session;
private SshClient sshClient;
private SftpClient sftpClient;

Expand All @@ -53,8 +52,7 @@ public FsCrawlerSshClient(String username, String password, String pemPath, Stri

public void open() throws Exception {
sshClient = createSshClient();
session = openSshSession(sshClient, username, password, pemPath, host, port);
sftpClient = createSftpClient(session);
sftpClient = createSftpClient(openSshSession(sshClient, username, password, pemPath, host, port));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
*/
public class ElasticsearchClient implements IElasticsearchClient {

private static final Logger logger = LogManager.getLogger(ElasticsearchClient.class);
private static final Logger logger = LogManager.getLogger();
@Deprecated
private final Path config;
private final FsSettings settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import static fr.pilato.elasticsearch.crawler.fs.client.IElasticsearchClient.INDEX_TYPE_DOC;

public class ElasticsearchEngine implements Engine<ElasticsearchOperation, ElasticsearchBulkRequest, ElasticsearchBulkResponse> {
private static final Logger logger = LogManager.getLogger(ElasticsearchEngine.class);
private static final Logger logger = LogManager.getLogger();
private final IElasticsearchClient elasticsearchClient;

public ElasticsearchEngine(IElasticsearchClient elasticsearchClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class FsCrawlerUtil {
public static final String INDEX_SETTINGS_FILE = "_settings";
public static final String INDEX_SETTINGS_FOLDER_FILE = "_settings_folder";

private static final Logger logger = LogManager.getLogger(FsCrawlerUtil.class);
private static final Logger logger = LogManager.getLogger();

/**
* Reads a mapping from config/_default/version/type.json file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class MetaFileHandler {

private static final Logger logger = LogManager.getLogger(MetaFileHandler.class);
private static final Logger logger = LogManager.getLogger();
public final static Path DEFAULT_ROOT = Paths.get(System.getProperty("user.home"), ".fscrawler");

private final Path root;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import java.lang.reflect.Method;

public class OsUtil {
private static final Logger logger = LogManager.getLogger(OsUtil.class);
private static final Logger logger = LogManager.getLogger();

private static final OperatingSystemMXBean osMxBean = ManagementFactory.getOperatingSystemMXBean();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class FsCrawlerAdvancedBulkProcessorListener<
REQ extends FsCrawlerBulkRequest<O>,
RES extends FsCrawlerBulkResponse<O>
> extends FsCrawlerSimpleBulkProcessorListener<O, REQ, RES> {
private static final Logger logger = LogManager.getLogger(FsCrawlerAdvancedBulkProcessorListener.class);
private static final Logger logger = LogManager.getLogger();

private final AtomicInteger successiveErrors = new AtomicInteger(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class FsCrawlerBulkProcessor<
Res extends FsCrawlerBulkResponse<O>
> implements Closeable {

private static final Logger logger = LogManager.getLogger(FsCrawlerBulkProcessor.class);
private static final Logger logger = LogManager.getLogger();

private final int bulkActions;
private final ByteSizeValue byteSize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import static fr.pilato.elasticsearch.crawler.fs.framework.JsonUtil.serialize;

public abstract class FsCrawlerBulkRequest<T extends FsCrawlerOperation<T>> {

private final Logger logger = LogManager.getLogger(FsCrawlerBulkRequest.class);
private static final Logger logger = LogManager.getLogger();

private final List<T> operations = new ArrayList<>();
private int totalByteSize = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@SuppressWarnings("CanBeFinal")
public abstract class FsCrawlerBulkResponse<O extends FsCrawlerOperation<O>> {

private static final Logger logger = LogManager.getLogger(FsCrawlerBulkResponse.class);
private static final Logger logger = LogManager.getLogger();

protected boolean errors;
protected List<BulkItemResponse<O>> items = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class FsCrawlerRetryBulkProcessorListener<
RES extends FsCrawlerBulkResponse<O>
> extends FsCrawlerAdvancedBulkProcessorListener<O, REQ, RES> {

private static final Logger logger = LogManager.getLogger(FsCrawlerRetryBulkProcessorListener.class);
private static final Logger logger = LogManager.getLogger();

private final String[] errorMessages;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class FsCrawlerSimpleBulkProcessorListener<
REQ extends FsCrawlerBulkRequest<O>,
RES extends FsCrawlerBulkResponse<O>
> implements FsCrawlerBulkProcessor.Listener<O, REQ, RES> {
private static final Logger logger = LogManager.getLogger(FsCrawlerSimpleBulkProcessorListener.class);
private static final Logger logger = LogManager.getLogger();

protected FsCrawlerBulkProcessor<O, REQ, RES> bulkProcessor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
import org.apache.logging.log4j.Logger;

class TestBulkListener extends FsCrawlerSimpleBulkProcessorListener<TestOperation, TestBulkRequest, TestBulkResponse> {
Logger logger = LogManager.getLogger(TestBulkListener.class);
private static final Logger logger = LogManager.getLogger();
TestBulkRequest latestRequest;
int nbSuccessfulExecutions = 0;

@Override
public void beforeBulk(long executionId, TestBulkRequest request) {
logger.trace("Execution [{}] starting", nbSuccessfulExecutions, request.numberOfActions());
logger.trace("Execution [{}] starting with [{}] actions", executionId, request.numberOfActions());
super.beforeBulk(executionId, request);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import static fr.pilato.elasticsearch.crawler.fs.framework.JsonUtil.parseJsonAsDocumentContext;

public abstract class FsCrawlerExtensionFsProviderAbstract implements FsCrawlerExtensionFsProvider {
private static final Logger logger = LogManager.getLogger(FsCrawlerExtensionFsProviderAbstract.class);
private static final Logger logger = LogManager.getLogger();
protected DocumentContext document;

protected abstract void parseSettings() throws PathNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*/
public abstract class FsCrawlerPlugin extends Plugin {

private final Logger logger = LogManager.getLogger(FsCrawlerPlugin.class);
private final Logger logger = LogManager.getLogger();

protected abstract String getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

public class FsCrawlerPluginsManager implements AutoCloseable {

private static final Logger logger = LogManager.getLogger(FsCrawlerPluginsManager.class);
private static final Logger logger = LogManager.getLogger();
private final PluginManager pluginManager;
private final HashMap<String, FsCrawlerExtensionFsProvider> fsProviders;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import java.net.URL;

public class FsHttpPlugin extends FsCrawlerPlugin {
private static final Logger logger = LogManager.getLogger(FsHttpPlugin.class);
private static final Logger logger = LogManager.getLogger();

@Override
protected String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.nio.file.Path;

public class FsLocalPlugin extends FsCrawlerPlugin {
private static final Logger logger = LogManager.getLogger(FsLocalPlugin.class);
private static final Logger logger = LogManager.getLogger();

@Override
protected String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import java.security.NoSuchAlgorithmException;

public class FsS3Plugin extends FsCrawlerPlugin {
private static final Logger logger = LogManager.getLogger(FsS3Plugin.class);
private static final Logger logger = LogManager.getLogger();

@Override
protected String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.MediaType;
import org.apache.commons.io.FilenameUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

Expand All @@ -51,6 +53,7 @@

@Path("/_document")
public class DocumentApi extends RestApi {
private static final Logger logger = LogManager.getLogger();

private final FsCrawlerDocumentService documentService;
private final FsSettings settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,5 @@

package fr.pilato.elasticsearch.crawler.fs.rest;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

class RestApi {

final Logger logger = LogManager.getLogger();

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,8 @@
import java.net.URI;

public class RestServer {

private static HttpServer httpServer = null;
private static final Logger logger = LogManager.getLogger();
private static HttpServer httpServer = null;

/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this application.
Expand Down
Loading

0 comments on commit 71b59c3

Please sign in to comment.