Skip to content

Commit c51e7c6

Browse files
committed
Migrate from logging to tracing #61
1 parent abc797b commit c51e7c6

15 files changed

+87
-43
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ readme = "README.md"
1414
[features]
1515
# Uses gp_log_add_func instead of gp_context_set_log_func for logging (not supported on many systems)
1616
extended_logs = []
17-
test = ["libgphoto2_sys/test"]
17+
test = ["libgphoto2_sys/test", "dep:tracing-subscriber"]
1818
serde = ["dep:serde"]
1919

2020
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@@ -25,10 +25,10 @@ members = ["libgphoto2-sys", "gphoto2-test"]
2525
[dependencies]
2626
libgphoto2_sys = { path = "libgphoto2-sys", version = "1.2" }
2727
libc = "0.2"
28-
log = "0.4"
2928
crossbeam-channel = "0.5.6"
3029
serde = { version = "1", optional = true, features = ["derive"] }
30+
tracing = "0.1.37"
31+
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
3132

3233
[dev-dependencies]
33-
env_logger = "0.9.1"
3434
insta = "1.20.0"

examples/bulb_capture.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
//! There are also actions for capturing movies, changing liveview, etc.
44
//! This example will only work for Nikon DSLR cameras.
55
6+
mod logging;
7+
68
use gphoto2::widget::{RadioWidget, ToggleWidget};
79
use gphoto2::{camera::CameraEvent, Context, Result};
810
use std::{thread::sleep, time::Duration};
911

1012
fn main() -> Result<()> {
11-
env_logger::init();
13+
logging::setup();
1214

1315
let camera = Context::new()?.autodetect_camera().wait()?;
1416

examples/camera_info.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
mod logging;
2+
13
use gphoto2::{Context, Result};
24

35
fn main() -> Result<()> {
4-
env_logger::init();
6+
logging::setup();
57

68
let camera = Context::new()?.autodetect_camera().wait()?;
79

examples/camera_ls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
mod logging;
2+
13
use gphoto2::{filesys::CameraFS, Context, Result};
24
use std::collections::HashMap;
35

@@ -24,7 +26,7 @@ fn list_folder_recursive(fs: &CameraFS, folder_name: &str) -> Result<FolderConte
2426
}
2527

2628
fn main() -> Result<()> {
27-
env_logger::init();
29+
logging::setup();
2830

2931
let camera = Context::new()?.autodetect_camera().wait()?;
3032
let fs = camera.fs();

examples/camera_progress.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![allow(dead_code)] // This is just an example
22

3+
mod logging;
4+
35
use gphoto2::{Context, Result};
46
use std::{collections::HashMap, path::Path};
57

@@ -60,7 +62,7 @@ impl ContextProgress {
6062
fn main() -> Result<()> {
6163
let mut context = Context::new()?;
6264

63-
env_logger::init();
65+
logging::setup();
6466

6567
context.set_progress_handlers(ProgressManager::new());
6668

examples/capture.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
mod logging;
2+
13
use gphoto2::{Context, Result};
24
use std::path::Path;
35

46
fn main() -> Result<()> {
5-
env_logger::init();
7+
logging::setup();
68

79
let camera = Context::new()?.autodetect_camera().wait()?;
810

examples/capture_preview.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Capture a preview and save it to /tmp/preview_image
22
3+
mod logging;
4+
35
use gphoto2::{Context, Result};
46
use std::{fs, io::Write};
57

68
fn main() -> Result<()> {
7-
env_logger::init();
9+
logging::setup();
810

911
let context = Context::new()?;
1012
let camera = context.autodetect_camera().wait()?;

examples/drop_camera.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Test if the camera can be dropped while there are is still eg. a widget of that camera present
22
3+
mod logging;
4+
35
use gphoto2::{Context, Result};
46

57
fn main() -> Result<()> {
6-
env_logger::init();
8+
logging::setup();
79

810
let camera = Context::new()?.autodetect_camera().wait()?;
911

examples/list_cameras.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
mod logging;
2+
13
use gphoto2::list::CameraDescriptor;
24
use gphoto2::{Context, Result};
35

46
fn main() -> Result<()> {
5-
env_logger::init();
7+
logging::setup();
68

79
let context = Context::new()?;
810

examples/list_config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//! Recursively list all configuration
22
//! Warning: Output might be very large
33
4+
mod logging;
5+
46
use gphoto2::{Context, Result};
57

68
fn main() -> Result<()> {
7-
env_logger::init();
9+
logging::setup();
810

911
let camera = Context::new()?.autodetect_camera().wait()?;
1012
println!("{:#?}", camera.config().wait()?);

0 commit comments

Comments
 (0)