aboutsummaryrefslogtreecommitdiffstats
path: root/crates/yt_dlp/src/logging.rs
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-16 14:16:39 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-11-16 14:16:39 +0100
commitb17d7fe27a68c0ea93fb0d6e5b81fe3c166dcee0 (patch)
tree855f6d1f96908ba210043cd0c069c2aa8941adae /crates/yt_dlp/src/logging.rs
parentfix(yt/select/add): Avoid crash on adding a video (diff)
downloadyt-b17d7fe27a68c0ea93fb0d6e5b81fe3c166dcee0.zip
build(treewide): Update dependencies
Diffstat (limited to 'crates/yt_dlp/src/logging.rs')
-rw-r--r--crates/yt_dlp/src/logging.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/crates/yt_dlp/src/logging.rs b/crates/yt_dlp/src/logging.rs
index 385255d..670fc1c 100644
--- a/crates/yt_dlp/src/logging.rs
+++ b/crates/yt_dlp/src/logging.rs
@@ -15,6 +15,8 @@
// The pyo3 `pyfunction` proc-macros call unsafe functions internally, which trigger this lint.
#![allow(unsafe_op_in_unsafe_fn)]
+use std::ffi::CString;
+
use log::{logger, Level, MetadataBuilder, Record};
use pyo3::{
prelude::{PyAnyMethods, PyListMethods, PyModuleMethods},
@@ -91,14 +93,17 @@ fn host_log(record: Bound<'_, PyAny>, rust_target: &str) -> PyResult<()> {
/// 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.
+///
+/// # Panics
+/// Only if internal assertions fail.
#[allow(clippy::module_name_repetitions)]
pub fn setup_logging(py: Python<'_>, target: &str) -> PyResult<()> {
- let logging = py.import_bound("logging")?;
+ let logging = py.import("logging")?;
logging.setattr("host_log", wrap_pyfunction!(host_log, &logging)?)?;
- py.run_bound(
- format!(
+ py.run(
+ CString::new(format!(
r#"
class HostHandler(Handler):
def __init__(self, level=0):
@@ -113,8 +118,9 @@ def basicConfig(*pargs, **kwargs):
kwargs["handlers"] = [HostHandler()]
return oldBasicConfig(*pargs, **kwargs)
"#
- )
- .as_str(),
+ ))
+ .expect("This is hardcoded")
+ .as_c_str(),
Some(&logging.dict()),
None,
)?;