diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index 03802f38538c9f54c0596d903c70080ad2490bd8..862ea8979ab286b16a236b4fdacda7afee54ae88 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -26,6 +26,7 @@ limitations under the License. */ #include #endif // PADDLE_WITH_CUDA +#include #include #include #include @@ -82,6 +83,22 @@ struct EnforceNotMet : public std::exception { const char* what() const noexcept override { return err_str_.c_str(); } private: + const std::string output_file_name{"paddle_err_info"}; + void saveErrorInformation(const std::string& err) { + std::stringstream ss; + ss << output_file_name; + std::time_t t = std::time(nullptr); + std::tm* tm = std::localtime(&t); + char mbstr[100]; + std::strftime(mbstr, sizeof(mbstr), "%F-%H-%M-%S", tm); + ss << "_" << mbstr << ".log"; + std::ofstream err_file(ss.str(), std::ofstream::out); + if (err_file.is_open()) { + err_file << err; + err_file.close(); + } + } + template inline void Init(StrType what, const char* f, int l) { static constexpr int TRACE_STACK_LIMIT = 100; @@ -112,6 +129,8 @@ struct EnforceNotMet : public std::exception { sout << "Windows not support stack backtrace yet."; #endif err_str_ = sout.str(); + + saveErrorInformation(err_str_); } };