Once we have our new extension storage engine, we'll want to wire it up to the Desktop Sync logging machinery. For Reasons, this is a bit more complicated than it has to be, and I wanted to capture some of those sticking points in this ticket. This will involve changes to both a-s and m-c.
The standard for Rust logging is the
log crate, which we use extensively in a-s. Unfortunately,
log only lets you set a global logger, and only once. That means calling
set_boxed_logger will set it for all of Firefox—I think one is already set, anyway, so that will fail with an error. But, even if it did work, we wouldn't want that, because other in-tree crates also use
log. We don't want, say, WebRender and Necko trace logs getting written into
This is why Dogear basically reimplements the
log macros, but with a "driver" as the first argument. The driver has a
logger, which, by default, uses the
log crate's global logger. But Desktop overrides this to return its own logger, which calls into the Sync logger. There's some complicated machinery around dispatching log messages to the main thread, which we need to do because the logger is in JS. All of that is factored out into
golden_gate::LogSink. On the JS side, we have another tiny helper class that adapts a
Log.jsm logger to a
If we want to copy what Dogear does, on the a-s side, we can add a new support crate (
log-support?) with our reimplemented macros, and have them take a
&dyn Log. We can store the logger in a field on
webext_storage::Store, and pass it to any method that needs it, and thread that through to the callback.
It's kind of unfortunate that this means passing an extra
log: &dyn Log as an argument to any function that wants to do logging, but it's one approach. Let's brainstorm others in this ticket, too!
Whatever approach we decide on here, we'll probably want to copy for our other Desktop integrations.