12#include <spdlog/sinks/null_sink.h>
13#include <spdlog/sinks/stdout_color_sinks.h>
22 logger->set_level(level);
26 std::string pattern) {
27 logger->set_pattern(pattern);
33 ss << std::scientific <<
"\n" << mat;
39 ss << std::scientific <<
"\n" << mat;
65 ss << std::defaultfloat << num.real() <<
"+j" << num.imag();
71 ss << std::defaultfloat << num;
76 char *p = getenv(
"CPS_LOG_PREFIX");
82 char *p = getenv(
"CPS_LOG_DIR");
84 return p ? p :
"logs";
90 setenv(
"CPS_LOG_DIR", path.c_str(), 1);
92 String var =
"CPS_LOG_DIR=" + path;
99 ss << std::right << std::setw(14) <<
"time";
100 for (
auto name : names) {
101 ss <<
", " << std::right << std::setw(13) << name;
109 std::stringstream ss;
110 ss << std::scientific << std::right << std::setw(14) << time;
111 ss <<
", " << std::right << std::setw(13) <<
data;
118 std::stringstream ss;
119 ss << std::scientific << std::right << std::setw(14) << time;
120 for (
Int i = 0; i <
data.rows(); i++) {
121 ss <<
", " << std::right << std::setw(13) <<
data(i, 0);
129 std::stringstream ss;
130 ss << std::scientific << std::right << std::setw(14) << time;
131 for (
Int i = 0; i <
data.rows(); i++) {
132 ss <<
", " << std::right << std::setw(13) <<
data(i, 0);
144 logger = create(name, filelevel, clilevel);
150Logger::Log Logger::create(
const std::string &name, Level filelevel,
154 std::vector<spdlog::sink_ptr> sinks;
158 fs::path p = filename;
159 if (p.has_parent_path() && !fs::exists(p.parent_path()))
160 fs::create_directories(p.parent_path());
162 if (clilevel != Logger::Level::off) {
163 auto console_sink = std::make_shared<spdlog::sinks::stderr_color_sink_mt>();
164 console_sink->set_level(clilevel);
165 console_sink->set_pattern(
167 sinks.push_back(console_sink);
170 if (filelevel != Logger::Level::off) {
172 std::make_shared<spdlog::sinks::basic_file_sink_mt>(filename,
true);
173 file_sink->set_level(filelevel);
174 file_sink->set_pattern(
prefix() +
"[%L] %v");
175 sinks.push_back(file_sink);
178 if (filelevel == Logger::Level::off && clilevel == Logger::Level::off) {
179 ret = spdlog::create<spdlog::sinks::null_sink_st>(name);
181 ret = std::make_shared<spdlog::logger>(name, begin(sinks), end(sinks));
spdlog::level::level_enum Level
std::shared_ptr< spdlog::logger > Log
static String matrixCompToString(const MatrixComp &mat)
static String phasorMatrixToString(const MatrixComp &mat)
static String sparseMatrixToString(const SparseMatrix &mat)
static void setLogDir(String path)
Set env variable CPS_LOG_DIR and overwrite.
static void setLogPattern(std::shared_ptr< spdlog::logger > logger, std::string pattern)
static Log get(const std::string &name, Level filelevel=Level::info, Level clilevel=Level::off)
static String complexToString(const Complex &num)
static String matrixToString(const Matrix &mat)
static void setLogLevel(std::shared_ptr< spdlog::logger > logger, Logger::Level level)
static String realToString(const Real &num)
static String getCSVLineFromData(Real time, Real data)
static String getCSVColumnNames(std::vector< String > names)
static String sparseMatrixCompToString(const SparseMatrixComp &mat)
static String phasorToString(const Complex &num)
static Real phaseDeg(Complex value)
static Real phase(Complex value)
static Real abs(Complex value)
struct dps_magma_data data
Eigen::SparseMatrix< Real, Eigen::ColMajor > SparseMatrix
Sparse matrix for real numbers.
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > Matrix
Dense matrix for real numbers.
Eigen::SparseMatrix< Complex, Eigen::ColMajor > SparseMatrixComp
Sparse matrix for complex numbers.
std::complex< Real > Complex
Eigen::Matrix< Complex, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > MatrixComp
Dense matrix for complex numbers.