Skip to content

Commit

Permalink
Expose function to enable debug logging
Browse files Browse the repository at this point in the history
Experimental function to enable CRT logs for debugging purposes.
Please do NOT use this method unless otherwise instructed.
  • Loading branch information
dnnanuti committed Jan 18, 2024
1 parent 29db5c9 commit 150f0cd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import copyreg

from ._logger_patch import TRACE as LOG_TRACE
from ._logger_patch import _install_trace_logging
from ._logger_patch import _install_trace_logging, _enable_debug_logging
from ._mountpoint_s3_client import S3Exception, __version__

_install_trace_logging()
Expand All @@ -16,4 +16,4 @@ def _s3exception_reduce(exc: S3Exception):

copyreg.pickle(S3Exception, _s3exception_reduce)

__all__ = ["LOG_TRACE", "S3Exception", "__version__"]
__all__ = ["LOG_TRACE", "S3Exception", "__version__", "_enable_debug_logging"]
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
# // SPDX-License-Identifier: BSD

import logging
import atexit

from ._mountpoint_s3_client import _enable_crt_logging, _disable_logging

TRACE = 5


def _install_trace_logging():
logging.addLevelName(TRACE, "TRACE")


# Experimental method for enabling verbose logging.
# Please do NOT use unless otherwise instructed.
def _enable_debug_logging():
atexit.register(_disable_logging)
_enable_crt_logging()
21 changes: 21 additions & 0 deletions s3torchconnectorclient/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

use log::LevelFilter;
use mountpoint_s3_crt::common::rust_log_adapter::RustLogAdapter;
use pyo3::prelude::*;
use pyo3_log::Logger;

Expand All @@ -27,6 +28,24 @@ mod put_object_stream;
mod python_structs;
mod build_info;


/// Experimental method to enable CRT logs for debugging purposes.
/// Please do NOT call this method unless otherwise instructed.
#[pyfunction]
#[pyo3(name = "_enable_crt_logging")]
fn _enable_crt_logging() {
let _ = RustLogAdapter::try_init().map_err(python_exception);
}


/// Experimental method to prevent deadlocks when enabling verbose CRT logging:
/// https://docs.rs/pyo3-log/latest/pyo3_log/#interaction-with-python-gil
#[pyfunction]
#[pyo3(name = "_disable_logging")]
fn _disable_logging() {
Logger::default().reset_handle();
}

#[pymodule]
#[pyo3(name = "_mountpoint_s3_client")]
fn make_lib(py: Python, mountpoint_s3_client: &PyModule) -> PyResult<()> {
Expand All @@ -49,5 +68,7 @@ fn make_lib(py: Python, mountpoint_s3_client: &PyModule) -> PyResult<()> {
mountpoint_s3_client.add_class::<PyRestoreStatus>()?;
mountpoint_s3_client.add("S3Exception", py.get_type::<S3Exception>())?;
mountpoint_s3_client.add("__version__", build_info::FULL_VERSION)?;
mountpoint_s3_client.add_function(wrap_pyfunction!(_enable_crt_logging, mountpoint_s3_client)?)?;
mountpoint_s3_client.add_function(wrap_pyfunction!(_disable_logging, mountpoint_s3_client)?)?;
Ok(())
}

0 comments on commit 150f0cd

Please sign in to comment.