I am implementing a use-case where we should delete all data linked to a process from the event log table when the process completes. We use the event log during the lifetime of the process. We also use the data of the completed process after its finished but the events are not needed anymore and should be purged since the log takes a lot of space.

However after my eventlistener have executed and deleted like 300+ events, new events are being created by the process engine. (around 50 events) The last one being PROCESSINSTANCE_END

Please advice.

My eventlistener:

public class CleanupEventLogOnProcessEnd implements FlowableEventListener {

    private static Logger log = LoggerFactory.getLogger(CleanupEventLogOnProcessEnd.class);
    private final ManagementService managementService;

    public CleanupEventLogOnProcessEnd(ManagementService managementService) {
        this.managementService = managementService;

    public void onEvent(FlowableEvent event) {
        if(FlowableEngineEventType.PROCESS_CANCELLED.equals(event.getType()) || FlowableEngineEventType.PROCESS_COMPLETED.equals(event.getType())) {

            FlowableEngineEvent flowableEndEvent = (FlowableEngineEvent) event;
            log.info("Cleaning up event log for processInstanceId {} on process completion");
                    .forEach(eventLogEntry ->

    public boolean isFailOnException() {
        return false;

    public boolean isFireOnTransactionLifecycleEvent() {
        return true;

    public String getOnTransaction() {
        return TransactionState.COMMITTED.name();

Hi Erik,

What happens when there is another listener (after your current one), which adds events to the event log?

One of the possibilities can be to apply housekeeping as it is for history (e.g. once a day purge log table for completed processes).
Another asynchronously plan to delete all events related to the process.


Hi Martin!

I’ll implement some housekeeping instead. Seems those events are created by the engine when clearing out the process variables from the runtime-tables mainly. Tried some different approaches of “quite ugly” overrides of different handlers in the engine, but lets keep it simple with a daily cleaner job instead. :slight_smile:

Anyway thanks!

Hey @billerby,

I am not sure if you’ve seen, but in our recent versions we have added such daily cleaner jobs that you can configure. See Automatic History Cleaning Configuration.


Thanks for the information, nice to know. However in our use case we need to keep the HistoricProcessInstances and just clean out the eventlog entries related to the finished processes. Anyway, we wrote a quartz-initaliazed cleaning job for this that works well. Made the db shrink to half the size :slight_smile:

I get it now. You have enableDatabaseEventLogging set to true on the Process engine configuration, right?

If you are interested you could also provide PR that would allow you to remove specific event log handlers and / or pick which events you would like to log only. This should avoid the need of your quartz initialised cleaning job.