Skip to content

Commit

Permalink
feat: #98 In the VocabularyTopExporter hierarchy, return loggerName a…
Browse files Browse the repository at this point in the history
…nd use a single LoggerWrapper that will append this loggerName to the logs.
  • Loading branch information
dmitry-weirdo committed Nov 27, 2024
1 parent 0c2c981 commit ed1a241
Show file tree
Hide file tree
Showing 22 changed files with 122 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package ru.klavogonki.statistics.export;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;

@Log4j2
public class LoggerWrapper {

private final Logger internalLogger;
private final String loggerPrefix;
private final String loggerPrefixFull;

public LoggerWrapper(Logger internalLogger, String loggerPrefix) {
this.internalLogger = internalLogger;
this.loggerPrefix = loggerPrefix;
this.loggerPrefixFull = String.format("[%s]: ", loggerPrefix);

logger.info("LoggerWrapper initialized for loggerPrefix = \"{}\".", loggerPrefix);
}

private String formatMessage(String message) { // appends prefix
// todo: maybe String.format will work for message as well, but let's not risk
return loggerPrefixFull + message;
}

public void debug(String message, Object p0) {
internalLogger.debug(formatMessage(message), p0);
}

public void debug(String message, Object p0, Object p1) {
internalLogger.debug(formatMessage(message), p0, p1);
}

public void warn(String message, Object p0) {
internalLogger.warn(formatMessage(message), p0);
}

public void warn(String message, Object p0, Object p1) {
internalLogger.warn(formatMessage(message), p0, p1);
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package ru.klavogonki.statistics.export.vocabulary;

import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.Logger;
import org.mapstruct.factory.Mappers;
import ru.klavogonki.statistics.dto.PlayerVocabularyDto;
import ru.klavogonki.statistics.entity.PlayerVocabularyStatsEntity;
import ru.klavogonki.statistics.excel.ExcelExporter;
import ru.klavogonki.statistics.excel.VocabularyTopByBestSpeedExcelTemplate;
import ru.klavogonki.statistics.excel.VocabularyTopByHaulExcelTemplate;
import ru.klavogonki.statistics.excel.VocabularyTopByRacesCountExcelTemplate;
import ru.klavogonki.statistics.export.DataExporter;
import ru.klavogonki.statistics.export.ExportContext;
import ru.klavogonki.statistics.export.ExporterUtils;
import ru.klavogonki.statistics.export.LoggerWrapper;
import ru.klavogonki.statistics.freemarker.PageUrls;
import ru.klavogonki.statistics.freemarker.VocabularyTopByHaulLoginToPageTemplate;
import ru.klavogonki.statistics.freemarker.VocabularyTopByHaulTemplate;
import ru.klavogonki.statistics.freemarker.VocabularyTopByRacesCountLoginToPageTemplate;
import ru.klavogonki.statistics.freemarker.VocabularyTopByRacesCountTemplate;
import ru.klavogonki.statistics.freemarker.VocabularyTopBySpeedLoginToPageTemplate;
import ru.klavogonki.statistics.freemarker.VocabularyTopBySpeedTemplate;
import ru.klavogonki.statistics.dto.PlayerVocabularyDto;
import ru.klavogonki.statistics.entity.PlayerVocabularyStatsEntity;
import ru.klavogonki.statistics.mapper.PlayerVocabularyDtoMapper;
import ru.klavogonki.statistics.util.JacksonUtils;

Expand All @@ -37,7 +37,8 @@ public interface VocabularyTopExporter extends DataExporter {

int minRacesCount();

Logger logger();
String loggerName();
LoggerWrapper logger();

default int pageSize() {
return 100;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,7 +23,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,8 +23,8 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,8 +23,8 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,8 +23,8 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,7 +23,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,7 +23,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,7 +23,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,8 +23,8 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.non_standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.NonStandardDictionary;
Expand All @@ -24,8 +23,8 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.statistics.entity.PlayerEntity;
import ru.klavogonki.statistics.entity.PlayerVocabularyStatsEntity;
import ru.klavogonki.statistics.export.LoggerWrapper;
import ru.klavogonki.statistics.export.vocabulary.non_standard.NonStandardVocabularyTopExporter;
import ru.klavogonki.statistics.repository.PlayerVocabularyStatsRepository;
import ru.klavogonki.statistics.springboot.Profiles;
Expand All @@ -14,11 +16,27 @@
// todo: same implementation as StandardVocabularyTopExporterDefaultImpl
@Component
@Profile(Profiles.DATABASE)
@Log4j2
public abstract class NonStandardVocabularyTopExporterDefaultImpl implements NonStandardVocabularyTopExporter {

private LoggerWrapper loggerWrapper;

@Autowired
protected PlayerVocabularyStatsRepository repository;

@Override
public LoggerWrapper logger() {
return getLoggerWrapper();
}

private LoggerWrapper getLoggerWrapper() {
if (loggerWrapper == null) {
loggerWrapper = new LoggerWrapper(logger, loggerName());
}

return loggerWrapper;
}

@Override
public List<PlayerVocabularyStatsEntity> getPlayersByBestSpeed() {
List<PlayerVocabularyStatsEntity> players = repository.findByVocabularyCodeEqualsAndRacesCountGreaterThanEqualAndPlayerBlockedEqualsOrderByBestSpeedDesc(vocabularyCode(), minRacesCount(), PlayerEntity.NOT_BLOCKED);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ru.klavogonki.statistics.export.vocabulary.standard;

import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import ru.klavogonki.common.StandardDictionary;
Expand All @@ -23,7 +22,7 @@ public int minRacesCount() {
}

@Override
public Logger logger() {
return logger;
public String loggerName() {
return this.getClass().getSimpleName();
}
}
Loading

0 comments on commit ed1a241

Please sign in to comment.