github.com/Jeffail/benthos/v3@v3.65.0/website/docs/components/processors/log.md (about)

     1  ---
     2  title: log
     3  type: processor
     4  status: stable
     5  categories: ["Utility"]
     6  ---
     7  
     8  <!--
     9       THIS FILE IS AUTOGENERATED!
    10  
    11       To make changes please edit the contents of:
    12       lib/processor/log.go
    13  -->
    14  
    15  import Tabs from '@theme/Tabs';
    16  import TabItem from '@theme/TabItem';
    17  
    18  
    19  Prints a log event each time it processes a batch. Messages always remain
    20  unchanged. The log message can be set using function interpolations described
    21  [here](/docs/configuration/interpolation#bloblang-queries) which allows you to log the
    22  contents and metadata of messages.
    23  
    24  ```yaml
    25  # Config fields, showing default values
    26  label: ""
    27  log:
    28    level: INFO
    29    fields: {}
    30    fields_mapping: ""
    31    message: ""
    32  ```
    33  
    34  In order to print a log message per message of a batch place it within a
    35  [`for_each`](/docs/components/processors/for_each) processor.
    36  
    37  For example, if we wished to create a debug log event for each message in a
    38  pipeline in order to expose the JSON field `foo.bar` as well as the
    39  metadata field `kafka_partition` we can achieve that with the
    40  following config:
    41  
    42  ```yaml
    43  pipeline:
    44    processors:
    45      - for_each:
    46        - log:
    47            level: DEBUG
    48            message: 'field: ${! json("foo.bar") }, part: ${! meta("kafka_partition") }'
    49  ```
    50  
    51  The `level` field determines the log level of the printed events and
    52  can be any of the following values: TRACE, DEBUG, INFO, WARN, ERROR.
    53  
    54  ### Structured Fields
    55  
    56  It's also possible add custom fields to logs when the format is set to a structured form such as `json` or `logfmt`. The config field `fields` allows you to provide a map of key/value string pairs, where the values support [interpolation functions](/docs/configuration/interpolation#bloblang-queries) allowing you to extract message contents and metadata like this:
    57  
    58  ```yaml
    59  pipeline:
    60    processors:
    61      - log:
    62          level: DEBUG
    63          message: hello world
    64          fields:
    65            reason: cus I wana
    66            id: ${! json("id") }
    67            age: ${! json("user.age") }
    68            kafka_topic: ${! meta("kafka_topic") }
    69  ```
    70  
    71  However, these values will always be output as string types. In cases where you want to add other types such as integers or booleans you can use the field `fields_mapping` to define a [Bloblang mapping](/docs/guides/bloblang/about) that outputs a map of key/values like this:
    72  
    73  ```yaml
    74  pipeline:
    75    processors:
    76      - log:
    77          level: DEBUG
    78          message: hello world
    79          fields_mapping: |
    80            root.reason = "cus I wana"
    81            root.id = this.id
    82            root.age = this.user.age
    83            root.kafka_topic = meta("kafka_topic")
    84  ```
    85  
    86  
    87  ## Fields
    88  
    89  ### `level`
    90  
    91  The log level to use.
    92  
    93  
    94  Type: `string`  
    95  Default: `"INFO"`  
    96  Options: `FATAL`, `ERROR`, `WARN`, `INFO`, `DEBUG`, `TRACE`, `ALL`.
    97  
    98  ### `fields`
    99  
   100  A map of fields to print along with the log message.
   101  This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries).
   102  
   103  
   104  Type: `object`  
   105  Default: `{}`  
   106  
   107  ### `fields_mapping`
   108  
   109  An optional [Bloblang mapping](/docs/guides/bloblang/about) that can be used to specify extra fields to add to the log. If log fields are also added with the `fields` field then those values will override matching keys from this mapping.
   110  
   111  
   112  Type: `string`  
   113  Default: `""`  
   114  Requires version 3.40.0 or newer  
   115  
   116  ```yaml
   117  # Examples
   118  
   119  fields_mapping: |-
   120    root.reason = "cus I wana"
   121    root.id = this.id
   122    root.age = this.user.age.number()
   123    root.kafka_topic = meta("kafka_topic")
   124  ```
   125  
   126  ### `message`
   127  
   128  The message to print.
   129  This field supports [interpolation functions](/docs/configuration/interpolation#bloblang-queries).
   130  
   131  
   132  Type: `string`  
   133  Default: `""`  
   134  
   135