13#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO
14#include <spdlog/spdlog.h>
16#if defined(SPDLOG_VER_MAJOR) && SPDLOG_VER_MAJOR >= 1
17#include <spdlog/sinks/basic_file_sink.h>
19#include <spdlog/sinks/file_sinks.h>
22#include <spdlog/fmt/ostr.h>
24#include <dpsim-models/Attribute.h>
25#include <dpsim-models/Definitions.h>
26#include <dpsim-models/MathUtils.h>
33 using Level = spdlog::level::level_enum;
34 using Log = std::shared_ptr<spdlog::logger>;
37 static Log create(
const std::string &name, Level filelevel = Level::info,
38 Level clilevel = Level::off);
44 static String prefix();
45 static String logDir();
50 static Log get(
const std::string &name, Level filelevel = Level::info,
51 Level clilevel = Level::off);
53 static void setLogLevel(std::shared_ptr<spdlog::logger> logger,
56 static void setLogPattern(std::shared_ptr<spdlog::logger> logger,
60 static String matrixToString(
const Matrix &mat);
61 static String matrixCompToString(
const MatrixComp &mat);
62 static String sparseMatrixToString(
const SparseMatrix &mat);
63 static String sparseMatrixCompToString(
const SparseMatrixComp &mat);
64 static String phasorMatrixToString(
const MatrixComp &mat);
65 static String phasorToString(
const Complex &num);
66 static String complexToString(
const Complex &num);
67 static String realToString(
const Real &num);
69 static String getCSVColumnNames(std::vector<String> names);
70 static String getCSVLineFromData(Real time, Real data);
71 static String getCSVLineFromData(Real time,
const Matrix &data);
72 static String getCSVLineFromData(Real time,
const MatrixComp &data);
76#if FMT_VERSION >= 90000
78class fmt::formatter<CPS::String> :
public fmt::ostream_formatter {};
80class fmt::formatter<CPS::Complex> :
public fmt::ostream_formatter {};
82class fmt::formatter<CPS::Vector> :
public fmt::ostream_formatter {};
84class fmt::formatter<CPS::VectorComp> :
public fmt::ostream_formatter {};
86class fmt::formatter<CPS::SparseMatrix> :
public fmt::ostream_formatter {};
88class fmt::formatter<CPS::SparseMatrixRow> :
public fmt::ostream_formatter {};
90class fmt::formatter<CPS::SparseMatrixComp> :
public fmt::ostream_formatter {};
92class fmt::formatter<CPS::SparseMatrixCompRow> :
public fmt::ostream_formatter {
95class fmt::formatter<CPS::Matrix> :
public fmt::ostream_formatter {};
97class fmt::formatter<CPS::MatrixComp> :
public fmt::ostream_formatter {};
99class fmt::formatter<CPS::MatrixInt> :
public fmt::ostream_formatter {};
101class fmt::formatter<CPS::MatrixRow> :
public fmt::ostream_formatter {};
103class fmt::formatter<CPS::LUFactorized> :
public fmt::ostream_formatter {};
105class fmt::formatter<CPS::LUFactorizedSparse> :
public fmt::ostream_formatter {
107template <
typename VarType>
108class fmt::formatter<CPS::MatrixVar<VarType>> :
public fmt::ostream_formatter {
110template <
int rows,
int cols>
111class fmt::formatter<CPS::MatrixFixedSize<rows, cols>>
112 :
public fmt::ostream_formatter {};
113template <
int rows,
int cols>
114class fmt::formatter<CPS::MatrixFixedSizeComp<rows, cols>>
115 :
public fmt::ostream_formatter {};
118class fmt::formatter<Eigen::Block<CPS::Matrix>>
119 :
public fmt::ostream_formatter {};
121class fmt::formatter<Eigen::Block<CPS::MatrixComp>>
122 :
public fmt::ostream_formatter {};
125template <
typename T>
struct formatter<CPS::Attribute<T>> {
126 template <
typename ParseContext>
constexpr auto parse(ParseContext &ctx) {
130 template <
typename FormatContext>
131 auto format(
const CPS::Attribute<T> &attr, FormatContext &ctx)
const {
132 auto &nc =
const_cast<CPS::Attribute<T> &
>(attr);
133 return fmt::format_to(ctx.out(),
"{}", nc.get());
137template <
typename T>
struct formatter<std::shared_ptr<CPS::Attribute<T>>> {
138 template <
typename ParseContext>
constexpr auto parse(ParseContext &ctx) {
142 template <
typename FormatContext>
143 auto format(
const std::shared_ptr<CPS::Attribute<T>> &p,
144 FormatContext &ctx)
const {
146 return fmt::format_to(ctx.out(),
"<null>");
147 auto &nc =
const_cast<CPS::Attribute<T> &
>(*p);
148 return fmt::format_to(ctx.out(),
"{}", nc.get());
static void setLogDir(String path)
Set env variable CPS_LOG_DIR and overwrite.