diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index 653aa0d792..4001123a96 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -2909,8 +2909,8 @@ StandardInputData=V2XigLJyZSBubyBzdHJhbmdlcnMgdG8gbG92ZQpZb3Uga25vdyB0aGUgcnVsZX
LogExtraFields=
Configures additional log metadata fields to include in all log records generated by
- processes associated with this unit. This setting takes one or more journal field assignments in the
- format FIELD=VALUE separated by whitespace. See
+ processes associated with this unit, including systemd. This setting takes one or more journal field
+ assignments in the format FIELD=VALUE separated by whitespace. See
systemd.journal-fields7
for details on the journal field concept. Even though the underlying journal implementation permits
binary field values, this setting accepts only valid UTF-8 values. To include space characters in a
diff --git a/src/core/unit.h b/src/core/unit.h
index 3f8377fbf6..d5a6d595e2 100644
--- a/src/core/unit.h
+++ b/src/core/unit.h
@@ -1078,7 +1078,13 @@ Condition *unit_find_failed_condition(Unit *u);
({ \
const Unit *_u = (unit); \
const int _l = (level); \
- (log_get_max_level() < LOG_PRI(_l) || (_u && !unit_log_level_test(_u, _l))) ? -ERRNO_VALUE(error) : \
+ bool _do_log = !(log_get_max_level() < LOG_PRI(_l) || \
+ (_u && !unit_log_level_test(_u, _l))); \
+ const ExecContext *_c = _do_log && _u ? \
+ unit_get_exec_context(_u) : NULL; \
+ LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
+ _c ? _c->n_log_extra_fields : 0); \
+ !_do_log ? -ERRNO_VALUE(error) : \
_u ? log_object_internal(_l, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \
log_internal(_l, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \
})
@@ -1116,7 +1122,12 @@ Condition *unit_find_failed_condition(Unit *u);
({ \
const Unit *_u = (unit); \
const int _l = (level); \
- unit_log_level_test(_u, _l) ? \
+ bool _do_log = unit_log_level_test(_u, _l); \
+ const ExecContext *_c = _do_log && _u ? \
+ unit_get_exec_context(_u) : NULL; \
+ LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
+ _c ? _c->n_log_extra_fields : 0); \
+ _do_log ? \
log_struct_errno(_l, error, __VA_ARGS__, LOG_UNIT_ID(_u)) : \
-ERRNO_VALUE(error); \
})
@@ -1125,8 +1136,14 @@ Condition *unit_find_failed_condition(Unit *u);
#define log_unit_struct_iovec_errno(unit, level, error, iovec, n_iovec) \
({ \
+ const Unit *_u = (unit); \
const int _l = (level); \
- unit_log_level_test(unit, _l) ? \
+ bool _do_log = unit_log_level_test(_u, _l); \
+ const ExecContext *_c = _do_log && _u ? \
+ unit_get_exec_context(_u) : NULL; \
+ LOG_CONTEXT_PUSH_IOV(_c ? _c->log_extra_fields : NULL, \
+ _c ? _c->n_log_extra_fields : 0); \
+ _do_log ? \
log_struct_iovec_errno(_l, error, iovec, n_iovec) : \
-ERRNO_VALUE(error); \
})