about summary refs log tree commit diff stats
path: root/crates/yt_dlp/src/logging.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-14 18:05:33 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-10-14 18:05:33 +0200
commit2c7980b773cad586af5db8ff0755f1d74d94f7d1 (patch)
tree5207aa3a69945ae7d5e5ef77ad14a50313954c25 /crates/yt_dlp/src/logging.rs
parentfeat(unreachable): Init trait (diff)
downloadyt-2c7980b773cad586af5db8ff0755f1d74d94f7d1.tar.gz
yt-2c7980b773cad586af5db8ff0755f1d74d94f7d1.zip
refactor(treewide): Conform to the clippy and rust lints
Diffstat (limited to 'crates/yt_dlp/src/logging.rs')
-rw-r--r--crates/yt_dlp/src/logging.rs16
1 files changed, 10 insertions, 6 deletions
diff --git a/crates/yt_dlp/src/logging.rs b/crates/yt_dlp/src/logging.rs
index 4039da4..385255d 100644
--- a/crates/yt_dlp/src/logging.rs
+++ b/crates/yt_dlp/src/logging.rs
@@ -12,6 +12,9 @@
 // It is licensed under the Apache 2.0 License, copyright up to 2024 by Dylan Storey
 // It was modified by Benedikt Peetz 2024
 
+// The pyo3 `pyfunction` proc-macros call unsafe functions internally, which trigger this lint.
+#![allow(unsafe_op_in_unsafe_fn)]
+
 use log::{logger, Level, MetadataBuilder, Record};
 use pyo3::{
     prelude::{PyAnyMethods, PyListMethods, PyModuleMethods},
@@ -19,6 +22,7 @@ use pyo3::{
 };
 
 /// Consume a Python `logging.LogRecord` and emit a Rust `Log` instead.
+#[allow(clippy::needless_pass_by_value)]
 #[pyfunction]
 fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> {
     let level = record.getattr("levelno")?;
@@ -37,7 +41,7 @@ fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> {
     } else {
         // Libraries (ex: tracing_subscriber::filter::Directive) expect rust-style targets like foo::bar,
         // and may not deal well with "." as a module separator:
-        let logger_name = logger_name.replace(".", "::");
+        let logger_name = logger_name.replace('.', "::");
         Some(format!("{rust_target}::{logger_name}"))
     };
 
@@ -84,10 +88,11 @@ fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> {
     Ok(())
 }
 
-/// Registers the host_log function in rust as the event handler for Python's logging logger
+/// Registers the `host_log` function in rust as the event handler for Python's logging logger
 /// This function needs to be called from within a pyo3 context as early as possible to ensure logging messages
 /// arrive to the rust consumer.
-pub fn setup_logging(py: Python, target: &str) -> PyResult<()> {
+#[allow(clippy::module_name_repetitions)]
+pub fn setup_logging(py: Python<'_>, target: &str) -> PyResult<()> {
     let logging = py.import_bound("logging")?;
 
     logging.setattr("host_log", wrap_pyfunction!(host_log, &logging)?)?;
@@ -100,15 +105,14 @@ class HostHandler(Handler):
         super().__init__(level=level)
 
     def emit(self, record):
-        host_log(record,"{}")
+        host_log(record,"{target}")
 
 oldBasicConfig = basicConfig
 def basicConfig(*pargs, **kwargs):
     if "handlers" not in kwargs:
         kwargs["handlers"] = [HostHandler()]
     return oldBasicConfig(*pargs, **kwargs)
-"#,
-            target
+"#
         )
         .as_str(),
         Some(&logging.dict()),