collector->get_data();
if ( empty( $data->logs ) ) {
$this->before_non_tabular_output();
$notice = sprintf(
/* translators: %s: Link to help article */
__( 'No data logged. Read about logging variables in Query Monitor.', 'query-monitor' ),
'https://querymonitor.com/docs/logging-variables/'
);
echo $this->build_notice( $notice ); // WPCS: XSS ok.
$this->after_non_tabular_output();
return;
}
$levels = array();
foreach ( $this->collector->get_levels() as $level ) {
if ( $data->counts[ $level ] ) {
$levels[ $level ] = sprintf(
'%s (%d)',
ucfirst( $level ),
$data->counts[ $level ]
);
} else {
$levels[ $level ] = ucfirst( $level );
}
}
$this->before_tabular_output();
$level_args = array(
'all' => sprintf(
/* translators: %s: Total number of items in a list */
__( 'All (%d)', 'query-monitor' ),
count( $data->logs )
),
);
echo '';
echo '';
echo '';
echo $this->build_filter( 'type', $levels, __( 'Level', 'query-monitor' ), $level_args ); // WPCS: XSS ok.
echo ' | ';
echo '' . esc_html__( 'Message', 'query-monitor' ) . ' | ';
echo '' . esc_html__( 'Caller', 'query-monitor' ) . ' | ';
echo '';
echo $this->build_filter( 'component', $data->components, __( 'Component', 'query-monitor' ) ); // WPCS: XSS ok.
echo ' | ';
echo '
';
echo '';
echo '
';
foreach ( $data->logs as $row ) {
$component = $row['component'];
$row_attr = array();
$row_attr['data-qm-component'] = $component->name;
$row_attr['data-qm-type'] = $row['level'];
$attr = '';
foreach ( $row_attr as $a => $v ) {
$attr .= ' ' . $a . '="' . esc_attr( $v ) . '"';
}
$is_warning = in_array( $row['level'], $this->collector->get_warning_levels(), true );
if ( $is_warning ) {
$class = 'qm-warn';
} else {
$class = '';
}
echo ''; // WPCS: XSS ok.
echo '';
if ( $is_warning ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo QueryMonitor::icon( 'warning' );
} else {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
echo QueryMonitor::icon( 'blank' );
}
echo esc_html( ucfirst( $row['level'] ) );
echo ' | ';
printf(
'%s | ',
esc_html( $row['message'] )
);
$stack = array();
$filtered_trace = $row['filtered_trace'];
foreach ( $filtered_trace as $frame ) {
$stack[] = self::output_filename( $frame['display'], $frame['calling_file'], $frame['calling_line'] );
}
$caller = array_shift( $stack );
echo '';
if ( ! empty( $stack ) ) {
echo self::build_toggler(); // WPCS: XSS ok;
}
echo '';
echo "- {$caller}
"; // WPCS: XSS ok.
if ( ! empty( $stack ) ) {
echo '- ' . implode( '
- ', $stack ) . '
'; // WPCS: XSS ok.
}
echo ' | ';
printf(
'%s | ',
esc_html( $component->name )
);
echo '
';
}
echo '';
$this->after_tabular_output();
}
/**
* @param array $class
* @return array
*/
public function admin_class( array $class ) {
/** @var QM_Data_Logger $data */
$data = $this->collector->get_data();
if ( empty( $data->logs ) ) {
return $class;
}
foreach ( $data->logs as $log ) {
if ( in_array( $log['level'], $this->collector->get_warning_levels(), true ) ) {
$class[] = 'qm-warning';
break;
}
}
return $class;
}
/**
* @param array $menu
* @return array
*/
public function admin_menu( array $menu ) {
/** @var QM_Data_Logger $data */
$data = $this->collector->get_data();
$key = 'log';
$count = 0;
if ( ! empty( $data->logs ) ) {
foreach ( $data->logs as $log ) {
if ( in_array( $log['level'], $this->collector->get_warning_levels(), true ) ) {
$key = 'warning';
break;
}
}
$count = count( $data->logs );
/* translators: %s: Number of logs that are available */
$label = __( 'Logs (%s)', 'query-monitor' );
} else {
$label = __( 'Logs', 'query-monitor' );
}
$menu[ $this->collector->id() ] = $this->menu( array(
'id' => "query-monitor-logger-{$key}",
'title' => esc_html( sprintf(
$label,
number_format_i18n( $count )
) ),
) );
return $menu;
}
}
/**
* @param array $output
* @param QM_Collectors $collectors
* @return array
*/
function register_qm_output_html_logger( array $output, QM_Collectors $collectors ) {
$collector = QM_Collectors::get( 'logger' );
if ( $collector ) {
$output['logger'] = new QM_Output_Html_Logger( $collector );
}
return $output;
}
add_filter( 'qm/outputter/html', 'register_qm_output_html_logger', 12, 2 );