25
25
26
26
#include " dpctl_error_handlers.h"
27
27
#include < cstring>
28
+ #include < glog/logging.h>
28
29
29
30
void DPCTL_AsyncErrorHandler::operator ()(
30
31
const cl::sycl::exception_list &exceptions)
@@ -40,6 +41,29 @@ void DPCTL_AsyncErrorHandler::operator()(
40
41
}
41
42
}
42
43
44
+ class GLogHelper
45
+ {
46
+ public:
47
+ GLogHelper ()
48
+ {
49
+ google::InitGoogleLogging (" " );
50
+ google::EnableLogCleaner (0 );
51
+ google::InstallFailureSignalHandler ();
52
+ FLAGS_colorlogtostderr = true ;
53
+ FLAGS_stderrthreshold = google::FATAL;
54
+ if (FLAGS_log_dir.empty ()) {
55
+ FLAGS_log_dir = " /tmp" ;
56
+ }
57
+ }
58
+
59
+ ~GLogHelper ()
60
+ {
61
+ google::ShutdownGoogleLogging ();
62
+ }
63
+ };
64
+
65
+ static GLogHelper gloginit;
66
+
43
67
inline int get_requested_level (void )
44
68
{
45
69
int requested_level = 0 ;
@@ -67,10 +91,9 @@ void error_handler(const std::exception &e,
67
91
int requested_level = get_requested_level ();
68
92
int error_level = static_cast <int >(error_type);
69
93
70
- if (requested_level <= error_level) {
71
- std::cerr << e.what () << " in " << func_name << " at " << file_name
72
- << " :" << line_num << std::endl;
73
- }
94
+ LOG_IF (ERROR, requested_level >= error_level)
95
+ << e.what () << " in " << func_name << " at " << file_name << " :"
96
+ << line_num << std::endl;
74
97
}
75
98
76
99
void error_handler (const std::string &what,
@@ -82,8 +105,7 @@ void error_handler(const std::string &what,
82
105
int error_level = static_cast <int >(error_type);
83
106
int requested_level = get_requested_level ();
84
107
85
- if (requested_level <= error_level) {
86
- std::cerr << what << " In " << func_name << " at " << file_name << " :"
87
- << line_num << std::endl;
88
- }
108
+ LOG_IF (INFO, requested_level >= error_level)
109
+ << what << " In " << func_name << " at " << file_name << " :" << line_num
110
+ << std::endl;
89
111
}
0 commit comments