Skip to content

Commit d3ec26f

Browse files
authored
✨ feat(biliass): use tracing for logging and enable tracing in yutto debug mode (#343)
1 parent bee9c8f commit d3ec26f

File tree

13 files changed

+181
-18
lines changed

13 files changed

+181
-18
lines changed

packages/biliass/rust/Cargo.lock

Lines changed: 134 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/biliass/rust/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ cached = "0.53.1"
1818
serde = "1.0.210"
1919
serde_json = "1.0.128"
2020
regex = "1.10.6"
21+
tracing = "0.1.40"
22+
tracing-subscriber = "0.3.18"
2123

2224
[build-dependencies]
2325
prost-build = "0.13.3"

packages/biliass/rust/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod comment;
22
mod convert;
33
mod error;
4+
mod logging;
45
mod proto;
56
mod python;
67
mod reader;
@@ -23,5 +24,6 @@ fn biliass_pyo3(m: &Bound<'_, PyModule>) -> PyResult<()> {
2324
m.add_function(wrap_pyfunction!(python::py_get_danmaku_meta_size, m)?)?;
2425
m.add_function(wrap_pyfunction!(python::py_xml_to_ass, m)?)?;
2526
m.add_function(wrap_pyfunction!(python::py_protobuf_to_ass, m)?)?;
27+
m.add_function(wrap_pyfunction!(python::py_enable_tracing, m)?)?;
2628
Ok(())
2729
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use tracing::Level;
2+
3+
pub fn enable_tracing() {
4+
let collector = tracing_subscriber::fmt()
5+
.with_max_level(Level::TRACE)
6+
.finish();
7+
8+
tracing::subscriber::set_global_default(collector).expect("setting tracing default failed");
9+
}

packages/biliass/rust/src/python/convert.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::{convert, reader};
2+
23
use pyo3::{
34
prelude::*,
45
pybacked::{PyBackedBytes, PyBackedStr},
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
use pyo3::prelude::*;
2+
3+
#[pyfunction(name = "enable_tracing")]
4+
pub fn py_enable_tracing() {
5+
crate::logging::enable_tracing();
6+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod convert;
2+
mod logging;
23
mod proto;
3-
44
pub use convert::{py_protobuf_to_ass, py_xml_to_ass};
5+
pub use logging::py_enable_tracing;
56
pub use proto::py_get_danmaku_meta_size;

packages/biliass/rust/src/writer/ass.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::comment::{Comment, CommentPosition};
22
use crate::reader::special::parse_special_comment;
33
use crate::writer::rows;
44
use crate::writer::utils;
5+
use tracing::warn;
56

67
pub fn write_head(
78
width: u32,
@@ -214,10 +215,10 @@ pub fn write_comment_with_animation(
214215
.into_iter()
215216
.any(|x| x.is_nan())
216217
{
217-
// eprintln!(
218-
// "Invalid rotation arguments: {:?}",
219-
// (rotate_y, rotate_z, from_x, from_y)
220-
// );
218+
warn!(
219+
"Invalid rotation arguments: {:?}",
220+
(rotate_y, rotate_z, from_x, from_y)
221+
);
221222
return "".to_owned();
222223
}
223224
let mut styles = vec![format!("\\org({}, {})", width / 2, height / 2)];
@@ -292,7 +293,7 @@ pub fn write_special_comment(comment: &Comment, width: u32, height: u32, styleid
292293
utils::get_zoom_factor(crate::reader::special::BILI_PLAYER_SIZE, (width, height));
293294
let parsed_res = parse_special_comment(&comment.comment, zoom_factor);
294295
if parsed_res.is_err() {
295-
// eprintln!("Invalid comment: {}", comment.comment);
296+
warn!("Invalid comment: {}", comment.comment);
296297
return "".to_owned();
297298
}
298299
let (

packages/biliass/rust/src/writer/utils.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use tracing::warn;
2+
13
use cached::proc_macro::cached;
24

35
fn divmod(a: f64, b: f64) -> (f64, f64) {
@@ -150,19 +152,19 @@ pub fn convert_flash_rotation(
150152
let scale_xy = if fov + trans_z != 0.0 {
151153
fov / (fov + trans_z)
152154
} else {
153-
// eprintln!(
154-
// "Rotation makes object behind the camera: trZ == {:.0}",
155-
// trans_z
156-
// );
155+
warn!(
156+
"Rotation makes object behind the camera: trZ == {:.0}",
157+
trans_z
158+
);
157159
1.
158160
};
159161
let trans_x = (trans_x - width / 2.0) * scale_xy + width / 2.0;
160162
let trans_y = (trans_y - height / 2.0) * scale_xy + height / 2.0;
161163
let (scale_xy, out_x, out_y) = if scale_xy < 0. {
162-
// eprintln!(
163-
// "Rotation makes object behind the camera: trZ == {:.0} < {:.0}",
164-
// trans_z, fov
165-
// );
164+
warn!(
165+
"Rotation makes object behind the camera: trZ == {:.0} < {:.0}",
166+
trans_z, fov
167+
);
166168
(-scale_xy, out_x + 180., out_y + 180.)
167169
} else {
168170
(scale_xy, out_x, out_y)

packages/biliass/src/biliass/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3-
from biliass._core import get_danmaku_meta_size as get_danmaku_meta_size
3+
from biliass._core import (
4+
enable_tracing as enable_tracing,
5+
get_danmaku_meta_size as get_danmaku_meta_size,
6+
)
47

58
from .biliass import (
69
Danmaku2ASS as Danmaku2ASS,

0 commit comments

Comments
 (0)