diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-05-11 20:38:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-05-11 22:24:45 +0200 |
commit | f2341e0a87cab1558c84c933956e9181d5fb6c52 (patch) | |
tree | 536878a0b833b532321b34613b20684d8fcf0624 /src/core/job.c | |
parent | 6f856a0992aee3fb06cb13a761b902657ff228ea (diff) |
core,network: major per-object logging rework
This changes log_unit_info() (and friends) to take a real Unit* object
insted of just a unit name as parameter. The call will now prefix all
logged messages with the unit name, thus allowing the unit name to be
dropped from the various passed romat strings, simplifying invocations
drastically, and unifying log output across messages. Also, UNIT= vs.
USER_UNIT= is now derived from the Manager object attached to the Unit
object, instead of getpid(). This has the benefit of correcting the
field for --test runs.
Also contains a couple of other logging improvements:
- Drops a couple of strerror() invocations in favour of using %m.
- Not only .mount units now warn if a symlinks exist for the mount
point already, .automount units do that too, now.
- A few invocations of log_struct() that didn't actually pass any
additional structured data have been replaced by simpler invocations
of log_unit_info() and friends.
- For structured data a new LOG_UNIT_MESSAGE() macro has been added,
that works like LOG_MESSAGE() but prefixes the message with the unit
name. Similar, there's now LOG_LINK_MESSAGE() and
LOG_NETDEV_MESSAGE().
- For structured data new LOG_UNIT_ID(), LOG_LINK_INTERFACE(),
LOG_NETDEV_INTERFACE() macros have been added that generate the
necessary per object fields. The old log_unit_struct() call has been
removed in favour of these new macros used in raw log_struct()
invocations. In addition to removing one more function call this
allows generated structured log messages that contain two object
fields, as necessary for example for network interfaces that are
joined into another network interface, and whose messages shall be
indexed by both.
- The LOG_ERRNO() macro has been removed, in favour of
log_struct_errno(). The latter has the benefit of ensuring that %m in
format strings is properly resolved to the specified error number.
- A number of logging messages have been converted to use
log_unit_info() instead of log_info()
- The client code in sysv-generator no longer #includes core code from
src/core/.
- log_unit_full_errno() has been removed, log_unit_full() instead takes
an errno now, too.
- log_unit_info(), log_link_info(), log_netdev_info() and friends, now
avoid double evaluation of their parameters
Diffstat (limited to 'src/core/job.c')
-rw-r--r-- | src/core/job.c | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/src/core/job.c b/src/core/job.c index a26f7de450..49fcac97dc 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -193,7 +193,7 @@ Job* job_install(Job *j) { if (uj->state == JOB_WAITING || (job_type_allows_late_merge(j->type) && job_type_is_superset(uj->type, j->type))) { job_merge_into_installed(uj, j); - log_unit_debug(uj->unit->id, + log_unit_debug(uj->unit, "Merged into installed job %s/%s as %u", uj->unit->id, job_type_to_string(uj->type), (unsigned) uj->id); return uj; @@ -203,7 +203,7 @@ Job* job_install(Job *j) { /* XXX It should be safer to queue j to run after uj finishes, but it is * not currently possible to have more than one installed job per unit. */ job_merge_into_installed(uj, j); - log_unit_debug(uj->unit->id, + log_unit_debug(uj->unit, "Merged into running job, re-running: %s/%s as %u", uj->unit->id, job_type_to_string(uj->type), (unsigned) uj->id); @@ -218,7 +218,7 @@ Job* job_install(Job *j) { j->installed = true; j->manager->n_installed_jobs ++; - log_unit_debug(j->unit->id, + log_unit_debug(j->unit, "Installed new job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); return j; @@ -236,7 +236,7 @@ int job_install_deserialized(Job *j) { pj = (j->type == JOB_NOP) ? &j->unit->nop_job : &j->unit->job; if (*pj) { - log_unit_debug(j->unit->id, "Unit %s already has a job installed. Not installing deserialized job.", j->unit->id); + log_unit_debug(j->unit, "Unit already has a job installed. Not installing deserialized job."); return -EEXIST; } @@ -246,7 +246,7 @@ int job_install_deserialized(Job *j) { if (j->state == JOB_RUNNING) j->unit->manager->n_running_jobs++; - log_unit_debug(j->unit->id, + log_unit_debug(j->unit, "Reinstalled deserialized job %s/%s as %u", j->unit->id, job_type_to_string(j->type), (unsigned) j->id); return 0; @@ -485,7 +485,9 @@ static bool job_is_runnable(Job *j) { } static void job_change_type(Job *j, JobType newtype) { - log_unit_debug(j->unit->id, + assert(j); + + log_unit_debug(j->unit, "Converting job %s/%s -> %s/%s", j->unit->id, job_type_to_string(j->type), j->unit->id, job_type_to_string(newtype)); @@ -764,28 +766,28 @@ static void job_log_status_message(Unit *u, JobType t, JobResult result) { sd_id128_t mid; mid = result == JOB_DONE ? SD_MESSAGE_UNIT_STARTED : SD_MESSAGE_UNIT_FAILED; - log_unit_struct(u->id, - result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(mid), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); + log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, + LOG_MESSAGE_ID(mid), + LOG_UNIT_ID(u), + LOG_MESSAGE("%s", buf), + "RESULT=%s", job_result_to_string(result), + NULL); } else if (t == JOB_STOP) - log_unit_struct(u->id, - result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); + log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, + LOG_MESSAGE_ID(SD_MESSAGE_UNIT_STOPPED), + LOG_UNIT_ID(u), + LOG_MESSAGE("%s", buf), + "RESULT=%s", job_result_to_string(result), + NULL); else if (t == JOB_RELOAD) - log_unit_struct(u->id, - result == JOB_DONE ? LOG_INFO : LOG_ERR, - LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED), - LOG_MESSAGE("%s", buf), - "RESULT=%s", job_result_to_string(result), - NULL); + log_struct(result == JOB_DONE ? LOG_INFO : LOG_ERR, + LOG_MESSAGE_ID(SD_MESSAGE_UNIT_RELOADED), + LOG_UNIT_ID(u), + LOG_MESSAGE("%s", buf), + "RESULT=%s", job_result_to_string(result), + NULL); } int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) { @@ -803,8 +805,7 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) { j->result = result; - log_unit_debug(u->id, "Job %s/%s finished, result=%s", - u->id, job_type_to_string(t), job_result_to_string(result)); + log_unit_debug(u, "Job %s/%s finished, result=%s", u->id, job_type_to_string(t), job_result_to_string(result)); job_print_status_message(u, t, result); job_log_status_message(u, t, result); @@ -868,15 +869,15 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive) { * this context. And JOB_FAILURE is already handled by the * unit itself. */ if (result == JOB_TIMEOUT || result == JOB_DEPENDENCY) { - log_unit_struct(u->id, - LOG_NOTICE, - "JOB_TYPE=%s", job_type_to_string(t), - "JOB_RESULT=%s", job_result_to_string(result), - LOG_MESSAGE("Job %s/%s failed with result '%s'.", + log_struct(LOG_NOTICE, + "JOB_TYPE=%s", job_type_to_string(t), + "JOB_RESULT=%s", job_result_to_string(result), + LOG_UNIT_ID(u), + LOG_UNIT_MESSAGE(u, "Job %s/%s failed with result '%s'.", u->id, job_type_to_string(t), job_result_to_string(result)), - NULL); + NULL); unit_start_on_failure(u); } @@ -904,7 +905,7 @@ static int job_dispatch_timer(sd_event_source *s, uint64_t monotonic, void *user assert(j); assert(s == j->timer_event_source); - log_unit_warning(j->unit->id, "Job %s/%s timed out.", j->unit->id, job_type_to_string(j->type)); + log_unit_warning(j->unit, "Job %s/%s timed out.", j->unit->id, job_type_to_string(j->type)); u = j->unit; job_finish_and_invalidate(j, JOB_TIMEOUT, true); |