### Function

# GLib log_writer_format_fields

since: 2.50

#### Declaration

    gchar*
    g_log_writer_format_fields (
      GLogLevelFlags log_level,
      const GLogField* fields,
      gsize n_fields,
      gboolean use_color
    )

#### Description

Format a structured log message as a string suitable for outputting to the terminal (or elsewhere).

This will include the values of all fields it knows how to interpret, which includes `MESSAGE` and `GLIB_DOMAIN` (see the documentation for `g_log_structured()`). It does not include values from unknown fields.

The returned string does not have a trailing new-line character. It is encoded in the character set of the current locale, which is not necessarily UTF-8.

Available since: 2.50

#### Parameters

`log_level`

  Type: `GLogLevelFlags`

  Log level, either from `GLogLevelFlags`, or a user-defined level.

`fields`

  Type: An array of `GLogField`

  Key–value pairs of structured data forming the log message.

  The length of the array is specified in the `n_fields` argument.
  The data is owned by the caller of the function.

`n_fields`

  Type: `gsize`

  Number of elements in the `fields` array.

`use_color`

  Type: `gboolean`

  `TRUE` to use ANSI color escape sequences when formatting the message, `FALSE` to not.

#### Return value

Type: `gchar*`

String containing the formatted log message, in the character set of the current locale.

The caller of the function takes ownership of the data, and is responsible for freeing it.
The value is a NUL terminated UTF-8 string.