|
68 | 68 | } \ |
69 | 69 | }) |
70 | 70 |
|
71 | | -// Our logs work by writing to stderr. By default this is done through fprintf |
72 | | -// (as defined in posix.cpp) which then does not show up in python environments. |
73 | | -// Here we override the pal to use std::cerr which can be properly redirected by |
74 | | -// scoped_estream_redirect. |
75 | | -void et_pal_emit_log_message( |
76 | | - et_timestamp_t timestamp, |
77 | | - et_pal_log_level_t level, |
78 | | - const char* filename, |
79 | | - ET_UNUSED const char* function, |
80 | | - size_t line, |
81 | | - const char* message, |
82 | | - ET_UNUSED size_t length) { |
83 | | - std::cerr << "[" << filename << ":" << line << "] " << message << std::endl; |
84 | | -} |
85 | | - |
86 | 71 | namespace py = pybind11; |
87 | 72 | using executorch::BUNDLED_PROGRAM_NAMESPACE::verify_method_outputs; |
88 | 73 | using ::executorch::ET_RUNTIME_NAMESPACE::BackendInterface; |
@@ -1168,6 +1153,32 @@ PYBIND11_MODULE(EXECUTORCH_PYTHON_MODULE_NAME, m) { |
1168 | 1153 | .def("__repr__", &PyMethodMeta::repr, call_guard); |
1169 | 1154 | } |
1170 | 1155 |
|
| 1156 | +namespace { |
| 1157 | + |
| 1158 | +// Our logs work by writing to stderr. By default this is done through fprintf |
| 1159 | +// (as defined in posix.cpp) which then does not show up in python environments. |
| 1160 | +// Here we override the pal to use std::cerr which can be properly redirected by |
| 1161 | +// scoped_estream_redirect. |
| 1162 | +void emit_log_message( |
| 1163 | + et_timestamp_t timestamp, |
| 1164 | + et_pal_log_level_t level, |
| 1165 | + const char* filename, |
| 1166 | + ET_UNUSED const char* function, |
| 1167 | + size_t line, |
| 1168 | + const char* message, |
| 1169 | + ET_UNUSED size_t length) { |
| 1170 | + std::cerr << "[" << filename << ":" << line << "] " << message << std::endl; |
| 1171 | +} |
| 1172 | + |
| 1173 | +runtime::PalImpl build_pal() { |
| 1174 | + return runtime::PalImpl::create(emit_log_message, __FILE__); |
| 1175 | +} |
| 1176 | + |
| 1177 | +// Update PAL to redirect logs. |
| 1178 | +ET_UNUSED bool registration_result = runtime::register_pal(build_pal()); |
| 1179 | + |
| 1180 | +} // namespace |
| 1181 | + |
1171 | 1182 | } // namespace pybindings |
1172 | 1183 | } // namespace extension |
1173 | 1184 | } // namespace executorch |
0 commit comments