-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ITEM-241 : Ajout appender personnalisé
Récupération numéro et type demande et concaténation dans chaque message envoyé dans les logs
- Loading branch information
1 parent
357e809
commit d1563e1
Showing
3 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
core/src/main/java/fr/abes/item/core/configuration/ItemLogAppender.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fr.abes.item.core.configuration; | ||
|
||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.ThreadContext; | ||
import org.apache.logging.log4j.core.Appender; | ||
import org.apache.logging.log4j.core.Filter; | ||
import org.apache.logging.log4j.core.LogEvent; | ||
import org.apache.logging.log4j.core.appender.AbstractAppender; | ||
import org.apache.logging.log4j.core.config.plugins.Plugin; | ||
import org.apache.logging.log4j.core.config.plugins.PluginAttribute; | ||
import org.apache.logging.log4j.core.config.plugins.PluginElement; | ||
import org.apache.logging.log4j.core.config.plugins.PluginFactory; | ||
|
||
@Plugin(name = "ItemLogAppender", category = "core", elementType = Appender.ELEMENT_TYPE) | ||
public class ItemLogAppender extends AbstractAppender { | ||
|
||
protected ItemLogAppender(String name, Filter filter) { | ||
super(name, filter, null); | ||
} | ||
|
||
@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) { | ||
System.out.println("DEM_" + typeDemande + "_" + demandeId + " : " + originalMessage); | ||
} | ||
} | ||
} | ||
|
||
// Méthode statique pour créer l'instance de l'appender via le fichier de configuration | ||
@PluginFactory | ||
public static ItemLogAppender createAppender( | ||
@PluginAttribute("name") String name, | ||
@PluginElement("Filter") Filter filter) { | ||
return new ItemLogAppender(name, filter); | ||
} | ||
} |