Skip to content

Commit

Permalink
➕ Make log crate optional
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurlm committed Nov 18, 2023
1 parent acbcbf2 commit 2014659
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:

- name: Build
run: cargo build --verbose
- name: Run tests no default features
run: cargo test --no-default-features
- name: Run tests
run: cargo test

Expand Down
5 changes: 3 additions & 2 deletions quickfix/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ version = "0.1.0"
edition = "2021"

[dependencies]
log = "0.4.20"
quickfix-ffi = { path = "../quickfix-ffi" }
thiserror = "1.0.50"
log = { version = "0.4.20", optional = true }

[dev-dependencies]
colored = "2.0.4"

[features]
default = []
default = ["log"]
print-ex = ["quickfix-ffi/print-ex"]
log = ["dep:log"]
5 changes: 4 additions & 1 deletion quickfix/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use error::QuickFixError;
pub use file_store_factory::FileStoreFactory;
pub use group::Group;
pub use header::Header;
pub use log_factory::{LogCallback, LogFactory, RustLogger, StdLogger};
pub use log_factory::{LogCallback, LogFactory, StdLogger};
pub use message::Message;
pub use session::send_to_target;
pub use session_id::SessionId;
Expand All @@ -30,6 +30,9 @@ pub use socket_acceptor::SocketAcceptor;
pub use socket_initiator::SocketInitiator;
pub use trailer::Trailer;

#[cfg(feature = "log")]
pub use log_factory::RustLogger;

pub trait ConnectionHandler {
fn start(&mut self) -> Result<(), QuickFixError>;
fn block(&mut self) -> Result<(), QuickFixError>;
Expand Down
2 changes: 2 additions & 0 deletions quickfix/src/log_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ impl LogCallback for StdLogger {
}
}

#[cfg(feature = "log")]
pub struct RustLogger;

#[cfg(feature = "log")]
impl LogCallback for RustLogger {
fn on_incoming(&self, session_id: Option<&SessionId>, msg: &str) {
log::info!("FIX: Incoming: {session_id:?}: {msg}");
Expand Down
15 changes: 10 additions & 5 deletions quickfix/tests/test_lifecycle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use quickfix::{
FileStoreFactory, LogFactory, QuickFixError, RustLogger, SessionSettings, StdLogger,
};
use quickfix::{FileStoreFactory, LogFactory, QuickFixError, SessionSettings, StdLogger};

#[test]
fn test_session_settings() {
Expand All @@ -13,12 +11,19 @@ fn test_session_settings() {
}

#[test]
fn test_file_log_factory() {
let _file_log_factory = LogFactory::try_new(&RustLogger).unwrap();
fn test_log_factory() {
let _file_log_factory = LogFactory::try_new(&StdLogger::Stdout).unwrap();
let _file_log_factory = LogFactory::try_new(&StdLogger::Stderr).unwrap();
}

#[test]
#[cfg(feature = "log")]
fn test_extra_log_factory() {
use quickfix::RustLogger;

let _file_log_factory = LogFactory::try_new(&RustLogger).unwrap();
}

#[test]
fn test_file_store_factory() {
let settings = SessionSettings::try_from_path("../example/settings.ini").unwrap();
Expand Down

0 comments on commit 2014659

Please sign in to comment.