Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/dsf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
import sys
import os

from dsf_cpp import __version__, LogLevel, get_log_level, set_log_level, mobility, mdt
from dsf_cpp import (

Check warning

Code scanning / Prospector (reported by Codacy)

Unable to import 'dsf_cpp' (import-error) Warning

Unable to import 'dsf_cpp' (import-error)

Check warning

Code scanning / Prospector (reported by Codacy)

'dsf_cpp.version' imported but unused (F401) Warning

'dsf_cpp.__version__' imported but unused (F401)
__version__,
LogLevel,
get_log_level,
set_log_level,
log_to_file,
mobility,
mdt,
)

from .python.cartography import (
get_cartography,
Expand Down
13 changes: 5 additions & 8 deletions src/dsf/base/Dynamics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
class Dynamics {
private:
network_t m_graph;
std::string m_name;
std::time_t m_timeInit, m_timeStep;
std::string m_name = "unnamed simulation";
std::time_t m_timeInit = 0;
std::time_t m_timeStep = 0;

protected:
tbb::task_arena m_taskArena;
Expand Down Expand Up @@ -120,14 +121,10 @@

template <typename network_t>
Dynamics<network_t>::Dynamics(network_t& graph, std::optional<unsigned int> seed)
: m_graph{std::move(graph)},
m_name{"unnamed simulation"},
m_timeInit{0},
m_timeStep{0},
m_generator{std::random_device{}()} {
: m_graph{std::move(graph)}, m_generator{std::random_device{}()} {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
if (seed.has_value()) {
m_generator.seed(*seed);
}
m_taskArena.initialize();
}
}; // namespace dsf
}; // namespace dsf
6 changes: 6 additions & 0 deletions src/dsf/bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ PYBIND11_MODULE(dsf_cpp, m) {
m.doc() = "Python bindings for the DSF library";
m.attr("__version__") = dsf::version();

// Bind the dsf::log_to_file function
m.def("log_to_file",
&dsf::log_to_file,
pybind11::arg("path"),
"Set up logging to a specified file");

// Create mobility submodule
auto mobility = m.def_submodule("mobility",
"Bindings for mobility-related classes and functions, "
Expand Down
15 changes: 15 additions & 0 deletions src/dsf/dsf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <cstdint>
#include <format>

#include <spdlog/spdlog.h>
#include <spdlog/sinks/basic_file_sink.h>

static constexpr uint8_t DSF_VERSION_MAJOR = 4;
static constexpr uint8_t DSF_VERSION_MINOR = 7;
static constexpr uint8_t DSF_VERSION_PATCH = 8;
Expand All @@ -15,6 +18,18 @@ namespace dsf {
/// @brief Returns the version of the DSF library
/// @return The version of the DSF library
auto const& version() { return DSF_VERSION; };

/// @brief Set up logging to a specified file
/// @param path The path to the log file
void log_to_file(std::string const& path) {
try {
spdlog::info("Logging to file: {}", path);
auto file_logger = spdlog::basic_logger_mt("dsf_file_logger", path);
spdlog::set_default_logger(file_logger);
} catch (const spdlog::spdlog_ex& ex) {
spdlog::error("Log initialization failed: {}", ex.what());
}
};
} // namespace dsf

#include "base/AdjacencyMatrix.hpp"
Expand Down
Loading