Package org.ametys.core.trace
Class ForensicLogger
java.lang.Object
org.ametys.core.trace.ForensicLogger
- All Implemented Interfaces:
Observer
,Contextualizable
This class is an observer and a helper to trace all forensic events
-
Field Summary
Fields inherited from interface org.ametys.core.observation.Observer
MAX_PRIORITY, MIN_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
contextualize
(Context context) static String
eventArguments
(Map<String, Object> arguments) Build message for event argumentsstatic String
eventIssuer
(UserIdentity user) Get readable value of issuerstatic String
getIP()
Get IP from requeststatic Logger
Get the logger of a given event ID for tracing.int
getPriority
(Event event) Retrieves the priority to observe this event.
This can be used to process a supported event before others observers.static void
Trace event in INFO level to following format: [IP::127.0.0.1] [Issuer::login#population] event.id (arg1::value1|arg2::value2|...) (header1::value1|header2::value2|...)void
Observes an event.static String
Get the request headers to logboolean
Checks if the event is supported.static void
Trace event in WARN level to following format: [IP::127.0.0.1] [Issuer::login#population] event.id (arg1::value1|arg2::value2|...) (header1::value1|header2::value2|...)
-
Constructor Details
-
ForensicLogger
public ForensicLogger()
-
-
Method Details
-
contextualize
- Specified by:
contextualize
in interfaceContextualizable
- Throws:
ContextException
-
getLogger
Get the logger of a given event ID for tracing.- Parameters:
eventId
- The event identifier.- Returns:
- The logger corresponding to the event
-
supports
Description copied from interface:Observer
Checks if the event is supported. If true, the observe(Event) method will be called. -
getPriority
Description copied from interface:Observer
Retrieves the priority to observe this event.
This can be used to process a supported event before others observers.- Specified by:
getPriority
in interfaceObserver
- Parameters:
event
- the event.- Returns:
- the priority where 0 the max priority and Integer.MAX_VALUE the min priority.
-
observe
Description copied from interface:Observer
Observes an event.- Specified by:
observe
in interfaceObserver
- Parameters:
event
- the event.transientVars
- transientVars passed from one Observer to another when processing a single Event. This may allow optimizations between observers.- Throws:
Exception
- if an error occurs. All exceptions will be logged but not propagated, as the observation mechanism should never fail.
-
info
Trace event in INFO level to following format: [IP::127.0.0.1] [Issuer::login#population] event.id (arg1::value1|arg2::value2|...) (header1::value1|header2::value2|...)- Parameters:
eventId
- the event ideventArgs
- the event argumentsissuer
- the issuer. Can be null.
-
warn
Trace event in WARN level to following format: [IP::127.0.0.1] [Issuer::login#population] event.id (arg1::value1|arg2::value2|...) (header1::value1|header2::value2|...)- Parameters:
eventId
- the event ideventArgs
- the event argumentsissuer
- the issuer. Can be null.
-
getIP
Get IP from request- Returns:
- the IP or [unknown] if there is no request
-
requestHeaders
Get the request headers to log- Returns:
- the request headers
-
eventIssuer
Get readable value of issuer- Parameters:
user
- the user. Can be null- Returns:
- the issuer to display in logs
-
eventArguments
Build message for event arguments- Parameters:
arguments
- the arguments- Returns:
- the message to trace for arguments
-