diff --git a/Cargo.toml b/Cargo.toml index 4202732..f4c0287 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,7 +24,7 @@ libc = "0.2.70" libloading = "0.6.0" nix = "0.17" slog = "2" -slog-stdlog = "4" +slog-stdlog = { version = "4", optional = true } tempfile = "3.0" thiserror = "1" 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 } [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_drm = ["drm", "failure"] backend_drm_atomic = ["backend_drm"] diff --git a/src/backend/drm/atomic/mod.rs b/src/backend/drm/atomic/mod.rs index 1d2e1f9..507abd3 100644 --- a/src/backend/drm/atomic/mod.rs +++ b/src/backend/drm/atomic/mod.rs @@ -220,7 +220,7 @@ impl AtomicDrmDevice { where L: Into>, { - 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"); let dev_id = fstat(fd.as_raw_fd()).map_err(Error::UnableToGetDeviceId)?.st_rdev; diff --git a/src/backend/drm/common/fallback.rs b/src/backend/drm/common/fallback.rs index bfc55d1..bea7378 100644 --- a/src/backend/drm/common/fallback.rs +++ b/src/backend/drm/common/fallback.rs @@ -181,7 +181,7 @@ impl FallbackDevice, LegacyDrmD where L: Into>, { - 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"); let force_legacy = env::var("SMITHAY_USE_LEGACY") @@ -246,7 +246,7 @@ where where L: Into>, { - 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"); info!(log, "Drm device driver: {:?}", driver); @@ -299,7 +299,7 @@ where D2: NativeDisplay, L: Into>, { - 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 { FallbackDevice::Preference(gbm) => match EglDevice::new(gbm, log) { Ok(dev) => Ok(FallbackDevice::Preference(dev)), @@ -335,7 +335,7 @@ where D2: NativeDisplay, L: Into>, { - 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 { FallbackDevice::Preference(gbm) => { match EglDevice::new_with_defaults(gbm, default_attributes, default_requirements, log) { diff --git a/src/backend/drm/egl/mod.rs b/src/backend/drm/egl/mod.rs index b9397d8..dac507f 100644 --- a/src/backend/drm/egl/mod.rs +++ b/src/backend/drm/egl/mod.rs @@ -123,7 +123,7 @@ where where L: Into>, { - 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(); diff --git a/src/backend/drm/eglstream/mod.rs b/src/backend/drm/eglstream/mod.rs index 3d8db14..69f759b 100644 --- a/src/backend/drm/eglstream/mod.rs +++ b/src/backend/drm/eglstream/mod.rs @@ -98,7 +98,7 @@ impl EglStreamDevice { where L: Into>, { - 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(); diff --git a/src/backend/drm/gbm/mod.rs b/src/backend/drm/gbm/mod.rs index d2f561d..b09f139 100644 --- a/src/backend/drm/gbm/mod.rs +++ b/src/backend/drm/gbm/mod.rs @@ -106,7 +106,7 @@ impl GbmDevice { ); }); - 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(); diff --git a/src/backend/drm/legacy/mod.rs b/src/backend/drm/legacy/mod.rs index cc07a66..5302601 100644 --- a/src/backend/drm/legacy/mod.rs +++ b/src/backend/drm/legacy/mod.rs @@ -119,7 +119,7 @@ impl LegacyDrmDevice { where L: Into>, { - 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"); let dev_id = fstat(dev.as_raw_fd()) diff --git a/src/backend/egl/context.rs b/src/backend/egl/context.rs index 06cb889..9b16651 100644 --- a/src/backend/egl/context.rs +++ b/src/backend/egl/context.rs @@ -33,7 +33,7 @@ impl EGLContext { B: native::Backend, N: native::NativeDisplay, { - 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, // fallback to 2.0 otherwise diff --git a/src/backend/egl/display.rs b/src/backend/egl/display.rs index d5c733a..0e960cd 100644 --- a/src/backend/egl/display.rs +++ b/src/backend/egl/display.rs @@ -69,7 +69,7 @@ impl> EGLDisplay { where L: Into>, { - 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 egl_attribs = native.attributes(); diff --git a/src/backend/egl/surface.rs b/src/backend/egl/surface.rs index 37bc7ff..163350f 100644 --- a/src/backend/egl/surface.rs +++ b/src/backend/egl/surface.rs @@ -50,7 +50,7 @@ impl EGLSurface { where L: Into>, { - 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 mut out: Vec = Vec::with_capacity(3); diff --git a/src/backend/libinput/mod.rs b/src/backend/libinput/mod.rs index 3ec0566..3672993 100644 --- a/src/backend/libinput/mod.rs +++ b/src/backend/libinput/mod.rs @@ -47,7 +47,7 @@ impl LibinputInputBackend { where L: Into>, { - 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"); LibinputInputBackend { context, diff --git a/src/backend/session/auto.rs b/src/backend/session/auto.rs index 0e4ca21..289e83b 100644 --- a/src/backend/session/auto.rs +++ b/src/backend/session/auto.rs @@ -69,7 +69,7 @@ impl AutoSession { where L: Into>, { - let logger = crate::slog_or_stdlog(logger) + let logger = crate::slog_or_fallback(logger) .new(o!("smithay_module" => "backend_session_auto", "session_type" => "auto")); info!(logger, "Trying to create logind session"); diff --git a/src/backend/session/dbus/logind.rs b/src/backend/session/dbus/logind.rs index 7cf258c..44ff53d 100644 --- a/src/backend/session/dbus/logind.rs +++ b/src/backend/session/dbus/logind.rs @@ -89,7 +89,7 @@ impl LogindSession { where L: Into>, { - let logger = crate::slog_or_stdlog(logger) + let logger = crate::slog_or_fallback(logger) .new(o!("smithay_module" => "backend_session", "session_type" => "logind")); // Acquire session_id, seat and vt (if any) via libsystemd diff --git a/src/backend/session/direct.rs b/src/backend/session/direct.rs index a15b4f2..3eaae76 100644 --- a/src/backend/session/direct.rs +++ b/src/backend/session/direct.rs @@ -168,7 +168,7 @@ impl DirectSession { where L: Into>, { - let logger = crate::slog_or_stdlog(logger) + let logger = crate::slog_or_fallback(logger) .new(o!("smithay_module" => "backend_session", "session_type" => "direct/vt")); let fd = tty diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 7615a86..ffae665 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -78,7 +78,7 @@ impl UdevBackend { where L: Into>, { - 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)? .into_iter() diff --git a/src/backend/winit.rs b/src/backend/winit.rs index 2d90a24..4204c56 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -152,7 +152,7 @@ pub fn init_from_builder_with_gl_attr( where L: Into>, { - 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"); let events_loop = EventLoop::new(); diff --git a/src/lib.rs b/src/lib.rs index ec15e1f..a9d1b5f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,10 @@ //! **Smithay: the Wayland compositor smithy** //! //! 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 #![recursion_limit = "1024"] @@ -29,7 +32,8 @@ pub mod xwayland; pub mod reexports; -fn slog_or_stdlog(logger: L) -> ::slog::Logger +#[cfg(feature = "slog-stdlog")] +fn slog_or_fallback(logger: L) -> ::slog::Logger where L: Into>, { @@ -38,3 +42,13 @@ where .into() .unwrap_or_else(|| ::slog::Logger::root(::slog_stdlog::StdLog.fuse(), o!())) } + +#[cfg(not(feature = "slog-stdlog"))] +fn slog_or_fallback(logger: L) -> ::slog::Logger +where + L: Into>, +{ + logger + .into() + .unwrap_or_else(|| ::slog::Logger::root(::slog::Discard, o!())) +} diff --git a/src/wayland/compositor/mod.rs b/src/wayland/compositor/mod.rs index 7c0b148..43aeca7 100644 --- a/src/wayland/compositor/mod.rs +++ b/src/wayland/compositor/mod.rs @@ -491,7 +491,7 @@ where R: Default + RoleType + Role + Send + 'static, Impl: FnMut(SurfaceEvent, WlSurface, CompositorToken) + '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 compositor = display.create_global( diff --git a/src/wayland/data_device/mod.rs b/src/wayland/data_device/mod.rs index ae8a01b..912311d 100644 --- a/src/wayland/data_device/mod.rs +++ b/src/wayland/data_device/mod.rs @@ -286,7 +286,7 @@ where R: Role + 'static, L: Into>, { - 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 callback = Rc::new(RefCell::new(callback)); display.create_global( diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index 7bdd35b..af8a681 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -183,7 +183,7 @@ where L: Into>, 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 formats = Rc::new(formats); diff --git a/src/wayland/explicit_synchronization/mod.rs b/src/wayland/explicit_synchronization/mod.rs index 150ba87..9b5d59b 100644 --- a/src/wayland/explicit_synchronization/mod.rs +++ b/src/wayland/explicit_synchronization/mod.rs @@ -206,7 +206,8 @@ where L: Into>, 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::( 2, diff --git a/src/wayland/output/mod.rs b/src/wayland/output/mod.rs index 601feed..73b199a 100644 --- a/src/wayland/output/mod.rs +++ b/src/wayland/output/mod.rs @@ -174,7 +174,7 @@ impl Output { where L: Into>, { - 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); diff --git a/src/wayland/seat/mod.rs b/src/wayland/seat/mod.rs index 46d6d60..a36c964 100644 --- a/src/wayland/seat/mod.rs +++ b/src/wayland/seat/mod.rs @@ -127,7 +127,7 @@ impl Seat { R: Role + 'static, L: Into>, { - let log = crate::slog_or_stdlog(logger); + let log = crate::slog_or_fallback(logger); let arc = Rc::new(SeatRc { inner: RefCell::new(Inner { pointer: None, diff --git a/src/wayland/shell/legacy/mod.rs b/src/wayland/shell/legacy/mod.rs index 4c381b0..1f58b9a 100644 --- a/src/wayland/shell/legacy/mod.rs +++ b/src/wayland/shell/legacy/mod.rs @@ -305,7 +305,7 @@ where L: Into>, Impl: FnMut(ShellRequest) + 'static, { - let _log = crate::slog_or_stdlog(logger); + let _log = crate::slog_or_fallback(logger); let implementation = Rc::new(RefCell::new(implementation)); diff --git a/src/wayland/shell/xdg/mod.rs b/src/wayland/shell/xdg/mod.rs index 77c7935..e745d06 100644 --- a/src/wayland/shell/xdg/mod.rs +++ b/src/wayland/shell/xdg/mod.rs @@ -289,7 +289,7 @@ where L: Into>, Impl: FnMut(XdgRequest) + 'static, { - let log = crate::slog_or_stdlog(logger); + let log = crate::slog_or_fallback(logger); let shell_state = Arc::new(Mutex::new(ShellState { known_toplevels: Vec::new(), known_popups: Vec::new(), diff --git a/src/wayland/shm/mod.rs b/src/wayland/shm/mod.rs index 8a3aea1..444deaa 100644 --- a/src/wayland/shm/mod.rs +++ b/src/wayland/shm/mod.rs @@ -109,7 +109,7 @@ pub fn init_shm_global( where L: Into>, { - let log = crate::slog_or_stdlog(logger); + let log = crate::slog_or_fallback(logger); // always add the mandatory formats formats.push(wl_shm::Format::Argb8888); diff --git a/src/xwayland/xserver.rs b/src/xwayland/xserver.rs index 575203c..4749004 100644 --- a/src/xwayland/xserver.rs +++ b/src/xwayland/xserver.rs @@ -88,7 +88,7 @@ impl XWayland { where L: Into>, { - let log = crate::slog_or_stdlog(logger); + let log = crate::slog_or_fallback(logger); let inner = Rc::new(RefCell::new(Inner { wm, kill_source: {