Skip to content

Commit

Permalink
modif objet logkbart ajout nb line + order by
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelQuetin committed Dec 19, 2023
1 parent 8724fae commit 5ce70d2
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/fr/abes/logskbart/dto/LigneLogDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
public class LigneLogDto {
private String level;
private String message;
private Integer nbLine;
}
1 change: 1 addition & 0 deletions src/main/java/fr/abes/logskbart/dto/LogKbartDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class LogKbartDto {
private String loggerFqcn;
private Integer threadId;
private Integer threadPriority;
private Integer nbLine;

@Getter @Setter
private static class InstantDto {
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/fr/abes/logskbart/entity/LogKbart.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class LogKbart implements Serializable {
@Column(name = "THREAD_PRIORITY")
private Integer threadPriority;

@Column(name = "NB_LINE")
private Integer nbLine;

@Override
public String toString() {
return "LogKbart{" +
Expand All @@ -62,6 +65,8 @@ public String toString() {
", level=" + level +
", message='" + message + '\'' +
", loggerFqcn='" + loggerFqcn + '\'' +
", nbLine='" + nbLine + '\'' +

'}';
}

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/fr/abes/logskbart/kafka/LogsListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord<String, Stri
LogKbart logKbart = logsMapper.map(dto, LogKbart.class);

String[] listMessage = message.key().split(";");
log.info(Arrays.toString(listMessage));
log.debug(Arrays.toString(listMessage));
// recuperation de l'heure a laquelle le message a ete envoye
Timestamp currentTimestamp = new Timestamp(message.timestamp());
logKbart.setTimestamp(new Date(currentTimestamp.getTime()));
logKbart.setPackageName(listMessage[0]);
String nbLineOrigine = (listMessage.length > 1) ? listMessage[1] : "";
logKbart.setNbLine(Integer.parseInt((nbLineOrigine.isEmpty() ? "-1" : nbLineOrigine) ));

logKbart.log();

Expand All @@ -73,7 +74,7 @@ public void listenInfoKbart2KafkaAndErrorKbart2Kafka(ConsumerRecord<String, Stri
// Si la ligne de log sur le topic errorkbart2kafka est de type ERROR
if (logKbart.getLevel().toString().equals("ERROR")) {
if (lastTimeStampByFilename.get(logKbart.getPackageName()) != null) {
Timestamp LastTimestampPlusTwoMinutes = new Timestamp(lastTimeStampByFilename.get(logKbart.getPackageName()).getTime() + TimeUnit.MINUTES.toMillis(2 * 60 * 1000));
Timestamp LastTimestampPlusTwoMinutes = new Timestamp(lastTimeStampByFilename.get(logKbart.getPackageName()).getTime() + TimeUnit.MINUTES.toMillis(2 ));

// Si ca fait 2min qu'on a pas recu de message pour ce fichier
if (currentTimestamp.after(LastTimestampPlusTwoMinutes)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
@Repository
@LogsBdConfiguration
public interface LogKbartRepository extends JpaRepository<LogKbart, Long> {
List<LogKbart> findAllByPackageNameAndTimestampBetween(String filename, Date debut, Date fin);
List<LogKbart> findAllByPackageNameAndTimestampBetweenOrderByNbLineAscTimestampAsc(String filename, Date debut, Date fin);
}
2 changes: 1 addition & 1 deletion src/main/java/fr/abes/logskbart/service/LogsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ public List<LogKbart> getLogKbartForPackage(String packageName, Date date) {
Calendar dateFin = (Calendar) dateChargement.clone();
dateFin.add(Calendar.DAY_OF_MONTH, 1);
log.debug("packageName {}, Date début {}, Date fin {}", packageName, dateChargement.getTime(), dateFin.getTime());
return repository.findAllByPackageNameAndTimestampBetween(packageName, dateChargement.getTime(), dateFin.getTime());
return repository.findAllByPackageNameAndTimestampBetweenOrderByNbLineAscTimestampAsc(packageName, dateChargement.getTime(), dateFin.getTime());
}
}
2 changes: 2 additions & 0 deletions src/main/java/fr/abes/logskbart/utils/LogsMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public LogKbart convert(MappingContext<LogKbartDto, LogKbart> context) {
target.setThreadId(source.getThreadId());
target.setThreadPriority(source.getThreadPriority());
target.setLoggerName(source.getLoggerName());
target.setNbLine(source.getNbLine());
return target;
}
};
Expand All @@ -47,6 +48,7 @@ public LigneLogDto convert(MappingContext<LogKbart, LigneLogDto> context) {
LigneLogDto target = new LigneLogDto();
target.setLevel(source.getLevel().toString());
target.setMessage(source.getMessage());
target.setNbLine(source.getNbLine());
return target;
}
};
Expand Down

0 comments on commit 5ce70d2

Please sign in to comment.