`buildboxcommon_logging.h`: use glog

Context

The current logging mechanism provided by buildboxcommon_logging.h is not thread-safe.

In order to get rid of that limitation, a potential solution is to start using glog.

Backwards compatibility

In terms of code changes, the impact of doing this switch should be minimal: the BUILDBOX_LOG_() macros that are currently in place would be kept, and programs that use buildbox-common's logging mechanism will only need to add a call to an initialization macro from main().

Limitations

However, a couple of significant changes would be introduced:

Prefix format

This is the information that is attached before the actual log message. glog uses its own prefix format, and it is not configurable.

Below are two sample outputs. The first message is produced by buildboxcommon current logging mechanism and the second one by glog:

2020-08-12T12:30:10.992+0100 [11522:139658511665152] [buildboxcasd_daemon.cpp:51] message
I20200812 12:30:10.992000  8105 buildboxcasd_daemon.cpp:51] message

The full format specifications are available here: glog, buildboxcommon_logging.

While buildbox-common prints the value of getpid() and pthread_self(), glog prefers gettid() when available.

(On May 2020 we've opened a PR upstream (https://github.com/google/glog/pull/554) in order to implement support for customizing the prefix format, but as of this writing it is still waiting for review.)

Logging to arbitrary files

buildboxcommon_logging provides the BUILDBOX_LOG_SET_FILE() macro that allows to redirect the output to an arbitrary file.

This is not possible in glog, which creates files in a directory and allows customizing only the path of the directory and the base name of the file. It attaches a suffix with a hardcoded format to that base name.

Task Description

Describe the steps to take / implementation plan. If it's a bug, do you know how it may be tackled?

  • Discuss whether this is the right choice and whether the changes that it will introduce are acceptable
  • If agreement is reached, introduce glog as a dependency and replace the current logic implemented in buildboxcommon_logging.{h,cpp} for calls to glog
  • Update documentation accordingly

Acceptance Criteria

buildbox-common provides a thread-safe logging mechanism

Consider whether the following are required, and complete if so:

  • Unit tests
  • Metrics
  • Documentation update(s)
Edited Aug 12, 2020 by Santiago Gil
Assignee Loading
Time tracking Loading