diff --git a/fastdeploy/fastdeploy_model.cc b/fastdeploy/fastdeploy_model.cc index bfe1c800a..cd21720e5 100644 --- a/fastdeploy/fastdeploy_model.cc +++ b/fastdeploy/fastdeploy_model.cc @@ -166,7 +166,7 @@ std::map FastDeployModel::PrintStatisInfoOfRuntime() { std::map statis_info_of_runtime_dict; if (time_of_runtime_.size() < 10) { - FDWARNING << "PrintStatisInfoOfRuntime require the runtime ran 10 times at " + std::cout << "[FastDeploy] [WARNING] PrintStatisInfoOfRuntime require the runtime ran 10 times at " "least, but now you only ran " << time_of_runtime_.size() << " times." << std::endl; } diff --git a/fastdeploy/fastdeploy_model.h b/fastdeploy/fastdeploy_model.h index 57d3a754e..0783546dd 100644 --- a/fastdeploy/fastdeploy_model.h +++ b/fastdeploy/fastdeploy_model.h @@ -75,7 +75,7 @@ class FASTDEPLOY_DECL FastDeployModel { #define TIMERECORD_END(id, prefix) \ if (DebugEnabled()) { \ tc_##id.End(); \ - FDLogger() << __FILE__ << "(" << __LINE__ << "):" << __FUNCTION__ << " " \ + FDINFO << __FILE__ << "(" << __LINE__ << "):" << __FUNCTION__ << " " \ << prefix << " duration = " << tc_##id.Duration() << "s." \ << std::endl; \ } diff --git a/fastdeploy/fastdeploy_runtime.cc b/fastdeploy/fastdeploy_runtime.cc index 3c119f7ab..c74fdb0b2 100644 --- a/fastdeploy/fastdeploy_runtime.cc +++ b/fastdeploy/fastdeploy_runtime.cc @@ -114,11 +114,11 @@ bool CheckModelFormat(const std::string& model_file, Frontend GuessModelFormat(const std::string& model_file) { if (model_file.size() > 8 && model_file.substr(model_file.size() - 8, 8) == ".pdmodel") { - FDLogger() << "Model Format: PaddlePaddle." << std::endl; + FDINFO << "Model Format: PaddlePaddle." << std::endl; return Frontend::PADDLE; } else if (model_file.size() > 5 && model_file.substr(model_file.size() - 5, 5) == ".onnx") { - FDLogger() << "Model Format: ONNX." << std::endl; + FDINFO << "Model Format: ONNX." << std::endl; return Frontend::ONNX; } diff --git a/fastdeploy/pybind/main.cc.in b/fastdeploy/pybind/main.cc.in index 5aaac049c..417a59761 100644 --- a/fastdeploy/pybind/main.cc.in +++ b/fastdeploy/pybind/main.cc.in @@ -137,6 +137,10 @@ PYBIND11_MODULE(@PY_LIBRARY_NAME@, m) { "Make programer easier to deploy deeplearning model, save time to save " "the world!"; + pybind11::class_(m, "FDLogger") + .def_readwrite_static("disable_info", &FDLogger::disable_info) + .def_readwrite_static("disable_warning", &FDLogger::disable_warning); + BindRuntime(m); BindFDModel(m); #ifdef ENABLE_VISION diff --git a/fastdeploy/utils/perf.h b/fastdeploy/utils/perf.h index 9f451c3a9..84c7ba8f8 100644 --- a/fastdeploy/utils/perf.h +++ b/fastdeploy/utils/perf.h @@ -38,7 +38,7 @@ class FASTDEPLOY_DECL TimeCounter { if (!print_out) { return; } - FDLogger() << prefix << " duration = " << Duration() << "s." << std::endl; + std::cout << prefix << " duration = " << Duration() << "s." << std::endl; } private: diff --git a/fastdeploy/utils/utils.cc b/fastdeploy/utils/utils.cc index 6e76c7888..7ea536e20 100644 --- a/fastdeploy/utils/utils.cc +++ b/fastdeploy/utils/utils.cc @@ -16,14 +16,17 @@ namespace fastdeploy { -FDLogger::FDLogger(bool verbose, const std::string& prefix) { - verbose_ = verbose; +bool FDLogger::disable_info = false; +bool FDLogger::disable_warning = false; + +FDLogger::FDLogger(int level, const std::string& prefix) { line_ = ""; + level_ = level; prefix_ = prefix; } FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) { - if (!verbose_) { + if (!verbose()) { return *this; } std::cout << prefix_ << " " << line_ << std::endl; diff --git a/fastdeploy/utils/utils.h b/fastdeploy/utils/utils.h index 2c7269763..f9ebc97e2 100644 --- a/fastdeploy/utils/utils.h +++ b/fastdeploy/utils/utils.h @@ -37,16 +37,31 @@ namespace fastdeploy { class FASTDEPLOY_DECL FDLogger { public: + static bool disable_info; + static bool disable_warning; FDLogger() { line_ = ""; prefix_ = "[FastDeploy]"; - verbose_ = true; + level_ = 0; + } + // 0: INFO + // 1: WARNING + // 2: ERROR + explicit FDLogger(int level = 0, const std::string& prefix = "[FastDeploy]"); + + bool verbose() { + if (disable_info && level_ == 0) { + return false; + } + if (disable_warning && level_ == 1) { + return false; + } + return true; } - explicit FDLogger(bool verbose, const std::string& prefix = "[FastDeploy]"); template FDLogger& operator<<(const T& val) { - if (!verbose_) { + if (!verbose()) { return *this; } std::stringstream ss; @@ -56,7 +71,7 @@ class FASTDEPLOY_DECL FDLogger { } FDLogger& operator<<(std::ostream& (*os)(std::ostream&)); ~FDLogger() { - if (!verbose_ && line_ != "") { + if (!verbose() && line_ != "") { std::cout << line_ << std::endl; } } @@ -64,7 +79,7 @@ class FASTDEPLOY_DECL FDLogger { private: std::string line_; std::string prefix_; - bool verbose_ = true; + int level_ = 0; }; FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file, @@ -75,15 +90,15 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file, #endif #define FDERROR \ - FDLogger(true, "[ERROR]") << __REL_FILE__ << "(" << __LINE__ \ + FDLogger(2, "[ERROR]") << __REL_FILE__ << "(" << __LINE__ \ << ")::" << __FUNCTION__ << "\t" #define FDWARNING \ - FDLogger(true, "[WARNING]") << __REL_FILE__ << "(" << __LINE__ \ + FDLogger(1, "[WARNING]") << __REL_FILE__ << "(" << __LINE__ \ << ")::" << __FUNCTION__ << "\t" #define FDINFO \ - FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ + FDLogger(0, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ << ")::" << __FUNCTION__ << "\t" #define FDASSERT(condition, format, ...) \ diff --git a/python/fastdeploy/__init__.py b/python/fastdeploy/__init__.py index b27c6e5c8..baa742e44 100644 --- a/python/fastdeploy/__init__.py +++ b/python/fastdeploy/__init__.py @@ -17,7 +17,7 @@ import os import sys from .c_lib_wrap import (Frontend, Backend, FDDataType, TensorInfo, Device, - is_built_with_gpu, is_built_with_ort, + FDLogger, is_built_with_gpu, is_built_with_ort, is_built_with_paddle, is_built_with_trt, get_default_cuda_directory) from .runtime import Runtime, RuntimeOption