Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display the relative time for the log #127

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Alley Logger
* Plugin URI: https://github.com/alleyinteractive/logger
* Description: A Monolog-based logging tool for WordPress. Supports storing log message in a custom post type or in individual posts and terms.
* Version: 2.4.3
* Version: 2.4.4
* Author: Alley Interactive
* Author URI: https://alley.com/
* Requires at least: 5.9
Expand Down
23 changes: 15 additions & 8 deletions template-parts/log-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ function ai_logger_render_table( array $data ): void {
<?php
}
}

$ai_logger_date_format = 'M d, Y h:i:s A O';

?>
<div class="ai-log-display">
<h4><?php esc_html_e( 'Log Summary', 'ai-logger' ); ?></h4>
Expand Down Expand Up @@ -218,16 +215,26 @@ function ai_logger_render_table( array $data ): void {
<td><?php esc_html_e( 'Channel', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['channel'] ?? '' ); ?></td>
</tr>
<?php $ai_logger_date_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); ?>
<tr>
<td><?php esc_html_e( 'Timestamp', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['datetime']->format( $ai_logger_date_format ) ); ?></td>
</tr>
<tr>
<td><?php esc_html_e( 'Timestamp Local', 'ai-logger' ); ?></td>
<td>
<?php echo esc_html( $log['datetime']->setTimezone( wp_timezone() )->format( $ai_logger_date_format ) ); ?>
<?php
echo esc_html(
sprintf(
/* translators: 1: Date and time, 2: Human readable time difference */
__( '%1$s (%2$s ago)', 'ai-logger' ),
$log['datetime']->setTimezone( wp_timezone() )->format( $ai_logger_date_format ),
human_time_diff( $log['datetime']->getTimestamp() ),
),
);
?>
</td>
</tr>
<tr>
<td><?php esc_html_e( 'Timestamp UTC', 'ai-logger' ); ?></td>
<td><?php echo esc_html( $log['datetime']->format( $ai_logger_date_format ) ); ?></td>
</tr>
</table>

<?php if ( ! empty( $log['context'] ) ) : ?>
Expand Down