Skip to content

Tuncate IP addresses

Output filter: ip-truncate-fields

This plugin replaces IP addresses with an anonymized string, replacing the last block of an IP address with "0".

Example (client_ip field):

  • IPv4: ->
  • IPv6: 2001:db8:0:0:0:ff00:42:8329 -> 2001:db8:0:0:0:ff00:42:0

All occurrences of the IP address are replaced in the log "message" fields with the new value.

Example (message field): "Client connect" -> "Client connect"

In the context of data protection regulations like GDPR, you might need to mask data fields, especially when you handover log data to 3rd parties.

For a stronger protection check other output plugins:


Add the following section 'outputFilter' to the Logagent configuration file. Please note you could use the plugin with multiple configurations for different event sources.

# tail web server logs
    - '/var/log/*/access_log'

# log agent parses web server logs out of the box ...
    module: ip-truncate-fields
    # JS regular expression to match log source name
    matchSource: !!js/regexp access_log
      - client_ip

Run Logagent with your config:

logagent --config logagent-example-config.yml -n httpd --yaml

The output replaced IP '::1' with '::0':

logSource:    httpd
_type:        access_common
client_ip:    ::0
remote_id:    -
user:         null
method:       GET
path:         /
http_version: HTTP/1.1
status_code:  304
size:         0
@timestamp:   Thu Apr 26 2018 22:02:26 GMT+0200 (CEST)