Skip to content

Commit 330c395

Browse files
committed
feat: configure log level
1 parent 01920ab commit 330c395

File tree

2 files changed

+54
-240
lines changed

2 files changed

+54
-240
lines changed

README.md

Lines changed: 33 additions & 239 deletions
Original file line numberDiff line numberDiff line change
@@ -219,249 +219,43 @@ This architecture ensures both interactive visualization and programmatic access
219219
- `--output`: Output file for results (JSON)
220220
- `--window-size`: Analysis window size in samples (default: 4096)
221221
- `--averages`: Number of spectra to average (default: 10)
222-
223-
## Noise Generator Utility
224-
225-
The project includes a standalone noise signal generator utility, located at `src/utility/noise_generator.rs` and available as a binary target. This tool is useful for generating synthetic white noise signals or simulated photoacoustic signals for testing and calibration of the signal processing pipeline.
226-
227-
### Usage
228-
229-
You can run the noise generator from the command line:
230-
231-
```bash
232-
cargo run --bin noise_generator [OPTIONS]
233-
```
234-
235-
### Command Line Options
236-
237-
- `--output <FILE>`: Specify the output WAV file for the generated noise (required).
238-
- `--duration <SECONDS>`: Duration of the generated noise in seconds (default: 5).
239-
- `--sample-rate <HZ>`: Sampling rate of the output file (default: 48000).
240-
- `--channels <N>`: Number of audio channels (default: 2).
241-
- `--correlated`: Set to true to use correlations between channels (default is independent)
242-
- `--correlation <VALUE>`: Correlation coefficient between channels (-1.0 to 1.0) (default: 0)
243-
- `--amplitude <VALUE>`: Amplitude of the noise signal (default: 0.3).
244-
- `--noise-type <TYPE>`: Type of noise to generate (default: "white"):
245-
- `white`: Pure Gaussian white noise
246-
- `mock`: Mock photoacoustic signal with pulses over white noise
247-
- `--pulse-frequency <HZ>`: Frequency of pulses for mock signals (default: 2000.0).
248-
- `--pulse-width <SECONDS>`: Width of each pulse in seconds (default: 0.04).
249-
- `--min-pulse-amplitude <VALUE>`: Minimum amplitude of pulses (default: 0.8).
250-
- `--max-pulse-amplitude <VALUE>`: Maximum amplitude of pulses (default: 1.0).
251-
252-
### Examples
253-
254-
```bash
255-
# Generate basic white noise
256-
cargo run --bin noise_generator -- --output white_noise.wav --duration 5 --amplitude 0.5
257-
258-
# Generate a mock photoacoustic signal
259-
cargo run --bin noise_generator -- --output mock_signal.wav --noise-type mock
260-
261-
# Generate a custom mock signal with specific parameters
262-
cargo run --bin noise_generator -- --output custom_mock.wav --noise-type mock \
263-
--pulse-frequency 1500 --pulse-width 0.05 --min-pulse-amplitude 0.7 \
264-
--max-pulse-amplitude 0.9 --amplitude 0.2 --duration 10
265-
266-
# Generate correlated stereo mock signal
267-
cargo run --bin noise_generator -- --output correlated_mock.wav --noise-type mock \
268-
--correlated --correlation 0.8
269-
```
270-
271-
### Mock Photoacoustic Signals
272-
273-
The mock signal generator creates synthetic signals that mimic real photoacoustic measurements:
274-
275-
- Base white noise represents background noise in the measurement environment
276-
- Pulsed sinusoidal signals simulate the photoacoustic response from water vapor
277-
- Random amplitude variations simulate fluctuations in absorption strength
278-
- Configurable parameters allow for testing under different conditions
279-
280-
These signals are particularly useful for:
281-
282-
- Testing and validating signal processing algorithms
283-
- Calibrating system performance
284-
- Developing and refining filtering techniques
285-
- Evaluating correlation effects in differential measurements
286-
- Benchmarking detection limits under controlled noise conditions
287-
288-
## Differential Signal Utility
289-
290-
The project includes a differential signal processing utility, located at `src/bin/differential.rs`. This tool enables you to create differential signals from WAV files in several ways:
291-
292-
1. Process a stereo WAV file to output the difference between left and right channels (L-R or R-L)
293-
2. Process two mono WAV files to output their difference (file1-file2)
294-
295-
### Usage
296-
297-
You can run the differential processor from the command line:
222+
- `--server`: Start in server mode (default: true)
223+
- `--web-port`, `-p`: Web server port (default: 8080)
224+
- `--web-address`: Web server address (default: localhost)
225+
- `--hmac-secret`: HMAC secret for JWT signing
226+
- `--config`: Path to configuration file (YAML format)
227+
- `--show-config-schema`: Output the configuration schema as JSON and exit
228+
- `--modbus-enabled`: Enable Modbus functionality
229+
- `--modbus-address`: Modbus server address
230+
- `--modbus-port`: Modbus server port
231+
- `--verbose`, `-v`: Enable verbose logging (debug level)
232+
- `--quiet`, `-q`: Disable all logging output
233+
234+
### Logging Options
235+
236+
The application provides flexible logging control through command line options:
298237

299238
```bash
300-
cargo run --bin differential [OPTIONS]
239+
# Default logging (info level)
240+
cargo run
241+
242+
# Enable verbose logging for debugging
243+
cargo run -- --verbose
244+
# or
245+
cargo run -- -v
246+
247+
# Disable all logging output
248+
cargo run -- --quiet
249+
# or
250+
cargo run -- -q
301251
```
302252

303-
### Command Line Options
304-
305-
- `--input <FILE>`: Input WAV file (stereo for channel differencing, mono for file differencing).
306-
- `--input2 <FILE>`: Second input WAV file (required for file1-minus-file2 mode).
307-
- `--output <FILE>`: Output WAV file (mono).
308-
- `--mode <MODE>`: Differential mode:
309-
- `left-minus-right` (default): Left minus Right for stereo files
310-
- `right-minus-left`: Right minus Left for stereo files
311-
- `file1-minus-file2`: First file minus second file for mono files
312-
- `--gain <VALUE>`: Gain to apply to the output signal (default: 1.0).
313-
314-
Example:
315-
316-
```bash
317-
# Process a stereo file to get L-R
318-
cargo run --bin differential -- --input stereo_file.wav --output lr_diff.wav --mode LeftMinusRleft-minus-right
319-
320-
# Subtract one mono file from another
321-
cargo run --bin differential -- --input first.wav --input2 second.wav --output diff.wav --mode file1-minus-file2 --gain 1.5
322-
```
323-
324-
This utility is particularly useful for testing the differential signal processing algorithms or preparing test files.
325-
326-
## Audio Filter Utility
253+
The logging levels are:
327254

328-
The project includes a standalone audio filter utility, located at `src/bin/filters.rs`. This tool allows for the application of different digital filters to WAV files for signal processing and analysis.
329-
330-
### Usage
331-
332-
You can run the filter processor from the command line:
333-
334-
```bash
335-
cargo run --bin filters [OPTIONS]
336-
```
337-
338-
### Command Line Options
339-
340-
- `--input`, `-i <FILE>`: Input WAV file.
341-
- `--output`, `-o <FILE>`: Output WAV file.
342-
- `--filter-type`, `-t <TYPE>`: Filter type to apply (default: bandpass):
343-
- `bandpass`: Bandpass filter around a center frequency
344-
- `lowpass`: Lowpass filter with specific cutoff
345-
- `--center-freq`, `-f <HZ>`: Center frequency in Hz for bandpass filter (default: 2000.0).
346-
- `--bandwidth`, `-b <HZ>`: Bandwidth in Hz for bandpass filter (default: 100.0).
347-
- `--cutoff-freq`, `-c <HZ>`: Cutoff frequency in Hz for lowpass filter (default: 5000.0).
348-
- `--order`, `-n <ORDER>`: Filter order for bandpass filter, must be even (default: 4).
349-
- `--channel`, `-l <NUMBER>`: Apply filter to specific channel only (default: all channels).
350-
- `--gain`, `-g <VALUE>`: Gain to apply to the output signal (default: 1.0).
351-
352-
### Examples
353-
354-
```bash
355-
# Apply a bandpass filter centered at 1000 Hz with 50 Hz bandwidth
356-
cargo run --bin filters -- -i input.wav -o output.wav -t bandpass -f 1000 -b 50
255+
- **Default (info)**: Shows general information about application operation
256+
- **Verbose (debug)**: Shows detailed debugging information for troubleshooting
257+
- **Quiet (off)**: Suppresses all log output
357258

358-
# Apply a lowpass filter with 3000 Hz cutoff
359-
cargo run --bin filters -- -i input.wav -o output.wav -t lowpass -c 3000
259+
Note: If both `--verbose` and `--quiet` are specified, `--quiet` takes precedence and disables all logging.
360260

361-
# Filter only the left channel of a stereo file
362-
cargo run --bin filters -- -i stereo.wav -o filtered.wav -l 0
363-
364-
# Use a higher-order filter for sharper cutoff
365-
cargo run --bin filters -- -i input.wav -o output.wav -n 8 -f 2000 -b 200
366-
```
367-
368-
This utility is useful for isolating specific frequency components in your audio signals or removing unwanted noise before analysis.
369-
370-
## Continuous Integration
371-
372-
This project uses GitHub Actions for continuous integration. The CI pipeline automatically builds and tests the code on multiple platforms:
373-
374-
- Windows (x86_64)
375-
- Ubuntu Linux (x86_64 and ARM64)
376-
- macOS (x86_64 and ARM64)
377-
378-
The CI workflow includes:
379-
380-
- Building the project for all target platforms
381-
- Running tests
382-
- Special handling for tests that require specific timeouts (like introspection tests)
383-
- Code quality checks (formatting and linting)
384-
385-
You can see the workflow status in the GitHub repository under the Actions tab.
386-
387-
## Modbus Client Utility
388-
389-
The project includes a Modbus client utility located at `src/bin/modbus_client.rs`. This tool allows you to interact with the Modbus TCP server component of the photoacoustic analyzer, reading sensor values and configuration parameters via the Modbus protocol.
390-
391-
### Usage
392-
393-
You can run the Modbus client from the command line:
394-
395-
```bash
396-
cargo run --bin modbus_client [OPTIONS]
397-
```
398-
399-
### Command Line Options
400-
401-
- `--address <IP>`: The IP address of the Modbus server (default: 127.0.0.1)
402-
- `--port <PORT>`: The port number of the Modbus server (default: 502)
403-
- `--input-register <ADDRESS>`: Starting input register address to read from (default: 0)
404-
- `--quantity <NUMBER>`: Number of registers to read (default: 6)
405-
406-
### Example Usage
407-
408-
```bash
409-
# Read the default registers from a local Modbus server
410-
cargo run --bin modbus_client
411-
412-
# Connect to a remote server on a non-standard port
413-
cargo run --bin modbus_client -- --address 192.168.1.100 --port 1502
414-
415-
# Read a specific range of registers
416-
cargo run --bin modbus_client -- --input-register 2 --quantity 3
417-
```
418-
419-
### Understanding Register Values
420-
421-
The raw register values may need interpretation according to the Modbus server's register map:
422-
423-
- Register 0: Resonance frequency (Hz × 10, divide by 10.0 for actual value)
424-
- Register 1: Signal amplitude (× 1000, divide by 1000.0 for actual value)
425-
- Register 2: Water vapor concentration (ppm × 10, divide by 10.0 for actual value)
426-
- Registers 3-4: Timestamp as low and high words of a 32-bit UNIX timestamp
427-
- Register 5: Status code (0=normal, 1=warning, 2=error)
428-
429-
For more comprehensive interaction with the Modbus server, refer to the example at `examples/modbus_client.rs`.
430-
431-
## Utility Functions
432-
433-
### Certificate Utilities
434-
435-
The project includes a utility module for generating self-signed SSL certificates at `src/utility/certificate_utilities.rs`. This can be used programmatically:
436-
437-
```rust
438-
use rust_photoacoustic::utility::certificate_utilities;
439-
440-
// Generate a self-signed certificate
441-
certificate_utilities::create_self_signed_cert(
442-
365, // Valid for 365 days
443-
"path/to/cert.pem", // Certificate output path
444-
"path/to/cert.key", // Private key output path
445-
"localhost", // Common name for the certificate
446-
None, // Optional key length (default: 2048)
447-
Some(vec![ // Optional subject alternative names
448-
"localhost".to_string(),
449-
"127.0.0.1".to_string(),
450-
"::1".to_string()
451-
])
452-
)?;
453-
```
454-
455-
This utility is used by the build process to automatically generate development certificates, but can also be used in your own code when needed.
456-
457-
### Running Tests Locally
458-
459-
To run the tests locally:
460-
461-
```bash
462-
# Run all tests
463-
cargo test
464-
465-
# Run a specific test with output displayed
466-
cargo test --test introspection_test -- --nocapture
467-
```
261+
You can also control logging using the `RUST_LOG` environment variable, which will be respected in addition to these command line options.

src/main.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,32 @@ pub struct Args {
8787
/// Modbus server port
8888
#[arg(long)]
8989
modbus_port: Option<u16>,
90+
91+
/// Enable verbose logging (debug level)
92+
#[arg(short = 'v', long = "verbose")]
93+
verbose: bool,
94+
95+
/// Disable all logging output
96+
#[arg(short = 'q', long = "quiet")]
97+
quiet: bool,
9098
}
9199

92100
#[rocket::main]
93101
async fn main() -> Result<()> {
94-
env_logger::init();
102+
// Initialize logger with appropriate level based on verbose and quiet flags
95103
let args = Args::parse();
104+
105+
let log_level = if args.quiet {
106+
log::LevelFilter::Off
107+
} else if args.verbose {
108+
log::LevelFilter::Debug
109+
} else {
110+
log::LevelFilter::Info
111+
};
112+
113+
env_logger::Builder::from_default_env()
114+
.filter_level(log_level)
115+
.init();
96116

97117
// Check if --show-config-schema flag is set
98118
if args.show_config_schema {

0 commit comments

Comments
 (0)