Make slog-stdlog into an optional dependency

slog-stdlog has a significant dependency tree and is basically unsued if
the downstream crate of Smithay always provides a logger (like anvil),
so it is not really needed.
This commit is contained in:
Victor Berger 2020-07-10 12:50:58 +02:00 committed by Victor Berger
parent b75d6524ce
commit 1871b5ddae
27 changed files with 47 additions and 32 deletions

View File

@ -24,7 +24,7 @@ libc = "0.2.70"
libloading = "0.6.0" libloading = "0.6.0"
nix = "0.17" nix = "0.17"
slog = "2" slog = "2"
slog-stdlog = "4" slog-stdlog = { version = "4", optional = true }
tempfile = "3.0" tempfile = "3.0"
thiserror = "1" thiserror = "1"
udev = { version = "0.4", optional = true } udev = { version = "0.4", optional = true }
@ -46,7 +46,7 @@ gl_generator = { version = "0.14", optional = true }
pkg-config = { version = "0.3.17", optional = true } pkg-config = { version = "0.3.17", optional = true }
[features] [features]
default = ["backend_winit", "backend_drm_legacy", "backend_drm_atomic", "backend_drm_gbm", "backend_drm_eglstream", "backend_drm_egl", "backend_libinput", "backend_udev", "backend_session_logind", "renderer_glium", "xwayland", "wayland_frontend"] default = ["backend_winit", "backend_drm_legacy", "backend_drm_atomic", "backend_drm_gbm", "backend_drm_eglstream", "backend_drm_egl", "backend_libinput", "backend_udev", "backend_session_logind", "renderer_glium", "xwayland", "wayland_frontend", "slog-stdlog"]
backend_winit = ["winit", "wayland-server/dlopen", "backend_egl", "wayland-egl", "renderer_gl", "use_system_lib"] backend_winit = ["winit", "wayland-server/dlopen", "backend_egl", "wayland-egl", "renderer_gl", "use_system_lib"]
backend_drm = ["drm", "failure"] backend_drm = ["drm", "failure"]
backend_drm_atomic = ["backend_drm"] backend_drm_atomic = ["backend_drm"]

View File

@ -220,7 +220,7 @@ impl<A: AsRawFd + 'static> AtomicDrmDevice<A> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm"));
info!(log, "AtomicDrmDevice initializing"); info!(log, "AtomicDrmDevice initializing");
let dev_id = fstat(fd.as_raw_fd()).map_err(Error::UnableToGetDeviceId)?.st_rdev; let dev_id = fstat(fd.as_raw_fd()).map_err(Error::UnableToGetDeviceId)?.st_rdev;

View File

@ -181,7 +181,7 @@ impl<A: AsRawFd + Clone + 'static> FallbackDevice<AtomicDrmDevice<A>, LegacyDrmD
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm_fallback")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm_fallback"));
info!(log, "Trying to initialize AtomicDrmDevice"); info!(log, "Trying to initialize AtomicDrmDevice");
let force_legacy = env::var("SMITHAY_USE_LEGACY") let force_legacy = env::var("SMITHAY_USE_LEGACY")
@ -246,7 +246,7 @@ where
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm_fallback")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm_fallback"));
let driver = crate::backend::udev::driver(dev.device_id()).expect("Failed to query device"); let driver = crate::backend::udev::driver(dev.device_id()).expect("Failed to query device");
info!(log, "Drm device driver: {:?}", driver); info!(log, "Drm device driver: {:?}", driver);
@ -299,7 +299,7 @@ where
D2: NativeDisplay<B2, Arguments = EglDeviceArguments>, D2: NativeDisplay<B2, Arguments = EglDeviceArguments>,
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm_fallback")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm_fallback"));
match dev { match dev {
FallbackDevice::Preference(gbm) => match EglDevice::new(gbm, log) { FallbackDevice::Preference(gbm) => match EglDevice::new(gbm, log) {
Ok(dev) => Ok(FallbackDevice::Preference(dev)), Ok(dev) => Ok(FallbackDevice::Preference(dev)),
@ -335,7 +335,7 @@ where
D2: NativeDisplay<B2, Arguments = EglDeviceArguments>, D2: NativeDisplay<B2, Arguments = EglDeviceArguments>,
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm_fallback")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm_fallback"));
match dev { match dev {
FallbackDevice::Preference(gbm) => { FallbackDevice::Preference(gbm) => {
match EglDevice::new_with_defaults(gbm, default_attributes, default_requirements, log) { match EglDevice::new_with_defaults(gbm, default_attributes, default_requirements, log) {

View File

@ -123,7 +123,7 @@ where
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_egl")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_egl"));
dev.clear_handler(); dev.clear_handler();

View File

@ -98,7 +98,7 @@ impl<D: RawDevice + ControlDevice + 'static> EglStreamDevice<D> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_eglstream")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_eglstream"));
raw.clear_handler(); raw.clear_handler();

View File

@ -106,7 +106,7 @@ impl<D: RawDevice + ControlDevice + 'static> GbmDevice<D> {
); );
}); });
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_gbm")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_gbm"));
dev.clear_handler(); dev.clear_handler();

View File

@ -119,7 +119,7 @@ impl<A: AsRawFd + 'static> LegacyDrmDevice<A> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_drm")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_drm"));
info!(log, "LegacyDrmDevice initializing"); info!(log, "LegacyDrmDevice initializing");
let dev_id = fstat(dev.as_raw_fd()) let dev_id = fstat(dev.as_raw_fd())

View File

@ -33,7 +33,7 @@ impl EGLContext {
B: native::Backend, B: native::Backend,
N: native::NativeDisplay<B>, N: native::NativeDisplay<B>,
{ {
let log = crate::slog_or_stdlog(log.into()).new(o!("smithay_module" => "renderer_egl")); let log = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "renderer_egl"));
// If no version is given, try OpenGLES 3.0, if available, // If no version is given, try OpenGLES 3.0, if available,
// fallback to 2.0 otherwise // fallback to 2.0 otherwise

View File

@ -69,7 +69,7 @@ impl<B: native::Backend, N: native::NativeDisplay<B>> EGLDisplay<B, N> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger.into()).new(o!("smithay_module" => "renderer_egl")); let log = crate::slog_or_fallback(logger.into()).new(o!("smithay_module" => "renderer_egl"));
let ptr = native.ptr()?; let ptr = native.ptr()?;
let egl_attribs = native.attributes(); let egl_attribs = native.attributes();

View File

@ -50,7 +50,7 @@ impl<N: native::NativeSurface> EGLSurface<N> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(log.into()).new(o!("smithay_module" => "renderer_egl")); let log = crate::slog_or_fallback(log.into()).new(o!("smithay_module" => "renderer_egl"));
let surface_attributes = { let surface_attributes = {
let mut out: Vec<c_int> = Vec::with_capacity(3); let mut out: Vec<c_int> = Vec::with_capacity(3);

View File

@ -47,7 +47,7 @@ impl LibinputInputBackend {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_libinput")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_libinput"));
info!(log, "Initializing a libinput backend"); info!(log, "Initializing a libinput backend");
LibinputInputBackend { LibinputInputBackend {
context, context,

View File

@ -69,7 +69,7 @@ impl AutoSession {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let logger = crate::slog_or_stdlog(logger) let logger = crate::slog_or_fallback(logger)
.new(o!("smithay_module" => "backend_session_auto", "session_type" => "auto")); .new(o!("smithay_module" => "backend_session_auto", "session_type" => "auto"));
info!(logger, "Trying to create logind session"); info!(logger, "Trying to create logind session");

View File

@ -89,7 +89,7 @@ impl LogindSession {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let logger = crate::slog_or_stdlog(logger) let logger = crate::slog_or_fallback(logger)
.new(o!("smithay_module" => "backend_session", "session_type" => "logind")); .new(o!("smithay_module" => "backend_session", "session_type" => "logind"));
// Acquire session_id, seat and vt (if any) via libsystemd // Acquire session_id, seat and vt (if any) via libsystemd

View File

@ -168,7 +168,7 @@ impl DirectSession {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let logger = crate::slog_or_stdlog(logger) let logger = crate::slog_or_fallback(logger)
.new(o!("smithay_module" => "backend_session", "session_type" => "direct/vt")); .new(o!("smithay_module" => "backend_session", "session_type" => "direct/vt"));
let fd = tty let fd = tty

View File

@ -78,7 +78,7 @@ impl UdevBackend {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_udev")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_udev"));
let devices = all_gpus(seat)? let devices = all_gpus(seat)?
.into_iter() .into_iter()

View File

@ -152,7 +152,7 @@ pub fn init_from_builder_with_gl_attr<L>(
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "backend_winit")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "backend_winit"));
info!(log, "Initializing a winit backend"); info!(log, "Initializing a winit backend");
let events_loop = EventLoop::new(); let events_loop = EventLoop::new();

View File

@ -2,7 +2,10 @@
//! **Smithay: the Wayland compositor smithy** //! **Smithay: the Wayland compositor smithy**
//! //!
//! Most entry points in the modules can take an optional [`slog::Logger`](::slog::Logger) as argument //! Most entry points in the modules can take an optional [`slog::Logger`](::slog::Logger) as argument
//! that will be used as a drain for logging. If `None` is provided, they'll log to `slog-stdlog`. //! that will be used as a drain for logging. If `None` is provided, the behavior depends on
//! whether the `slog-stdlog` is enabled. If yes, the module will log to the global logger of the
//! `log` crate. If not, the logs will discarded. This cargo feature is part of the default set of
//! features of Smithay.
// `error_chain!` can recurse deeply // `error_chain!` can recurse deeply
#![recursion_limit = "1024"] #![recursion_limit = "1024"]
@ -29,7 +32,8 @@ pub mod xwayland;
pub mod reexports; pub mod reexports;
fn slog_or_stdlog<L>(logger: L) -> ::slog::Logger #[cfg(feature = "slog-stdlog")]
fn slog_or_fallback<L>(logger: L) -> ::slog::Logger
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
@ -38,3 +42,13 @@ where
.into() .into()
.unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!())) .unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!()))
} }
#[cfg(not(feature = "slog-stdlog"))]
fn slog_or_fallback<L>(logger: L) -> ::slog::Logger
where
L: Into<Option<::slog::Logger>>,
{
logger
.into()
.unwrap_or_else(|| ::slog::Logger::root(::slog::Discard, o!()))
}

View File

@ -491,7 +491,7 @@ where
R: Default + RoleType + Role<SubsurfaceRole> + Send + 'static, R: Default + RoleType + Role<SubsurfaceRole> + Send + 'static,
Impl: FnMut(SurfaceEvent, WlSurface, CompositorToken<R>) + 'static, Impl: FnMut(SurfaceEvent, WlSurface, CompositorToken<R>) + 'static,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "compositor_handler")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "compositor_handler"));
let implem = Rc::new(RefCell::new(implem)); let implem = Rc::new(RefCell::new(implem));
let compositor = display.create_global( let compositor = display.create_global(

View File

@ -286,7 +286,7 @@ where
R: Role<DnDIconRole> + 'static, R: Role<DnDIconRole> + 'static,
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "data_device_mgr")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "data_device_mgr"));
let action_choice = Rc::new(RefCell::new(action_choice)); let action_choice = Rc::new(RefCell::new(action_choice));
let callback = Rc::new(RefCell::new(callback)); let callback = Rc::new(RefCell::new(callback));
display.create_global( display.create_global(

View File

@ -183,7 +183,7 @@ where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
H: DmabufHandler + 'static, H: DmabufHandler + 'static,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "dmabuf_handler")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "dmabuf_handler"));
let max_planes = formats.iter().map(|f| f.plane_count).max().unwrap_or(0); let max_planes = formats.iter().map(|f| f.plane_count).max().unwrap_or(0);
let formats = Rc::new(formats); let formats = Rc::new(formats);

View File

@ -206,7 +206,8 @@ where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
R: 'static, R: 'static,
{ {
let _log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "wayland_explicit_synchronization")); let _log =
crate::slog_or_fallback(logger).new(o!("smithay_module" => "wayland_explicit_synchronization"));
display.create_global::<ZwpLinuxExplicitSynchronizationV1, _>( display.create_global::<ZwpLinuxExplicitSynchronizationV1, _>(
2, 2,

View File

@ -174,7 +174,7 @@ impl Output {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger).new(o!("smithay_module" => "output_handler")); let log = crate::slog_or_fallback(logger).new(o!("smithay_module" => "output_handler"));
info!(log, "Creating new wl_output"; "name" => &name); info!(log, "Creating new wl_output"; "name" => &name);

View File

@ -127,7 +127,7 @@ impl Seat {
R: Role<CursorImageRole> + 'static, R: Role<CursorImageRole> + 'static,
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger); let log = crate::slog_or_fallback(logger);
let arc = Rc::new(SeatRc { let arc = Rc::new(SeatRc {
inner: RefCell::new(Inner { inner: RefCell::new(Inner {
pointer: None, pointer: None,

View File

@ -305,7 +305,7 @@ where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
Impl: FnMut(ShellRequest<R>) + 'static, Impl: FnMut(ShellRequest<R>) + 'static,
{ {
let _log = crate::slog_or_stdlog(logger); let _log = crate::slog_or_fallback(logger);
let implementation = Rc::new(RefCell::new(implementation)); let implementation = Rc::new(RefCell::new(implementation));

View File

@ -289,7 +289,7 @@ where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
Impl: FnMut(XdgRequest<R>) + 'static, Impl: FnMut(XdgRequest<R>) + 'static,
{ {
let log = crate::slog_or_stdlog(logger); let log = crate::slog_or_fallback(logger);
let shell_state = Arc::new(Mutex::new(ShellState { let shell_state = Arc::new(Mutex::new(ShellState {
known_toplevels: Vec::new(), known_toplevels: Vec::new(),
known_popups: Vec::new(), known_popups: Vec::new(),

View File

@ -109,7 +109,7 @@ pub fn init_shm_global<L>(
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger); let log = crate::slog_or_fallback(logger);
// always add the mandatory formats // always add the mandatory formats
formats.push(wl_shm::Format::Argb8888); formats.push(wl_shm::Format::Argb8888);

View File

@ -88,7 +88,7 @@ impl<WM: XWindowManager + 'static> XWayland<WM> {
where where
L: Into<Option<::slog::Logger>>, L: Into<Option<::slog::Logger>>,
{ {
let log = crate::slog_or_stdlog(logger); let log = crate::slog_or_fallback(logger);
let inner = Rc::new(RefCell::new(Inner { let inner = Rc::new(RefCell::new(Inner {
wm, wm,
kill_source: { kill_source: {