How to Truncate Long Logs in Fluent Bit
To truncate logs in Fluent Bit, the easiest option is to use a Lua script.
Assuming you have the following log entry from an application:
To truncate the msg field in these logs, you can use a Lua script along with your Fluent Bit configuration file.
Create a Lua script named truncate.lua with the following content:
The highlighted line specifies the maximum length. Here, it is set to five characters for demonstration purposes. You can set it to a higher value in a real-world application as needed.
Here is how you can reference the Lua script in your Fluent Bit configuration file (fluent-bit.conf):
Adding the filter section allows Fluent Bit to reference the Lua script to truncate the logs.
When you restart Fluent Bit, you will see the logs truncated:
As you can see, the msg field only contains text with up to 5 characters.
Using this Lua, you can easily control the length of specific log fields in Fluent Bit.