+/* Structured logging mechanism. */
+
+/**
+ * GLogWriterOutput:
+ * @G_LOG_WRITER_HANDLED: Log writer has handled the log entry.
+ * @G_LOG_WRITER_UNHANDLED: Log writer could not handle the log entry.
+ *
+ * Return values from #GLogWriterFuncs to indicate whether the given log entry
+ * was successfully handled by the writer, or whether there was an error in
+ * handling it (and hence a fallback writer should be used).
+ *
+ * If a #GLogWriterFunc ignores a log entry, it should return
+ * %G_LOG_WRITER_HANDLED.
+ *
+ * Since: 2.50
+ */
+typedef enum
+{
+ G_LOG_WRITER_HANDLED = 1,
+ G_LOG_WRITER_UNHANDLED = 0,
+} GLogWriterOutput;
+
+/**
+ * GLogField:
+ * @key: field name (UTF-8 string)
+ * @value: field value (arbitrary bytes)
+ * @length: length of @value, in bytes, or -1 if it is nul-terminated
+ *
+ * Structure representing a single field in a structured log entry. See
+ * g_log_structured() for details.
+ *
+ * Log fields may contain arbitrary values, including binary with embedded nul
+ * bytes. If the field contains a string, the string must be UTF-8 encoded and
+ * have a trailing nul byte. Otherwise, @length must be set to a non-negative
+ * value.
+ *
+ * Since: 2.50
+ */
+typedef struct _GLogField GLogField;
+struct _GLogField
+{
+ const gchar *key;
+ gconstpointer value;
+ gssize length;
+};
+
+/**
+ * GLogWriterFunc:
+ * @log_level: log level of the message
+ * @fields: (array length=n_fields): fields forming the message
+ * @n_fields: number of @fields
+ * @user_data: user data passed to g_log_set_writer_func()
+ *
+ * Writer function for log entries. A log entry is a collection of one or more
+ * #GLogFields, using the standard [field names from journal
+ * specification](https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html).
+ * See g_log_structured() for more information.
+ *
+ * Writer functions must ignore fields which they do not recognise, unless they
+ * can write arbitrary binary output, as field values may be arbitrary binary.
+ *
+ * @log_level is guaranteed to be included in @fields as the `PRIORITY` field,
+ * but is provided separately for convenience of deciding whether or where to
+ * output the log entry.
+ *
+ * Writer functions should return %G_LOG_WRITER_HANDLED if they handled the log
+ * message successfully or if they deliberately ignored it. If there was an
+ * error handling the message (for example, if the writer function is meant to
+ * send messages to a remote logging server and there is a network error), it
+ * should return %G_LOG_WRITER_UNHANDLED. This allows writer functions to be
+ * chained and fall back to simpler handlers in case of failure.
+ *
+ * Returns: %G_LOG_WRITER_HANDLED if the log entry was handled successfully;
+ * %G_LOG_WRITER_UNHANDLED otherwise
+ *
+ * Since: 2.50
+ */
+typedef GLogWriterOutput (*GLogWriterFunc) (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields,
+ gpointer user_data);
+
+GLIB_AVAILABLE_IN_2_50
+void g_log_structured (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ ...);
+GLIB_AVAILABLE_IN_2_50
+void g_log_structured_array (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields);
+
+GLIB_AVAILABLE_IN_2_50
+void g_log_variant (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ GVariant *fields);
+
+GLIB_AVAILABLE_IN_2_50
+void g_log_set_writer_func (GLogWriterFunc func,
+ gpointer user_data,
+ GDestroyNotify user_data_free);
+
+GLIB_AVAILABLE_IN_2_50
+gboolean g_log_writer_supports_color (gint output_fd);
+GLIB_AVAILABLE_IN_2_50
+gboolean g_log_writer_is_journald (gint output_fd);
+
+GLIB_AVAILABLE_IN_2_50
+gchar *g_log_writer_format_fields (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields,
+ gboolean use_color);
+
+GLIB_AVAILABLE_IN_2_50
+GLogWriterOutput g_log_writer_journald (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields,
+ gpointer user_data);
+GLIB_AVAILABLE_IN_2_50
+GLogWriterOutput g_log_writer_standard_streams (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields,
+ gpointer user_data);
+GLIB_AVAILABLE_IN_2_50
+GLogWriterOutput g_log_writer_default (GLogLevelFlags log_level,
+ const GLogField *fields,
+ gsize n_fields,
+ gpointer user_data);
+
+GLIB_AVAILABLE_IN_2_68
+void g_log_writer_default_set_use_stderr (gboolean use_stderr);
+GLIB_AVAILABLE_IN_2_68
+gboolean g_log_writer_default_would_drop (GLogLevelFlags log_level,
+ const char *log_domain);
+
+/* G_MESSAGES_DEBUG enablement */
+GLIB_AVAILABLE_IN_2_72
+gboolean g_log_get_debug_enabled (void);
+GLIB_AVAILABLE_IN_2_72
+void g_log_set_debug_enabled (gboolean enabled);
+
+/**
+ * G_DEBUG_HERE:
+ *
+ * A convenience form of g_log_structured(), recommended to be added to
+ * functions when debugging. It prints the current monotonic time and the code
+ * location using %G_STRLOC.
+ *
+ * Since: 2.50
+ */
+#define G_DEBUG_HERE() \
+ g_log_structured (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
+ "CODE_FILE", __FILE__, \
+ "CODE_LINE", G_STRINGIFY (__LINE__), \
+ "CODE_FUNC", G_STRFUNC, \
+ "MESSAGE", "%" G_GINT64_FORMAT ": %s", \
+ g_get_monotonic_time (), G_STRLOC)
+
+/* internal */
+void _g_log_fallback_handler (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer unused_data);
+
+/* Internal functions, used to implement the following macros */
+GLIB_AVAILABLE_IN_ALL
+void g_return_if_fail_warning (const char *log_domain,
+ const char *pretty_function,
+ const char *expression) G_ANALYZER_NORETURN;
+GLIB_AVAILABLE_IN_ALL
+void g_warn_message (const char *domain,
+ const char *file,
+ int line,
+ const char *func,
+ const char *warnexpr) G_ANALYZER_NORETURN;
+G_NORETURN
+GLIB_DEPRECATED
+void g_assert_warning (const char *log_domain,
+ const char *file,
+ const int line,
+ const char *pretty_function,
+ const char *expression);
+
+GLIB_AVAILABLE_IN_2_56
+void g_log_structured_standard (const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *file,
+ const gchar *line,
+ const gchar *func,
+ const gchar *message_format,
+ ...) G_GNUC_PRINTF (6, 7);
+