Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge develop dans main #64

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,18 @@
@Plugin(name = "ItemLogAppender", category = "core", elementType = Appender.ELEMENT_TYPE)
public class ItemLogAppender extends AbstractAppender {

// Utilisation d'un ThreadLocal pour stocker l'heure de début de chaque méthode
private static final ThreadLocal<Long> startTime = new ThreadLocal<>();

// Seuil en ms au dessus duquel on veut afficher un message
private final int msSeuilDetection = 0;

protected ItemLogAppender(String name, Filter filter) {
super(name, filter, null);
}

// Méthode à appeler pour démarrer le chronométrage
public static void startMethodExecution() {
startTime.set(System.currentTimeMillis());
}

/**
* Appender permettant une normalisation des logs
* Pour obtenir le temps d'execution d'une méthode, ajoutez
* ItemLogAppender.startMethodExecution();
* au début d'une méthode. L'appender calcule par méthode sans
* besoin d'une borne d'arrêt ou de fin
* @param event
*/
@Override
public void append(LogEvent event) {
if (event.getLevel().isMoreSpecificThan(Level.INFO)) {
String originalMessage = event.getMessage().getFormattedMessage();
String demandeId = ThreadContext.get("demandeId");
String typeDemande = ThreadContext.get("typeDemande");
if (demandeId != null && typeDemande != null) {
// Calcul du temps d'exécution
Long startTimeValue = startTime.get();
long executionTime = startTimeValue != null ? System.currentTimeMillis() - startTimeValue : -1;

if (executionTime < msSeuilDetection) {
System.out.println("DEM_" + typeDemande + "_" + demandeId + " / "
+ event.getSource().getClassName() + " / "
+ event.getSource().getMethodName() + " : "
+ originalMessage);
}
//Uniquement si un ItemLogAppender.startMethodExecution(); à été placé au début d'une méthode
else{
System.out.println("DEM_" + typeDemande + "_" + demandeId + " / "
+ event.getSource().getClassName() + " / "
+ event.getSource().getMethodName() + " : "
+ originalMessage + " / Execution time: " + executionTime + " ms");
}
System.out.println("DEM_" + typeDemande + "_" + demandeId + " : " + originalMessage);
}
}
}
Expand Down
Loading