Skip to content

pressure-vessel: Put apt-style severity prefixes on messages

Simon McVittie requested to merge wip/message-prefix into master

These indicate which lines are harmless and which lines are really bad, without taking up too much space.

The mapping from GLib log level to message is not 100% obvious, because G_LOG_LEVEL_ERROR is "worse than" an error. We diagnose "can't happen" situations (assertion failures, etc.) as "Internal error". Ideally, users should never see these: they indicate a bug.

For situations that will cause pressure-vessel to exit with an error, introduce a new log level flag PV_LOG_LEVEL_FAILURE and map it to the apt-style "E:" prefix. pv_log_failure() is a convenience macro to log at level PV_LOG_LEVEL_FAILURE. Conceptually this is a fatal error, but it's a fatal error prompted by something external to pressure-vessel, for which we want pressure-vessel to clean up "nicely" and exit gracefully, even though it's going to fail - so we can't use g_error() for this.

In the parts of main() that involve parsing command-line arguments, add usage_error() as syntactic sugar for pv_log_failure(). I might eventually turn these into G_OPTION_ERROR_FAILED as we factor out more of main() into helper functions, but for now they're handled separately.

For less-severe log levels, use single-letter prefixes similar to apt's.


Example output:

$ PRESSURE_VESSEL_LOG_INFO=1 PRESSURE_VESSEL_LOG_WITH_TIMESTAMP=1 \
  ./_build/in-sysroot/pressure-vessel/pressure-vessel-wrap \
  --runtime=x --runtime-archive=y --verbose
12:37:52.140424: pressure-vessel-wrap[1781669]: I: pressure-vessel version 0.20210203.0.86-e97d
12:37:52.140546: pressure-vessel-wrap[1781669]: E: --runtime and --runtime-archive cannot both be used
12:37:52.140567: pressure-vessel-wrap[1781669]: D: Exiting with status 2

Merge request reports