3535#include " base/injector.hh"
3636#include " base/lnav_log.hh"
3737#include " base/paths.hh"
38- #include " base/snippet_highlighters.hh"
39- #include " piper.looper.cfg.hh"
40- #include " readline_highlighters.hh"
4138
42- using namespace lnav ::roles::literals;
43-
44- namespace lnav {
45- namespace piper {
39+ namespace lnav ::piper {
4640
4741const char HEADER_MAGIC[4 ] = {' L' , 0 , ' N' , 1 };
4842
@@ -83,143 +77,4 @@ read_header(int fd, const char* first8)
8377 return meta_buf;
8478}
8579
86- multiplex_matcher::match_result
87- multiplex_matcher::match (const string_fragment& line)
88- {
89- const auto & cfg = injector::get<const config&>();
90- auto md = lnav::pcre2pp::match_data::unitialized ();
91-
92- for (const auto & demux_pair : cfg.c_demux_definitions ) {
93- const auto & df = demux_pair.second ;
94-
95- if (!df.dd_valid ) {
96- continue ;
97- }
98-
99- if (!this ->mm_partial_match_ids .empty ()
100- && this ->mm_partial_match_ids .count (demux_pair.first ) == 0 )
101- {
102- continue ;
103- }
104-
105- log_info (" attempting to demux using: %s" , demux_pair.first .c_str ());
106- {
107- md = df.dd_pattern .pp_value ->create_match_data ();
108- if (df.dd_pattern .pp_value ->capture_from (line)
109- .into (md)
110- .matches ()
111- .ignore_error ())
112- {
113- log_info (" demuxer pattern matched" );
114- if (!md[df.dd_muxid_capture_index ].has_value ()) {
115- log_info (" however, mux_id was not captured" );
116-
117- const auto match_um = lnav::console::user_message::warning (
118- attr_line_t (" demuxer " )
119- .append_quoted (demux_pair.first )
120- .append (" matched, however the " )
121- .append (" mux_id" _symbol)
122- .append (" was not captured" ));
123- this ->mm_details .emplace_back (match_um);
124- continue ;
125- }
126- if (!md[df.dd_body_capture_index ].has_value ()) {
127- log_info (" however, body was not captured" );
128- const auto match_um = lnav::console::user_message::warning (
129- attr_line_t (" demuxer " )
130- .append_quoted (demux_pair.first )
131- .append (" matched, however the " )
132- .append (" body" _symbol)
133- .append (" was not captured" ));
134- this ->mm_details .emplace_back (match_um);
135- continue ;
136- }
137- log_info (" and required captures were found, using demuxer" );
138-
139- if (df.dd_enabled ) {
140- auto match_um = lnav::console::user_message::ok (
141- attr_line_t (" demuxer " )
142- .append_quoted (demux_pair.first )
143- .append (" matched line " )
144- .append (lnav::roles::number (
145- fmt::to_string (this ->mm_line_count ))));
146- this ->mm_details .emplace_back (match_um);
147- return found{demux_pair.first };
148- }
149- auto config_al
150- = attr_line_t ()
151- .append (fmt::format (
152- FMT_STRING (" :config /log/demux/{}/enabled "
153- " true" ),
154- demux_pair.first ))
155- .move ();
156- readline_lnav_highlighter (config_al, -1 );
157- auto match_um
158- = lnav::console::user_message::info (
159- attr_line_t (" demuxer " )
160- .append_quoted (demux_pair.first )
161- .append (" matched line " )
162- .append (lnav::roles::number (
163- fmt::to_string (this ->mm_line_count )))
164- .append (" , however, it is disabled" ))
165- .with_help (
166- attr_line_t (" Use " )
167- .append_quoted (
168- lnav::roles::quoted_code (config_al))
169- .append (" to enable this demuxer" ))
170- .move ();
171- this ->mm_details .emplace_back (match_um);
172- }
173-
174- auto partial_size = df.dd_pattern .pp_value ->match_partial (
175- line.sub_range (0 , 1024 ));
176- auto regex_al = attr_line_t (df.dd_pattern .pp_value ->get_pattern ());
177- lnav::snippets::regex_highlighter (
178- regex_al, -1 , line_range{0 , (int ) regex_al.length ()});
179- auto in_line = line.sub_range (0 , 1024 ).rtrim (" \n " ).to_string ();
180- auto esc_res
181- = fmt::v10::detail::find_escape (&in_line[0 ], &(*in_line.end ()));
182- if (esc_res.end != nullptr ) {
183- in_line = fmt::format (FMT_STRING (" {:?}" ), in_line);
184- }
185- auto note = attr_line_t (" pattern: " )
186- .append (regex_al)
187- .append (" \n " )
188- .append (lnav::roles::quoted_code (in_line))
189- .append (" \n " )
190- .append (partial_size + 2 , ' ' )
191- .append (" ^ matched up to here" )
192- .move ();
193- auto match_um = lnav::console::user_message::info (
194- attr_line_t (" demuxer " )
195- .append_quoted (demux_pair.first )
196- .append (" did not match line " )
197- .append (lnav::roles::number (
198- fmt::to_string (this ->mm_line_count ))))
199- .with_note (note)
200- .move ();
201- this ->mm_details .emplace_back (match_um);
202- }
203- if (df.dd_control_pattern .pp_value ) {
204- md = df.dd_control_pattern .pp_value ->create_match_data ();
205- if (df.dd_control_pattern .pp_value ->capture_from (line)
206- .into (md)
207- .matches ()
208- .ignore_error ())
209- {
210- log_info (" demuxer control pattern matched" );
211- this ->mm_partial_match_ids .emplace (demux_pair.first );
212- }
213- }
214- }
215-
216- this ->mm_line_count += 1 ;
217- if (this ->mm_partial_match_ids .empty ()) {
218- return not_found{};
219- }
220-
221- return partial{};
222- }
223-
224- } // namespace piper
225- } // namespace lnav
80+ } // namespace lnav::piper
0 commit comments