[Other] Enable to hidden INFO/WARNING log informations (#1368)

* Enable to hidden INFO/WARNING log informations

* Fix build error

---------

Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com>
This commit is contained in:
Jason
2023-02-20 17:24:12 +08:00
committed by GitHub
parent b6658b8094
commit dc5b4be7a9
5 changed files with 36 additions and 5 deletions

View File

@@ -26,7 +26,8 @@ namespace function {
@param out The output tensor which stores the result. @param out The output tensor which stores the result.
@param axis Axis which will be gathered. @param axis Axis which will be gathered.
*/ */
void GatherAlongAxis(const FDTensor& x, const FDTensor& index, FDTensor* result, FASTDEPLOY_DECL void GatherAlongAxis(const FDTensor& x,
const FDTensor& index, FDTensor* result,
int axis); int axis);
} // namespace function } // namespace function

View File

@@ -156,6 +156,8 @@ PYBIND11_MODULE(@PY_LIBRARY_NAME@, m) {
"Make programer easier to deploy deeplearning model, save time to save " "Make programer easier to deploy deeplearning model, save time to save "
"the world!"; "the world!";
m.def("set_logger", &SetLogger);
BindFDTensor(m); BindFDTensor(m);
BindRuntime(m); BindRuntime(m);
BindFDModel(m); BindFDModel(m);

View File

@@ -13,18 +13,27 @@
// limitations under the License. // limitations under the License.
#include "fastdeploy/utils/utils.h" #include "fastdeploy/utils/utils.h"
#include <sstream> #include <sstream>
namespace fastdeploy { namespace fastdeploy {
bool FDLogger::enable_info = true;
bool FDLogger::enable_warning = true;
void SetLogger(bool enable_info, bool enable_warning) {
FDLogger::enable_info = enable_info;
FDLogger::enable_warning = enable_warning;
}
FDLogger::FDLogger(bool verbose, const std::string& prefix) { FDLogger::FDLogger(bool verbose, const std::string& prefix) {
verbose_ = verbose; verbose_ = verbose;
line_ = ""; line_ = "";
#ifdef __ANDROID__ #ifdef __ANDROID__
prefix_ = std::string("[FastDeploy]") + prefix; prefix_ = std::string("[FastDeploy]") + prefix;
#else #else
prefix_ = prefix; prefix_ = prefix;
#endif #endif
} }
FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) { FDLogger& FDLogger::operator<<(std::ostream& (*os)(std::ostream&)) {

View File

@@ -43,6 +43,9 @@ namespace fastdeploy {
class FASTDEPLOY_DECL FDLogger { class FASTDEPLOY_DECL FDLogger {
public: public:
static bool enable_info;
static bool enable_warning;
FDLogger() { FDLogger() {
line_ = ""; line_ = "";
prefix_ = "[FastDeploy]"; prefix_ = "[FastDeploy]";
@@ -90,11 +93,12 @@ FASTDEPLOY_DECL bool ReadBinaryFromFile(const std::string& file,
<< __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t"
#define FDWARNING \ #define FDWARNING \
FDLogger(true, "[WARNING]") \ FDLogger(fastdeploy::FDLogger::enable_warning, "[WARNING]") \
<< __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t" << __REL_FILE__ << "(" << __LINE__ << ")::" << __FUNCTION__ << "\t"
#define FDINFO \ #define FDINFO \
FDLogger(true, "[INFO]") << __REL_FILE__ << "(" << __LINE__ \ FDLogger(fastdeploy::FDLogger::enable_info, "[INFO]") \
<< __REL_FILE__ << "(" << __LINE__ \
<< ")::" << __FUNCTION__ << "\t" << ")::" << __FUNCTION__ << "\t"
#define FDASSERT(condition, format, ...) \ #define FDASSERT(condition, format, ...) \
@@ -214,6 +218,10 @@ std::string Str(const std::vector<T>& shape) {
return oss.str(); return oss.str();
} }
/// Set behaviour of logging while using FastDeploy
FASTDEPLOY_DECL void SetLogger(bool enable_info = true,
bool enable_warning = true);
template <typename T> template <typename T>
void CalculateStatisInfo(const void* src_ptr, int size, double* mean, void CalculateStatisInfo(const void* src_ptr, int size, double* mean,
double* max, double* min) { double* max, double* min) {

View File

@@ -30,6 +30,17 @@ from .c_lib_wrap import (
is_built_with_trt, is_built_with_trt,
get_default_cuda_directory, ) get_default_cuda_directory, )
def set_logger(enable_info=True, enable_warning=True):
"""Set behaviour of logger while using FastDeploy
:param enable_info: (boolean)Whether to print out log level of INFO
:param enable_warning: (boolean)Whether to print out log level of WARNING, recommend to set to True
"""
from .c_lib_wrap import set_logger
set_logger(enable_info, enable_warning)
from .runtime import Runtime, RuntimeOption from .runtime import Runtime, RuntimeOption
from .model import FastDeployModel from .model import FastDeployModel
from . import c_lib_wrap as C from . import c_lib_wrap as C