How to Clean Directus Flows Logs

How to Clean Directus Flows Logs

Directus Flows allow you to create custom workflows that can automate repetitive tasks and integrate with various services and APIs.

Introduction

Directus is a powerful open-source tool that provides a headless CMS and a suite of APIs to manage your database. Among its many features is Directus Flows, a powerful automation engine that allows you to create custom workflows to automate tasks and integrate with other services.

  • Over time, Directus Flows can generate a significant amount of logs, especially if your workflows are complex or run frequently.

  • These logs can help with debugging and monitoring, but they can also accumulate and consume storage, potentially affecting the performance of your Directus instance.

  • This blog post will guide you through the process of cleaning Directus Flows logs to ensure your system remains efficient and clutter-free.

Inspiration Behind the Article

In the dynamic world of software development and content management, unexpected issues often arise that challenge us to find innovative solutions. This article was born out of one such challenge faced during a production project.

Recently, our team encountered a surprising situation where a Directus Flow we had set up for a critical operation generated an unexpectedly high number of logs—thousands of them, to be exact. This not only cluttered our logs but also raised concerns about storage usage and system performance. As we delved into the problem, we realized the need for an efficient way to manage and clean up these logs.

This experience motivated us to create an automated solution that could streamline the process of cleaning up logs. We developed a custom Directus Flow that allows us to clean all logs with just a click of a button, ensuring that our system remains efficient and organized without manual intervention.

We wanted to share this solution with the broader community, knowing that others might face similar challenges. By detailing our process and solution, we hope to help you keep your Directus instance clean and running smoothly, just as we did for our project.

What are Directus Flows?

Directus Flows allow you to create custom workflows that can automate repetitive tasks and integrate with various services and APIs. Each flow consists of a series of steps, and these steps can trigger actions like sending an email, updating a database record, or calling an external API.

Every time a flow is executed, Directus logs the event. These logs contain valuable information such as the status of the flow, any errors that occurred, and the time the flow was executed.

Why Clean Directus Flows Logs?

Cleaning Directus Flows logs is essential for several reasons:

  1. Storage Management: Logs can accumulate over time, taking up valuable storage space.

  2. Performance: A large number of logs can slow down your system, affecting the performance of Directus.

  3. Data Privacy: Removing logs that contain sensitive information can help maintain data privacy and security.

  4. Organization: Keeping your logs clean and organized makes it easier to troubleshoot issues and maintain your system.

Step-by-Step Guide to Cleaning Directus Flows Logs

Prerequisites

  • Access to your Directus instance with admin privileges.

  • Basic understanding of Directus Flows and their configurations.

  • Familiarity with your hosting environment and database management tools.

Step 1: Access the Directus Admin Panel

  1. Log in to your Directus instance as an administrator.

  2. Navigate to the Flows section from the sidebar menu.

Step 2: Identify the Logs to Clean

  1. Within the Flows section, locate the specific flow for which you want to clean the logs.

  2. Click on the flow to view its details and history.

  3. In Right Sidebar, You can see Logs.

  4. Review the logs to identify which ones are no longer needed. You can sort logs by date, status, or other criteria to help with this process.

Step 3: Back Up Your Logs

Before deleting any logs, it’s crucial to back them up in case you need to reference them in the future. You can export the logs using the following methods:

  • Export via Directus: Use the export feature in Directus to download the logs in a CSV or JSON format.

  • Database Export: Access your database directly and export the relevant tables or rows containing the logs.

Step 4: Setup Automation

After identifying logs, We will setup flow to delete logs.

  1. Open Settings

  2. Navigate to Flows

  3. Create a New Flow

  4. Enter Name -> Cleanup

Activity & Logs Tracking

  • Select Only Track Activity ( This will avoid occupying additional memory for logs, which is not required for this flow )

  • Provide helpful Description

Trigger Setup

  • You can select Manual to trigger this flow in selected collection

Create Operation

  • After creating trigger, what should happen will be decided by the operation.

  • Select Delete Operation

  • Write directus_revisions in Collection field using raw input instead of selecting from dropdown ( you will not find option in dropdown, since its a system_collection )

Run Flow

  • Open selected collection for running the flow

This will DELETE all the revision logs . Carefully perform this action in production.

Conclusion

  • Cleaning Directus Flows logs is a crucial task to maintain the efficiency and performance of your Directus instance.

  • By following the steps outlined in this guide, you can ensure your logs are managed effectively, keeping your system running smoothly and securely.

Helpful Resources

Upcoming Articles

  • Top 5 Directus Extensions

  • Getting started with Directus and Supabase